CiA402 Application implementation.
#include <ecSlvApi.h>
#include <ecApiDef.h>
#include "ecSlvCiA402.h"
#include "ESL_cia402Obd.h"
#include "ESL_cia402Demo.h"
#include "project.h"
#include <ESL_os.h>
#include <ESL_BOARD_OS_config.h>
#include <ESL_BOARD_config.h>
#include <ESL_vendor.h>
#include <ESL_gpioHelper.h>
#include <ESL_foeDemo.h>
#include <ESL_soeDemo.h>
#include <ESL_eeprom.h>
#include <ESL_version.h>
#include <ecSlvApi.h>
#if !(defined MBXMEM)
#define MBXMEM
#endif
#define I2C_IOEXP_ADDR 0x60 // The I2C address for GPIO expander
#define RXPDOMAP_INDEX 0x1600
#define TXPDOMAP_INDEX 0x1A00
#define COE_SM_ERROR_MAX_COUNT 0xFFFF
#define AXIS_ONE 0
#define AXIS_TWO 1
#define AXIS_THREE 2
#if !(defined BIT2BYTE)
#define BIT2BYTE(x) (((x)+7) >> 3)
#endif
static void EC_SLV_APP_applicationRun(void* pAppCtxt_p);
#if (defined GPIO_TEST_PINS) && (1==GPIO_TEST_PINS)
#if (defined GPIO_TEST_PROFILE_SEL) && (GPIO_TEST_PROFILE_2 == GPIO_TEST_PROFILE_SEL)
static void EC_SLV_APP_measurement(void* pMsrmtCtxt_p, uint32_t measureChannel_p, bool channelOn_p);
#endif
#endif
{
if (!pApplicationInstance_p)
{
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
error = ESL_setSWVersion(ptSlave);
{
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
ET1100_BOOT_MBXOUT_START, ET1100_BOOT_MBXOUT_DEF_LENGTH,
ET1100_BOOT_MBXIN_START, ET1100_BOOT_MBXIN_DEF_LENGTH);
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
ET1100_MBXOUT_START, ET1100_MBXOUT_DEF_LENGTH,
ET1100_MBXIN_START, ET1100_MBXIN_DEF_LENGTH);
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
0, ET1100_MBXOUT_START, ET1100_MBXOUT_DEF_LENGTH,
ET1100_MBXOUT_CONTROLREG, ET1100_MBXOUT_ENABLE);
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
1, ET1100_MBXIN_START, ET1100_MBXIN_DEF_LENGTH,
ET1100_MBXIN_CONTROLREG, ET1100_MBXIN_ENABLE);
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
2, ET1100_OUTPUT_START, ET1100_OUTPUT_DEF_LENGTH,
ET1100_OUTPUT_CONTROLREG, ET1100_OUTPUT_ENABLE);
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
3, ET1100_INPUT_START, ET1100_INPUT_DEF_LENGTH,
ET1100_INPUT_CONTROLREG, ET1100_INPUT_ENABLE);
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
error = (
EC_API_EError_t)EC_API_SLV_setSyncManErrLimit(ptSlave, COE_SM_ERROR_MAX_COUNT);
{
OSAL_printf("%s:%d (%s) Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
Exit:
return error;
}
{
if (!pApplicationInstance_p)
{
goto Exit;
}
{
OSAL_printf("%s:%d (%s) CiA402 Object Dictionary error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
Exit:
return error;
}
{
uint16_t rxIndex = RXPDOMAP_INDEX + axis_p;
uint16_t curOffset = 0;
if (!pApplicationInstance_p)
{
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Create PDO 0x%04x error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, rxIndex, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
Exit:
return error;
}
{
uint16_t txIndex = TXPDOMAP_INDEX + axis_p;
uint16_t curOffset = 0;
if (!pApplicationInstance_p)
{
goto Exit;
}
{
OSAL_printf("Create PDO for axis %d error code: 0x%08x\r\n", axis_p);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("PDO 0x1A00 Entry 2 Error code: 0x%08x\r\n", error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("PDO 0x1A00 Entry 2 Error code: 0x%08x\r\n", error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("PDO 0x1A00 Entry 2 Error code: 0x%08x\r\n", error);
goto Exit;
}
{
OSAL_printf("%s:%d (%s) Variable Error code: 0x%08x\r\n", __FUNCTION__, __LINE__, __FUNCTION__, error);
goto Exit;
}
{
OSAL_printf("PDO 0x1A00 Entry 2 Error code: 0x%08x\r\n", error);
goto Exit;
}
Exit:
return error;
}
#if (defined GPIO_TEST_PINS) && (1==GPIO_TEST_PINS)
#if (defined GPIO_TEST_PROFILE_SEL) && (GPIO_TEST_PROFILE_2 == GPIO_TEST_PROFILE_SEL)
void EC_SLV_APP_measurement(void* pMsrmtCtxt_p, uint32_t measureChannel_p, bool channelOn_p)
{
volatile CSL_GpioBank_registersRegs * pGpioRegBank = NULL;
uint32_t pinMask = 0;
if (pApplicationInstance)
{
switch (measureChannel_p)
{
case 0: pGpioRegBank = ESL_TESTPIN_STATE_REG_BANK; pinMask = ESL_TESTPIN_0_MASK; break;
case 1: pGpioRegBank = ESL_TESTPIN_STATE_REG_BANK; pinMask = ESL_TESTPIN_1_MASK; break;
case 2: pGpioRegBank = ESL_TESTPIN_STATE_REG_BANK; pinMask = ESL_TESTPIN_2_MASK; break;
default:
break;
}
if (channelOn_p)
{
ESL_GPIO_testPins_set(pGpioRegBank, pinMask);
}
else
{
ESL_GPIO_testPins_clear(pGpioRegBank, pinMask);
}
}
}
#endif
#endif
#if !(defined DPRAM_REMOTE) && !(defined FBTL_REMOTE)
static OSAL_FUNC_UNUSED void EC_SLV_APP_boardPhyReset(void* pCtxt_p, uint8_t phyIdx_p, bool reset_p)
{
uint8_t module = (uint8_t)~0;
uint8_t pin = (uint8_t)~0;
switch(phyIdx_p)
{
case 0:
#if (defined APP_PHY00_RESET_MODULE) && (defined APP_PHY00_RESET_PIN)
{
module = APP_PHY00_RESET_MODULE;
pin = APP_PHY00_RESET_PIN;
}
#endif
#if (defined APP_PHY10_RESET_MODULE) && (defined APP_PHY10_RESET_PIN)
{
module = APP_PHY10_RESET_MODULE;
pin = APP_PHY10_RESET_PIN;
}
#endif
break;
case 1:
#if (defined APP_PHY01_RESET_MODULE) && (defined APP_PHY01_RESET_PIN)
{
module = APP_PHY01_RESET_MODULE;
pin = APP_PHY01_RESET_PIN;
}
#endif
#if (defined APP_PHY11_RESET_MODULE) && (defined APP_PHY11_RESET_PIN)
{
module = APP_PHY11_RESET_MODULE;
pin = APP_PHY11_RESET_PIN;
}
#endif
break;
default:
return;
}
if ((uint8_t)-1 == pin || (uint8_t)-1 == module)
{
OSAL_printf("Invalid PHY config %u\r\n", phyIdx_p);
OSAL_error(__FUNCTION__, __LINE__, OSAL_STACK_PHYDETECT_ERROR, true, 0);
}
if (reset_p)
{
OSAL_printf("Phy Reset: %u.%u\r\n", module, pin);
ESL_GPIO_write(pApplicationInstance->
gpioHandle, (ESL_GPIO_EModule_t)module, (ESL_GPIO_EPin_t)pin, ESL_GPIO_enPINSTATE_LOW);
}
else
{
OSAL_printf("Phy UnReset: %u.%u\r\n", module, pin);
ESL_GPIO_write(pApplicationInstance->
gpioHandle, (ESL_GPIO_EModule_t)module, (ESL_GPIO_EPin_t)pin, ESL_GPIO_enPINSTATE_HIGH);
}
}
#endif
static void EC_SLV_APP_appBoardStatusLed(void* pCallContext_p, void* pLedContext_p, bool runLed_p, bool errLed_p)
{
OSALUNREF_PARM(pLedContext_p);
if (NULL == pApplicationInstance)
{
goto Exit;
}
Exit:
return;
}
{
if (!pApplicationInstance)
{
goto Exit;
}
,EC_SLV_APP_appBoardStatusLed
Exit:
return error;
}
{
if (!pAppInstance_p)
{
goto Exit;
}
#if !(defined DPRAM_REMOTE) && !(defined FBTL_REMOTE)
#if (defined APP_PHY00_RESET_PIN) && (defined APP_PHY00_RESET_MODULE) && (defined APP_PHY01_RESET_PIN) && (defined APP_PHY01_RESET_MODULE)
{
ESL_GPIO_setConfigMode(pAppInstance_p->
gpioHandle, APP_PHY00_RESET_MODULE, APP_PHY00_RESET_PIN, ESL_GPIO_enDIRECTION_MODE_OUTPUT, ESL_GPIO_enIRQ_MODE_NONE);
ESL_GPIO_setConfigMode(pAppInstance_p->
gpioHandle, APP_PHY01_RESET_MODULE, APP_PHY01_RESET_PIN, ESL_GPIO_enDIRECTION_MODE_OUTPUT, ESL_GPIO_enIRQ_MODE_NONE);
}
#endif
#if (defined APP_PHY10_RESET_PIN) && (defined APP_PHY10_RESET_MODULE) && (defined APP_PHY11_RESET_PIN) && (defined APP_PHY11_RESET_MODULE)
{
ESL_GPIO_setConfigMode(pAppInstance_p->
gpioHandle, APP_PHY10_RESET_MODULE, APP_PHY10_RESET_PIN, ESL_GPIO_enDIRECTION_MODE_OUTPUT, ESL_GPIO_enIRQ_MODE_NONE);
ESL_GPIO_setConfigMode(pAppInstance_p->
gpioHandle, APP_PHY11_RESET_MODULE, APP_PHY11_RESET_PIN, ESL_GPIO_enDIRECTION_MODE_OUTPUT, ESL_GPIO_enIRQ_MODE_NONE);
}
#endif
#else
OSALUNREF_PARM(pAppInstance_p);
#endif
#if (defined GPIO_LEDRG0_BANK) && (defined GPIO_LEDRG0_PIN) && (defined GPIO_LEDLR0_BANK) && (defined GPIO_LEDLR0_PIN)
{
ESL_GPIO_setConfigMode(pAppInstance_p->
gpioHandle, GPIO_LEDRG0_BANK, GPIO_LEDRG0_PIN, ESL_GPIO_enDIRECTION_MODE_OUTPUT, ESL_GPIO_enIRQ_MODE_NONE);
ESL_GPIO_setConfigMode(pAppInstance_p->
gpioHandle, GPIO_LEDLR0_BANK, GPIO_LEDLR0_PIN, ESL_GPIO_enDIRECTION_MODE_OUTPUT, ESL_GPIO_enIRQ_MODE_NONE);
}
#endif
#if (defined GPIO_LEDRG1_BANK) && (defined GPIO_LEDRG1_PIN) && (defined GPIO_LEDLR1_BANK) && (defined GPIO_LEDLR1_PIN)
{
ESL_GPIO_setConfigMode(pAppInstance_p->
gpioHandle, GPIO_LEDRG1_BANK, GPIO_LEDRG1_PIN, ESL_GPIO_enDIRECTION_MODE_OUTPUT, ESL_GPIO_enIRQ_MODE_NONE);
ESL_GPIO_setConfigMode(pAppInstance_p->
gpioHandle, GPIO_LEDLR1_BANK, GPIO_LEDLR1_PIN, ESL_GPIO_enDIRECTION_MODE_OUTPUT, ESL_GPIO_enIRQ_MODE_NONE);
}
#endif
#if !(defined DPRAM_REMOTE) && !(defined FBTL_REMOTE)
#if (defined APP_PHY00_RESET_PIN) && (defined APP_PHY00_RESET_MODULE) && (defined APP_PHY01_RESET_PIN) && (defined APP_PHY01_RESET_MODULE)
{
EC_SLV_APP_boardPhyReset(pAppInstance_p, 0, true);
EC_SLV_APP_boardPhyReset(pAppInstance_p, 1, true);
}
#endif
#if (defined APP_PHY10_RESET_PIN) && (defined APP_PHY10_RESET_MODULE) && (defined APP_PHY11_RESET_PIN) && (defined APP_PHY11_RESET_MODULE)
{
EC_SLV_APP_boardPhyReset(pAppInstance_p, 0, true);
EC_SLV_APP_boardPhyReset(pAppInstance_p, 1, true);
}
#endif
#endif
Exit:
return;
}
{
if (!pAppInstance_p)
{
goto Exit;
}
#if !(defined DPRAM_REMOTE) && !(defined FBTL_REMOTE)
#if !(defined TIESC_PHYADDR_0) && !(defined TIESC_PHYADDR_1) && !(defined TIESC_PHYADDR_2) && !(defined TIESC_PHYADDR_3)
#error "EtherCAT without PHY is useless"
#endif
#if (defined TIESC_PHYADDR_0) && (defined TIESC_PHYADDR_1)
{
}
#endif
#if (defined TIESC_PHYADDR_2) && (defined TIESC_PHYADDR_3)
{
}
#endif
#if (defined TIESC_PHYADDR_4) && (defined TIESC_PHYADDR_5)
{
}
#endif
#endif
Exit:
return;
}
{
if (!pAppInstance_p)
{
goto Exit;
}
{
OSAL_error(__FUNCTION__, __LINE__, OSAL_CONTAINER_NOMEMORY, true, 0);
goto Exit;
}
error = EC_SLV_APP_populateBoardFunctions(pAppInstance_p);
{
OSAL_printf("Populate board functions Error code: 0x%08x\r\n", error);
goto Exit;
}
error = EC_SLV_APP_populateSlaveInfo(pAppInstance_p);
{
OSAL_printf("Create Slave Info Error code: 0x%08x\r\n", error);
goto Exit;
}
error = EC_SLV_APP_populateCiA402Functions(pAppInstance_p);
{
OSAL_printf("Create slave information error code: 0x%08x\r\n", error);
return;
}
{
OSAL_printf("Create RxPDO error code: 0x%08x\r\n", error);
return;
}
{
OSAL_printf("Create RxPDO error code: 0x%08x\r\n", error);
return;
}
{
OSAL_printf("Create RxPDO error code: 0x%08x\r\n", error);
return;
}
{
OSAL_printf("Create TxPDO error code: 0x%08x\r\n", error);
return;
}
{
OSAL_printf("Create TxPDO error code: 0x%08x\r\n", error);
return;
}
{
OSAL_printf("Create TxPDO error code: 0x%08x\r\n", error);
return;
}
#if !(defined DPRAM_REMOTE) && !(defined FBTL_REMOTE)
#else
OSAL_SCHED_startTask(EC_SLV_APP_usrAppRunWrapper, pAppInstance_p, OSAL_TASK_ePRIO_Idle
,(uint8_t*)EC_SLV_APP_appRunWrapTaskStack_g, APPRWRAP_TASK_SIZE_BYTE, 0, "AppRun");
#endif
#if (defined GPIO_TEST_PINS) && (1==GPIO_TEST_PINS)
#if (defined GPIO_TEST_PROFILE_SEL) && (GPIO_TEST_PROFILE_2 == GPIO_TEST_PROFILE_SEL)
#endif
#endif
{
OSAL_printf("Slave Init Error Code: 0x%08x\r\n", error);
return;
}
Exit:
return;
}
{
if (pAppInstance_p)
{
}
}
void EC_SLV_APP_applicationRun(void* pAppRunCtxt_p)
{
OSALUNREF_PARM(pAppRunCtxt_p);
#if (defined GPIO_TEST_PINS) && (1==GPIO_TEST_PINS)
#if (defined GPIO_TEST_PROFILE_SEL) && ((GPIO_TEST_PROFILE_1 == GPIO_TEST_PROFILE_SEL) || (GPIO_TEST_PROFILE_2 == GPIO_TEST_PROFILE_SEL))
static bool bToggle = false;
if (bToggle)
{
ESL_GPIO_testPins_set(ESL_TESTPIN_STATE_REG_BANK, ESL_TESTPIN_3_MASK);
}
else
{
ESL_GPIO_testPins_clear(ESL_TESTPIN_STATE_REG_BANK, ESL_TESTPIN_3_MASK);
}
bToggle = !bToggle;
#endif
#endif
}