EtherCAT SubDevice2.02.00
 
Loading...
Searching...
No Matches
Process data memory access

This chapter provides guidance to the developers who want to optimize the access to the process data. The SDK uses by default the process data buffers provided by the Beckhoff Stack if none is provided. The PDO setter and getter functions listed in the PDO Help functions copy the process data from one memory area to another. Those functions have time and performance costs, therefore, the SDK allows to register callbacks to access the customer specific memory areas and enable zero copy behavior.

The SDK provides the following API to register the customer callbacks :

Function Description
EC_API_SLV_cbRegisterPreSeqInputPDBuffer Request a buffer to read input process data
EC_API_SLV_cbRegisterPreSeqOutputPDBuffer Request a buffer to write output process data
EC_API_SLV_cbRegisterPostSeqInputPDBuffer Triggered after input process data has been read
EC_API_SLV_cbRegisterPostSeqOutputPDBuffer Triggered after output process data has been written

The output process data buffer is updated by PDO_OutputMapping(), which is synchronized to SYNC0/SM event. In this function, the callback registered with EC_API_SLV_cbRegisterPreSeqOutputPDBuffer() is called to acquire the output process data buffer handled by the application and update it with the latest data from the output process data Sync Manager. Once the update is complete, it calls the callback registered with EC_API_SLV_cbRegisterPostSeqOutputPDBuffer() to release the acquired output process data buffer back to the application.

The input process data buffer is read by PDO_InputMapping(), which is synchronized to SYNC0/SM event. In this function, the callback registered with EC_API_SLV_cbRegisterPreSeqInputPDBuffer() is called to acquire the input process data buffer handled by the application and update the input process data Sync Manager with the latest data. Once the update is complete, it calls the callback registered with EC_API_SLV_cbRegisterPostSeqInputPDBuffer() to release the acquired input process data buffer back to the application.

Using these functions, the end user can register its own callbacks and handle the process data on its own will. For instance, the customer can implement a triple buffer mechanism in a Dual Port RAM and the SDK will get and set the data from it.

EC_API_SLV_SHandle_t* ptSlave = pApplicationInstance_p->ptEcSlvApi;
EC_API_SLV_cbRegisterPreSeqInputPDBuffer (ptSlave, ptSlave, DPR_PreSequenceInputProcessData);
EC_API_SLV_cbRegisterPreSeqOutputPDBuffer (ptSlave, ptSlave, DPR_PreSequenceOutputProcessData);
EC_API_SLV_cbRegisterPostSeqInputPDBuffer (ptSlave, ptSlave, DPR_PostSequenceInputProcessData);
EC_API_SLV_cbRegisterPostSeqOutputPDBuffer (ptSlave, ptSlave, DPR_PostSequenceOutputProcessData);
//SubDevice to MainDevice COMM (TXPDO)
void* DPR_PreSequenceInputProcessData(void* pContext_p, uint32_t i32uLength_p)
{
void* pvPayload = NULL;
// Get latest processdata of application from DPR to send to the MainDevice.
pvPayload = (void*) DPR_getBuffer(DPR_eService_GetInputProcessData, i32uLength_p);
return pvPayload;
}
//MainDevice to SubDevice COMM (RXPDO)
void* DPR_PreSequenceOutputProcessData(void* pContext_p, uint32_t i32uLength_p)
{
void* pvPayload = NULL;
//Get dirty buffer to write the process data received from the MainDevice.
pvPayload = (void*) DPR_getBuffer(DPR_eService_SetOutputProcessData, i32uLength_p);
return pvPayload;
}
//SubDevice to MainDevice COMM (TXPDO)
void DPR_PostSequenceInputProcessData(void* pContext_p, void* pvBuffer_p, uint32_t i32uLength_p)
{
//Buffer has been read. Nothing to do.
DPR_setBuffer(DPR_eService_GetInputProcessData, pvBuffer_p, i32uLength_p);
}
//MainDevice to SubDevice COMM (RXPDO)
void DPR_PostSequenceOutputProcessData(void* pContext_p, void* pvBuffer_p, uint32_t i32uLength_p)
{
//Buffer has been written. Flip the dirty buffer with the latest buffer.
DPR_setBuffer(DPR_eService_SetOutputProcessData, pvBuffer_p, i32uLength_p);
}
uint32_t EC_API_SLV_cbRegisterPostSeqInputPDBuffer(EC_API_SLV_SHandle_t *pHandle, EC_API_SLV_CBPostSeqInputPD_t cbFunc, void *pContext)
This is the function to register a function which releases an external Process data buffer.
Definition ecSlvApi_pdo.c:2393
uint32_t EC_API_SLV_cbRegisterPreSeqOutputPDBuffer(EC_API_SLV_SHandle_t *pHandle, EC_API_SLV_CBPreSeqOutputPD_t cbFunc, void *pContext)
This is the function to register a function which gets an external Process data buffer.
Definition ecSlvApi_pdo.c:2351
uint32_t EC_API_SLV_cbRegisterPostSeqOutputPDBuffer(EC_API_SLV_SHandle_t *pHandle, EC_API_SLV_CBPostSeqOutputPD_t cbFunc, void *pContext)
This is the function to register a function which releases an external Process data buffer.
Definition ecSlvApi_pdo.c:2436
uint32_t EC_API_SLV_cbRegisterPreSeqInputPDBuffer(EC_API_SLV_SHandle_t *pHandle, EC_API_SLV_CBPreSeqInputPD_t cbFunc, void *pContext)
This is the function to register a function which gets an external Process data buffer.
Definition ecSlvApi_pdo.c:2308
Definition ecSlvApiInternal.h:341
Note
These callback functions are not meant to be used as user callbacks for other purposes such as GPIO toggling. These functions must handle the input/output process data. The stack expects that the process data buffers are handled with these functions.