Flexcan Handler - background information needed

I am writing a driver to send SDO & PDO CAN packages. I started out with the flexcan loopback example and then adapted it. Now I can not get my head around the “void BOARD_FLEXCAN_HANDLER(void)” function. Where can I find documentation for it?
What am I allowed to do in this function?
How does it get executed? → I’ve put a PRINTF command inside the function but this command does not seem to get executed. If I put the command in the if() condition it gets executed.

Am I supposed to just leave the code how it is in this “BOARD_FLEXCAN_HANDLER” ?

I wonder how i can then specifically make a read operation. Writing to the CAN bus works, I simply add data to the struct and then set the “flexcanTxDataOrRemte” flag. But reading … how do I know that new data has been read? I mean I can send the data but then I need to get feedback when it was sent (which I would know in the function below) but then I need to implement synchronization functions to get the feedback back up?

So yea… if you could answer only a few of my questions I think it would help already a lot. :slight_smile:

Here is the Code of the function:

// This BOARD_FLEXCAN_HANDLER should probably not be touched????

void BOARD_FLEXCAN_HANDLER(void)
{
    PRINTF("Handling stuff \n\r");

    // Solve Tx interrupt
    if (FLEXCAN_GetMsgBufStatusFlag(BOARD_FLEXCAN_BASEADDR, TX_MSG_BUF_NUM))
    {
        PRINTF("A CAN MESSAGE WAS SENT \n\r");

        FLEXCAN_ClearMsgBufStatusFlag(BOARD_FLEXCAN_BASEADDR, TX_MSG_BUF_NUM);

    }

    // Solve Rx interrupt
    if (FLEXCAN_GetMsgBufStatusFlag(BOARD_FLEXCAN_BASEADDR, RX_MSG_BUF_NUM))
    {
        PRINTF("A CAN MESSAGE WAS RECEIVED \n\r");

        // Lock message buffer for receive data.
        FLEXCAN_LockRxMsgBuf(BOARD_FLEXCAN_BASEADDR, RX_MSG_BUF_NUM);
        rxBuffer = *rxMsgBufPtr;
        FLEXCAN_UnlockAllRxMsgBuf(BOARD_FLEXCAN_BASEADDR);

        FLEXCAN_ClearMsgBufStatusFlag(BOARD_FLEXCAN_BASEADDR, RX_MSG_BUF_NUM);

        rxCanReceive = true;
    }
}

BOARD_FLEXCAN_HANDLER is a preprocessor define which is defined in examples/imx7_colibri_m4/board.h. It translates to FLEXCAN2_Handler which is registered as the interrupt handler for FlexCAN2…

You can find some documentation in the doc/ folder. The API Reference Manual has a chapter about FlexCAN. The example in examples/imx7_colibri_m4/driver_examples/flexcan/flexcan_loopback/main.c uses a single variable to notify the main loop that a new message has been received. In a more elaborate application you would probably use FreeRTOS primitives to wake up a task from the interrupt handler and consume the received data there.