Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of Texas Instruments Incorporated nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define TIESC_HW 0
#define PRU_200MHZ 1
#include "project.h"
#include "ecSubDeviceCiA402.h"
#if (defined FBTL_REMOTE) && (FBTL_REMOTE==1)
#if (defined FBTLIMPL_LINEUART) && (1==FBTLIMPL_LINEUART)
#include "sysLib_lineUart.h"
#else
#include <sysLib_sharedMemory.h>
#endif
#endif
#include <osal.h>
#include <ESL_os.h>
#include <ESL_BOARD_config.h>
#include <ESL_BOARD_OS_config.h>
#include <ESL_cia402Obd.h>
#include <ESL_version.h>
#if (defined SOC_AM263PX)
#include <ESL_BOARD_pinmux.h>
#endif
#include <ecSlvApi.h>
#if (defined SOC_AM263PX) || (defined SOC_AM261X)
#define FrameProc ECAT_FrameProcAPP
#include <industrial_comms/ethercat_subdevice/icss_fwhal/firmware/m_v2.3/ecat_frame_handler_bin.h>
#define HostProc ECAT_HostProcAPP
#include <industrial_comms/ethercat_subdevice/icss_fwhal/firmware/m_v2.3/ecat_host_interface_bin.h>
#else
#define FrameProc ECAT_FrameProcAPP
#include <industrial_comms/ethercat_subdevice/icss_fwhal/firmware/g_v1.3/ecat_frame_handler_bin.h>
#define HostProc ECAT_HostProcAPP
#include <industrial_comms/ethercat_subdevice/icss_fwhal/firmware/g_v1.3/ecat_host_interface_bin.h>
#if (defined INCLUDE_MDIO_MANUAL_MODE_WORKAROUND)
#define PRUFirmware PRUMDIOFirmwareECATAPP
#include <industrial_comms/ethercat_subdevice/icss_fwhal/firmware/g_v1.3/mdio_fw_bin.h>
#endif
#endif
#define TIESC_HW 0
#define PRU_200MHZ 1
#define THREAD_IDLE_TIMEOUT (10U)
#if defined(SDK_VARIANT_PREMIUM)
#define MAX_MAINLOOP_TASK_BLOCK_TIME_IN_MS (2U)
#define ENABLE_LOOP_TASK_SYNC_TO_EVENTS (1U)
#define LOOP_TASK_NOTIFICATION_INDEX (0U)
#if (ENABLE_LOOP_TASK_SYNC_TO_EVENTS == 1)
const TickType_t loopTaskMaxBlockTime = pdMS_TO_TICKS(MAX_MAINLOOP_TASK_BLOCK_TIME_IN_MS);
static TaskHandle_t loopTaskHandle_g = NULL;
static void EC_SLV_APP_loopTaskNotify(TaskHandle_t pTaskHandle);
#endif
#endif
#if defined(SDK_VARIANT_PREMIUM) && (ENABLE_LOOP_TASK_SYNC_TO_EVENTS == 1)
static void EC_SLV_APP_loopTaskNotify(TaskHandle_t pTaskHandle)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (pTaskHandle)
{
if (HwiP_inISR())
{
vTaskNotifyGiveIndexedFromISR(pTaskHandle, LOOP_TASK_NOTIFICATION_INDEX, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
else
{
xTaskNotifyGiveIndexed(pTaskHandle, LOOP_TASK_NOTIFICATION_INDEX);
}
}
}
#endif
static void EC_SLV_APP_Pinmux_config(void)
{
#if !(defined DPRAM_REMOTE) && !(defined FBTL_REMOTE)
#if (defined SOC_AM263PX)
Pinmux_config(gPruicssPinMuxCfg, PINMUX_DOMAIN_ID_MAIN);
#define MSS_CTRL_ICSSM_PRU_GPIO_OUT_CTRL_VALUE (0x0001077F)
#define MSS_CTRL_ICSSM_PRU1_GPIO_OUT_CTRL_VALUE (0x0001037F)
HW_WR_REG32(CSL_MSS_CTRL_U_BASE + CSL_MSS_CTRL_ICSSM_PRU0_GPIO_OUT_CTRL, MSS_CTRL_ICSSM_PRU_GPIO_OUT_CTRL_VALUE);
HW_WR_REG32(CSL_MSS_CTRL_U_BASE + CSL_MSS_CTRL_ICSSM_PRU1_GPIO_OUT_CTRL, MSS_CTRL_ICSSM_PRU1_GPIO_OUT_CTRL_VALUE);
uint32_t pinNum[CONFIG_GPIO_NUM_INSTANCES] = {CONFIG_ICSSM_MUX_SEL_PIN, CONFIG_ICSSM_MUX_EN_PIN, CONFIG_MUX_ENABLE_PIN, CONFIG_USER_LED_PIN};
uint32_t pinDir[CONFIG_GPIO_NUM_INSTANCES] = {CONFIG_ICSSM_MUX_SEL_DIR, CONFIG_ICSSM_MUX_EN_DIR, CONFIG_MUX_ENABLE_DIR, CONFIG_USER_LED_DIR};
for(uint32_t index = 0; index < CONFIG_GPIO_NUM_INSTANCES-1; index++)
{
uint32_t gGpioBaseAddr = (uint32_t) AddrTranslateP_getLocalAddr(CONFIG_ICSSM_MUX_SEL_BASE_ADDR);
GPIO_setDirMode(gGpioBaseAddr, pinNum[index], pinDir[index]);
GPIO_pinWriteHigh(gGpioBaseAddr, pinNum[index]);
}
OSAL_SCHED_sleep(300);
#endif
#endif
}
static void EC_SLV_APP_CIA_loopTask(void *pArg_p)
{
char* pProductName = NULL;
uint32_t vendorId = 0;
uint32_t productCode = 0;
#if !defined(ENABLE_LOOP_TASK_SYNC_TO_EVENTS) || (ENABLE_LOOP_TASK_SYNC_TO_EVENTS == 0)
uint16_t alErrorCode = 0;
#endif
uint8_t axisNo = 0;
if (!pApplicationInstance)
{
goto Exit;
}
EC_SLV_APP_CIA_initBoardFunctions(pApplicationInstance);
EC_SLV_APP_CIA_registerStacklessBoardFunctions(pApplicationInstance);
#if !(defined FBTL_REMOTE) && !(defined DPRAM_REMOTE)
(uint32_t*)ECAT_HostProcAPP, sizeof(ECAT_HostProcAPP));
{
OSAL_printf("%s:%d Error code: 0x%08x\r\n", __func__, __LINE__, error);
OSAL_error(__func__, __LINE__, OSAL_STACK_INIT_ERROR, true, 0);
}
#if (defined INCLUDE_MDIO_MANUAL_MODE_WORKAROUND)
{
OSAL_printf("%s:%d Error code: 0x%08x\r\n", __func__, __LINE__, error);
OSAL_error(__func__, __LINE__, OSAL_STACK_INIT_ERROR, true, 0);
}
#endif
#endif
{
OSAL_printf("%s:%d Error code: 0x%08x\r\n", __func__, __LINE__, error);
OSAL_error(__func__, __LINE__, OSAL_STACK_INIT_ERROR, true, 0);
}
EC_SLV_APP_cia402_initAxisObjects(pApplicationInstance);
for(axisNo = 0; axisNo < AXES_NUMBER; axisNo++)
{
{
OSAL_printf("%s:%d Error code: 0x%08x\r\n", __func__, __LINE__, error);
}
}
OSAL_printf("%s - %xh / %xh\r\n", pProductName, vendorId, productCode);
#if defined(SDK_VARIANT_PREMIUM)
EC_API_SLV_setExplicitDeviceId(pApplicationInstance->
ptEcSlvApi,0x0005);
uint16_t explicitDeviceID = 0;
EC_API_SLV_getExplicitDeviceId(pApplicationInstance->
ptEcSlvApi,&explicitDeviceID);
OSAL_printf("Explicit Device ID : 0x%4x\r\n",explicitDeviceID);
#endif
#if defined(SDK_VARIANT_PREMIUM) && (ENABLE_LOOP_TASK_SYNC_TO_EVENTS == 1)
loopTaskHandle_g = xTaskGetCurrentTaskHandle();
if(loopTaskHandle_g == NULL)
{
}
error = EC_API_SLV_cbRegisterDirectTaskNotifyFunction(pApplicationInstance->
ptEcSlvApi, EC_SLV_APP_loopTaskNotify, loopTaskHandle_g);
{
OSAL_printf("%s:%d Error code: 0x%08x\r\n", __func__, __LINE__, error);
OSAL_error(__func__, __LINE__, error, true, 1, "Task notify callback function register error\r\n");
}
#endif
error = EC_SLV_APP_CiA_fetchAxisObjects(pApplicationInstance);
{
OSAL_printf("%s:%d Error code: 0x%08x\r\n", __func__, __LINE__, error);
OSAL_error(__func__, __LINE__, OSAL_STACK_INIT_ERROR, true, 0);
}
for(;;)
{
#if (defined GPIO_TEST_PINS) && (1==GPIO_TEST_PINS)
#if (defined GPIO_TEST_PROFILE_SEL) && (defined GPIO_TEST_PROFILE_1) && (GPIO_TEST_PROFILE_1 == GPIO_TEST_PROFILE_SEL)
ESL_GPIO_testPins_set(ESL_TESTPIN_STATE_REG_BANK, ESL_TESTPIN_0_MASK);
#endif
#endif
#if (defined GPIO_TEST_PINS) && (1==GPIO_TEST_PINS)
#if (defined GPIO_TEST_PROFILE_SEL) && (defined GPIO_TEST_PROFILE_1) && (GPIO_TEST_PROFILE_1 == GPIO_TEST_PROFILE_SEL)
ESL_GPIO_testPins_clear(ESL_TESTPIN_STATE_REG_BANK, ESL_TESTPIN_0_MASK);
#endif
#endif
#if defined(SDK_VARIANT_PREMIUM) && (ENABLE_LOOP_TASK_SYNC_TO_EVENTS == 1)
ulTaskNotifyTakeIndexed(LOOP_TASK_NOTIFICATION_INDEX, pdTRUE, loopTaskMaxBlockTime);
#else
{
OSAL_SCHED_yield();
}
else
{
OSAL_SCHED_sleep(THREAD_IDLE_TIMEOUT);
}
#endif
}
Exit:
ESL_OS_taskLeave();
return;
}
static void EC_SLV_APP_CIA_mainTask(void *pArg_p)
{
uint32_t retVal = OSAL_ERR_NoError;
if (!applicationInstance)
{
OSAL_error(__func__, __LINE__, OSAL_ERR_InvalidParm, true, 1, "Application instance missing!!!\r\n");
goto Exit;
}
if (OSAL_ERR_NoError != retVal)
{
OSAL_error(__func__, __LINE__, retVal, true, 1, "OS Board init error\r\n");
}
retVal = ESL_OS_printfMutexInit();
if (OSAL_ERR_NoError != retVal)
{
goto Exit;
}
OSAL_registerPrintOut(NULL, ESL_OS_printf);
retVal = EC_SLV_APP_CIA_remoteInit(applicationInstance);
if(!((OSAL_CONTAINER_LOCALIMPLEMENTATION == retVal) || (OSAL_ERR_NoError == retVal)))
{
OSAL_error(__func__, __LINE__, OSAL_ERR_InvalidParm, true, 1, "Fatal error remote API init!!!\r\n");
goto Exit;
}
EC_SLV_APP_Pinmux_config();
{
KBECSLV_STACKSIZE_PDI, KBECSLV_STACKSIZE_LED, KBECSLV_STACKSIZE_SYNC0,
KBECSLV_STACKSIZE_SYNC1);
applicationInstance->
loopThreadHandle = OSAL_SCHED_startTask(EC_SLV_APP_CIA_loopTask
,applicationInstance
#if !(defined FBTL_REMOTE) || (0==FBTL_REMOTE)
,OSAL_TASK_Prio_Normal
#else
,OSAL_TASK_Prio_Idle
#endif
,(uint8_t*)EC_SLV_APP_applLoopTaskStack_g
,APPLLOOP_TASK_SIZE_BYTE
,0
,"Appl_LoopTask");
{
OSAL_printf("Error return start Loop Task\r\n");
OSAL_error(__func__, __LINE__, OSAL_STACK_INIT_ERROR, true, 0);
}
for (;;)
{
OSAL_SCHED_sleep(1000);
}
}
else
{
for (;;)
{
for (;;)
{
OSAL_printf("long jmp restart\r\n");
OSAL_SCHED_sleep(1000);
}
}
}
Exit:
return;
}
int main(int argc, char *argv[])
{
static uint32_t selectedPruInstance = UINT32_MAX;
uint32_t error = OSAL_ERR_NoError;
ESL_OS_init();
#if !(defined FBTL_REMOTE)
selectedPruInstance = ESL_DEFAULT_PRUICSS;
#endif
if (1 < argc)
{
char *inst = argv[1];
selectedPruInstance = strtoul(inst, NULL, 0);
}
OSAL_init();
applicationInstance.
mainThreadParam.stack = (uint8_t*)EC_SLV_APP_mainTaskStack_g;
applicationInstance.
mainThreadParam.taskMain = (TaskP_FxnMain)EC_SLV_APP_CIA_mainTask;
if (SystemP_SUCCESS != error)
{
OSAL_printf(
"Error setting create thread of %s (%ld)\r\n", applicationInstance.
mainThreadParam.name, error);
OSAL_error(__func__, __LINE__, OSAL_STACK_INIT_ERROR, true, 0);
}
OSAL_startOs();
OSAL_error(__func__, __LINE__, OSAL_ERR_InvalidParm, true, 1, "Not reachable by design!!!\r\n");
return error;
}
{
uint32_t retVal = OSAL_CONTAINER_LOCALIMPLEMENTATION;
if (!applicationInstance)
{
goto Exit;
}
#if (defined FBTL_REMOTE) && (FBTL_REMOTE==1)
#if (defined FBTLIMPL_LINEUART) && (FBTLIMPL_LINEUART==1)
retVal = SYSLIB_createLibInstanceLine( FBTL_LINE_UART_NAME,
FBTL_MAX_ASYNC_LEN, FBTL_MAX_ASYNC_LEN,
FBTL_MAX_PD_LEN, FBTL_MAX_PD_LEN
#if (defined FBTLTRACECALLS) && (FBTLTRACECALLS==1)
,true
#else
,false
#endif
);
#else
retVal = SYSLIB_createLibInstanceShm(FBTLSHARED_MEM_NAME, FBTLSHARED_MEM_SIZE, false,
FBTL_MAX_ASYNC_LEN, FBTL_MAX_ASYNC_LEN, FBTL_MAX_PD_LEN, FBTL_MAX_PD_LEN
#if (defined FBTLTRACECALLS) && (FBTLTRACECALLS==1)
,true
#else
,false
#endif
);
#endif
#else
OSALUNREF_PARM(applicationInstance);
retVal = OSAL_CONTAINER_LOCALIMPLEMENTATION;
#endif
if(OSAL_CONTAINER_LOCALIMPLEMENTATION == retVal)
{
OSAL_printf("\r\nLocal Implementation\r\n");
}
#if (defined FBTL_REMOTE) && (FBTL_REMOTE==1)
{
retVal = EC_API_SLV_FBTL_configuration(applicationInstance->
remoteHandle);
{
OSAL_printf("%s:%d Error code: 0x%08x\r\n", __func__, __LINE__, retVal);
OSAL_error(__func__, __LINE__, OSAL_STACK_INIT_ERROR, true, 0);
goto Exit;
}
}
#endif
else
{
;
}
Exit:
if((OSAL_ERR_NoError != retVal) && (OSAL_CONTAINER_LOCALIMPLEMENTATION != retVal))
{
OSAL_printf("%s:%d::> err ret = 0x%x\r\n", __func__, __LINE__, retVal);
}
return retVal;
}
uint32_t EC_API_SLV_mainLoopCyclic(void)
Trigger stack mainloop.
Definition ecSlvApi.c:2343
uint32_t EC_API_SLV_stackInit(void)
This is the function to initialize Stack backend.
Definition ecSlvApi.c:784
uint32_t EC_API_SLV_getState(EC_API_SLV_SHandle_t *pHandle, EC_API_SLV_EEsmState_t *pState, uint16_t *pAlErrorCode)
This is the function to read the EtherCAT Slave state machine.
Definition ecSlvApi.c:1681
uint32_t EC_API_SLV_getVendorId(EC_API_SLV_SHandle_t *pHandle, uint32_t *pVendorId)
Get device vendor ID.
Definition ecSlvApi_param.c:878
uint32_t EC_API_SLV_getProductName(EC_API_SLV_SHandle_t *pHandle, char **ppProductName)
Get serial number.
Definition ecSlvApi_param.c:1079
uint32_t EC_API_SLV_getProductCode(EC_API_SLV_SHandle_t *pHandle, uint32_t *pProductCode)
Get device product code.
Definition ecSlvApi_param.c:928
uint32_t EC_API_SLV_CiA402_enableStateMachineForAxis(EC_API_SLV_SHandle_t *pHandle, uint8_t axisNo, bool enable)
Activate CiA402 state machine for an axis.
Definition ecSlvApi_CiA402.c:311
@ EC_API_eERR_NULLPTR
Definition ecSlvApiDef_error.h:54
@ EC_API_eERR_NONE
Definition ecSlvApiDef_error.h:41
uint32_t EC_API_SLV_stackInsertPruFirmware(uint32_t *pFirmwareIn, uint32_t lenFirmwareIn, uint32_t *pFirmwareOut, uint32_t lenFirmwareOut)
Insert fieldbus custom PRU firmware.
Definition ecSlvApi.c:824
uint32_t EC_API_SLV_stackInsertMdioManualFirmware(uint32_t *pFirmware, uint32_t lenFirmware)
Insert PRU firmware for manual MDIO workaround.
Definition ecSlvApi.c:869
enum EC_API_SLV_EEsmState EC_API_SLV_EEsmState_t
EC_STATE_T EtherCAT State Machine states.
@ EC_API_SLV_eESM_uninit
Uninitialized State.
Definition ecSlvApi_types.h:70
@ EC_API_SLV_eESM_init
Init State.
Definition ecSlvApi_types.h:71
void EC_SLV_APP_CIA_applicationInit(EC_SLV_APP_CIA_Application_t *pAppInstance_p)
Initialize subdevice application example.
Definition ecSubDeviceCiA402.c:959
void ESL_dumpVersions(EC_API_SLV_SHandle_t *pEcSubDevice)
Dump stack version info.
Definition ESL_version.c:73
uint32_t EC_API_SLV_load(OSAL_ERR_CBHandler_t cbErrHandler, uint32_t pruSelect)
Initialize stack environment (OSAL and HWAL) after load.
Definition ecSlvApi.c:634
uint32_t EC_API_SLV_prepareTasks(OSAL_TASK_Priority_t pdiTaskPrio, OSAL_TASK_Priority_t statusLEDTaskPrio, OSAL_TASK_Priority_t sync0TaskPrio, OSAL_TASK_Priority_t sync1TaskPrio, uint32_t pdiTaskStackSize, uint32_t statusLEDTaskStackSize, uint32_t sync0TaskStackSize, uint32_t sync1TaskStackSize)
Prepare internal task priorities.
Definition ecSlvApi.c:747
TaskP_Object mainThreadHandle
Definition ecSubDeviceCiA402.h:169
void * loopThreadHandle
Definition ecSubDeviceCiA402.h:171
TaskP_Params mainThreadParam
Definition ecSubDeviceCiA402.h:170
uint32_t selectedPruInstance
Definition ecSubDeviceCiA402.h:166
EC_API_SLV_SHandle_t * ptEcSlvApi
Definition ecSubDeviceCiA402.h:207
void * remoteHandle
Definition ecSubDeviceCiA402.h:175
Definition ecSubDeviceCiA402.h:165