In my application I would like to configure FlexCAN to receive a message with a specific ID. I understand that I need to setup a mailbox to receive the message using FLEXCAN_DRV_ConfigRxMb followed by FLEXCAN_DRV FLEXCAN_DRV_Receive.
My question is the following:
When this message is received and the callback is invoked can I safely call both of these functions again to configure the mailbox to receive the same message ID again from within the callback? I need this to happen as fast as possible so as to no drop messages. If there is a better way of handling this please let me know.
Thanks!
Hello,
If you want to be sure you don't lost messages between MBs config, you can use RxFIFO if you don't use CAN FD messages. To do that you need to set RxFIFO filters.
flexcan_id_table_t flTable[8];
for(i=0;i<8;i++)
{
flTable[i].id = 2;
flTable[i].isExtendedFrame=false;
flTable[i].isRemoteFrame=false;
}
FLEXCAN_DRV_ConfigRxFifo(INST_CANCOM1,FLEXCAN_RX_FIFO_ID_FORMAT_A,&flTable[0]);
/* You can set a filter mask or not for acceptance by setting global mask to be more easy to handle or you can
skip this part and will check all the id filters as set by initialization */
/* This will set mask to 3 and check ID type as filter set */
FLEXCAN_DRV_SetRxFifoGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_STD, ((1U<<30U)|0x3));
/* Sets the Rx masking type as rx global mask */
(void) FLEXCAN_DRV_SetRxMaskType(INST_CANCOM1, FLEXCAN_RX_MASK_GLOBAL);
/* End of filter acceptance masking */
Call for transfer of a message already in fifo. For every message in fifo you need to call again the function. If you have a callback installed you can call it again in the event triggered is FLEXCAN_EVENT_RXFIFO_COMPLETE.
status = FLEXCAN_DRV_RxFifo(INST_CANCOM1, &recvBuff);
or you can poll the MBs status for RxFIFO which is MBs 0 all the time.
while(FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, 0U) == STATUS_BUSY);
BR,
Alexandru Nan
Hi Alexandru,
Any suggestions on this?
Thanks,
Sumit
Hi Sumit,
I think you can safely call FLEXCAN_DRV_Receive within callback function in FLEXCAN_EVENT_RX_COMPLETE event. You do not call FLEXCAN_DRV_ConfigRxMb again.
FLEXCAN_DRV_Receive just enable MB interrupt which was disabled within IRQ handler before callback is called.
BR, Petr
Thanks for the response Alexandru. We are using CAN FD hence RXFIFO is not an option.