This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-AM243: When is the callback function of an EtherCAT slave device called?

Part Number: LP-AM243

Tool/software:

Hello

I am using your LP-AM243 board to evaluate the EtherCAT Slave Stack

The SDK version is ind_comms_sdk_am243x_09_02_00_08

The sample project uses 401_simple from EtherCAT Slave.

I registered the callback function for registering the process data buffer and the user application callback function with reference to the Buffer Handling API chapter.

InputPD pre-read callback: appPreSeqInputPD()
OutputPD pre-write callback: appPreSeqOutputPD()
InputPD after loading callback: appPostSeqInputPD()
OutputPD after loading callback: appPostSeqOutputPD()
User application callback: EC_SLV_APP_SS_applicationRun()

My question is, if I register the callback functions as above, is the order in which the callback functions are called guaranteed as follows?

1. Frame reception

2. appPreSeqInputPD()

3. appPostSeqInputPD()

4. EC_SLV_APP_SS_applicationRun()

5. appPreSeqOutputPD()

6. appPostSeqOutputPD()

When managing flags for process data buffering, we are concerned that if callbacks are called in a different order than expected, such as appPreSeqOutputPD() being called before EC_SLV_APP_SS_applicationRun(), the flag management sequence will be disrupted.

For reference, the following is an excerpt from the custom source code for the callback function registration process.

// InputPD pre-read callback function registration
error = EC_API_SLV_cbRegisterPreSeqInputPDBuffer(
    pApplicationInstance_p->ptEcSlvApi,
    (EC_API_SLV_CBPreSeqInputPD_t)appPreSeqInputPD,
    pApplicationInstance_p
);
if (error != EC_API_eERR_NONE)
{
    OSAL_printf("Register PreSeqInputPD Error code: 0x%08x\r\n", error);
    /* @cppcheck_justify{misra-c2012-15.1} goto is used to assure single point of exit */
    /* cppcheck-suppress misra-c2012-15.1 */
    goto Exit;
}
OSAL_printf("Register PreSeqInputPD Callback\r\n");

// OutputPD pre-write callback function registration
error = EC_API_SLV_cbRegisterPreSeqOutputPDBuffer(
    pApplicationInstance_p->ptEcSlvApi,
    (EC_API_SLV_CBPreSeqOutputPD_t)appPreSeqOutputPD,
    pApplicationInstance_p
);
if (error != EC_API_eERR_NONE)
{
    OSAL_printf("Register PreSeqOutputPD Error code: 0x%08x\r\n", error);
    /* @cppcheck_justify{misra-c2012-15.1} goto is used to assure single point of exit */
    /* cppcheck-suppress misra-c2012-15.1 */
    goto Exit;
}
OSAL_printf("Register PreSeqOutputPD Callback\r\n");

// InputPD Loading Callback Function Registration
error = EC_API_SLV_cbRegisterPostSeqInputPDBuffer(
    pApplicationInstance_p->ptEcSlvApi,
    (EC_API_SLV_CBPostSeqInputPD_t)appPostSeqInputPD,
    pApplicationInstance_p
);
if (error != EC_API_eERR_NONE)
{
    OSAL_printf("Register PostSeqInputPD Error code: 0x%08x\r\n", error);
    /* @cppcheck_justify{misra-c2012-15.1} goto is used to assure single point of exit */
    /* cppcheck-suppress misra-c2012-15.1 */
    goto Exit;
}
OSAL_printf("Register PostSeqInputPD Callback\r\n");

// Register callback function after writing to OutputPD
error = EC_API_SLV_cbRegisterPostSeqOutputPDBuffer(
    pApplicationInstance_p->ptEcSlvApi,
    (EC_API_SLV_CBPostSeqOutputPD_t)appPostSeqOutputPD,
    pApplicationInstance_p
);
if (error != EC_API_eERR_NONE)
{
    OSAL_printf("Register PostSeqOutputPD Error code: 0x%08x\r\n", error);
    /* @cppcheck_justify{misra-c2012-15.1} goto is used to assure single point of exit */
    /* cppcheck-suppress misra-c2012-15.1 */
    goto Exit;
}

// Register callback function User ApplicationRun
EC_API_SLV_cbRegisterUserApplicationRun(
    pApplicationInstance_p->ptEcSlvApi,
    EC_SLV_APP_SS_applicationRun,
    pApplicationInstance_p
);
if (error != EC_API_eERR_NONE)
{
    OSAL_printf("Register EC_SLV_APP_SS_applicationRun Error code: 0x%08x\r\n", error);
    /* @cppcheck_justify{misra-c2012-15.1} goto is used to assure single point of exit */
    /* cppcheck-suppress misra-c2012-15.1 */
    goto Exit;
}

  • Hello,

    The callback execution sequence would be as below.

    1. Frame reception

    2. appPreSeqOutputPD()

    3. appPostSeqOutputPD()

    4. EC_SLV_APP_SS_applicationRun()

    5. appPreSeqInputPD()

    6. appPostSeqInputPD()

    Kind Regards,

  • Thank you for your reply.

    I checked again and found that my sequence was incorrect and that it was exactly as you suggested.

    I will check again.

    Regarding this sequence, is there a case where the order of the sequence is reversed, for example, when ESM is in OP state and 5. appPreSeqInputPD() is called before 3. appPostSeqOutputPD() is called in one cycle?

    Since your SlaveStack is provided as a library, I have no way of confirming that the sequence is guaranteed, so I am asking the question.

    Thank you in advance.

  • Hello,

    For various synchronization modes specified in the EtherCAT specification, the sequence would be PDO output mapping > Application > PDO input mapping. Hence the above specified sequence should be valid in all synchronization modes. 

    Kind Regards,