Scope
This example demonstrates the steps to configure the hardware, create the basic EtherCAT Slave information as well as the Object Dictionary and the Process Data configuration.
Related Files
EtherCAT_Slave_Simple.c
Basic Setup
The example starts by initializing operating system (OSAL) and hardware abstraction layers (HWAL). The EtherCAT functionality itself is implemented within the Appl_LoopTask
that is started from the main
application entry point, both are implemented in
EtherCAT_Slave_Simple.c.
Initialization of Stack, PRU, and Example Application
Before entering the main stack loop, the example application itself is initialized in EC_SLV_APP_applicationInit
. This function creates a new EtherCAT Slave device instance, registers a board status LED callback, sets vendor ID, product code and name, revision number, etc.
Initialization of the EtherCAT Slave
td |
Manufacturer Specific Objects
Next various objects are created in the Object Dictionary of the EtherCAT Slave device. These objects are used to display information related to the device or used to map them as Process Data. These objects are declared in the Manufacturer Specific Area, whereas the CoE Communication Area objects are created automatically by the SDK RXPDO configuration
static EC_API_EError_t EC_SLV_APP_populateOutObjects(EC_SLV_APP_Sapplication_t* pApplicationInstance)
{
...
,NULL, NULL, NULL, NULL, &pApplicationInstance->ptRecObjOut);
{
OSAL_printf("Object 0x2000 Record Error code: 0x%08x\n", error);
goto Exit;
}
{
OSAL_printf("Object 0x2000 SubIndex 1 Error code: 0x%08x\n", error);
goto Exit;
}
...
}
@ EC_API_eERR_INVALID
Definition ecSlvApi_Error.h:52
@ EC_API_eERR_NONE
Definition ecSlvApi_Error.h:45
enum EC_API_EError EC_API_EError_t
uint32_t EC_API_SLV_CoE_configRecordSubIndex(EC_API_SLV_SHandle_t *pEcSlaveApi_p, EC_API_SLV_SCoE_Object_t *pObject_p, uint8_t subIndex_p, char *pName_p, uint16_t type_p, uint16_t bitLen_p, uint16_t flags_p)
This function creates a subIndex for the Record Object.
Definition ecSlvApi_CoEStub.c:922
uint32_t EC_API_SLV_CoE_odAddRecord(EC_API_SLV_SHandle_t *pEcSlaveApi_p, uint16_t index_p, char *pName_p, EC_API_SLV_CBObjRead_t cbRead_p, void *pReadCtxt_p, EC_API_SLV_CBObjWrite_t cbWrite_p, void *pWriteCtxt_p, EC_API_SLV_SCoE_Object_t **pOutSdo_p)
This function creates a Record Object.
Definition ecSlvApi_CoEStub.c:867
struct EC_API_SLV_Handle EC_API_SLV_SHandle_t
EC_API_SLV_SHandle_t describes the EtherCAT Slave API.
Definition ecSlvApi.h:136
#define ACCESS_READWRITE
Read/write in all states.
Definition ecSlvApiDef_CoE.h:148
#define OBJACCESS_RXPDOMAPPING
Mappable in RxPDOs.
Definition ecSlvApiDef_CoE.h:158
#define DEFTYPE_UNSIGNED32
UNSIGNED32.
Definition ecSlvApiDef_CoE.h:50
TXPDO configuration
static EC_API_EError_t EC_SLV_APP_populateInOutObjects(EC_SLV_APP_Sapplication_t* pApplicationInstance)
{
...
,NULL, NULL, NULL, NULL
,&pApplicationInstance->pt2002RecObj);
{
OSAL_printf("Object Record Error code: 0x%08x\n", error);
goto Exit;
}
{
OSAL_printf("Object 0x2002 SubIndex 1 Error code: 0x%08x\n", error);
goto Exit;
}
...
}
#define ACCESS_READ
Read only in all states.
Definition ecSlvApiDef_CoE.h:149
#define OBJACCESS_TXPDOMAPPING
Mappable in TxPDOs.
Definition ecSlvApiDef_CoE.h:159
Objects 0x200C
and 0x200E
are used to demonstrate CoE callback functions. These callbacks, sendEoEFrame
and sendEmergencyMsg
are deactivated by default in order to pass the EtherCAT Conformance Tests, however, these may be used as write parameter of the stated objects. Using these callback functions, the example application sends an EoE frame or a CoE emergency message with the data written to them. See the code snippet below:
if (i32uErr != eECERR_NONE)
{
osal_Printf("Object 0x200C Error code: 0x%08x\n", i32uErr);
goto Exit;
}
if (i32uErr != eECERR_NONE)
{
osal_Printf("Object 0x200E Error code: 0x%08x\n", i32uErr);
goto Exit;
}
uint32_t EC_API_SLV_CoE_odAddVariable(EC_API_SLV_SHandle_t *pEcSlaveApi_p, uint16_t index_p, char *pName_p, uint16_t type_p, uint16_t bitLen_p, uint16_t flags_p, EC_API_SLV_CBObjRead_t cbRead_p, void *pReadCtxt_p, EC_API_SLV_CBObjWrite_t cbWrite_p, void *pWriteCtxt_p)
This function creates a Base Data Type Object for the Object Dictionary.
Definition ecSlvApi_CoEStub.c:746
Process Data Object Configuration
Once the Object Dictionary is configured, Process Data are defined. The function EC_SLV_APP_populateRxPDO()
is used to generate the output PDOs and EC_SLV_APP_populateTxPDO()
to generate the input PDOs. By default, the SDK sets the PDO assignment fixed, meaning that a PDO generated by the application is attached to a SyncManager and this configuration cannot be changed. However, it allows by default to modify the PDO entry content. To change these behaviours refer to EC_API_SLV_PDO_setFixedMapping()
and EC_API_SLV_PDO_setAssignment()
functions.
Initialization and starting the Stacks
The EC_API_SLV_init()
function initializes the SDK Stack and validates whether the user defined configuration is valid or not. If the EtherCAT configuration is valid, then object content can be written and finally, the EC_API_SLV_run()
function starts the Beckhoff Stack.