hello, i'm using KSDK 1.3 on MK10DX256VLQ10 microcontroller.
i'd like to have some clarifications on the usage of flexcan RX fifo.
here's my setup code:
/*number of can 2 rx fifo filters id*/ #define CAN_2_RX_FIFO_ID_FILTER_NUM kFlexCanRxFifoIDFilters_8 /*number of elements of can 2 rx fifo filters id array*/ #define CAN_2_RX_FIFO_ID_FILTER_ARRAY_SIZE (CAN_2_RX_FIFO_ID_FILTER_NUM + 1) * 8 static flexcan_user_config_t can_2_config = { 16, CAN_2_RX_FIFO_ID_FILTER_NUM, true, kFlexCanNormalMode }; static flexcan_state_t can_2_state; static flexcan_msgbuff_t can_2_fifo; static flexcan_id_table_t can_2_fifo_id_table; static uint32_t can_2_rx_fifo_id[CAN_2_RX_FIFO_ID_FILTER_ARRAY_SIZE]; static uint32_t can_2_rx_msg_ids[] = /*MUST be smaller than can_2_rx_fifo_id array*/ { CAN_2_MSG_ID_1, CAN_2_MSG_ID_2, CAN_2_MSG_ID_3, CAN_2_MSG_ID_4, CAN_2_MSG_ID_5, CAN_2_MSG_ID_6 }; void CAN_Init() { configure_flexcan_pins(CAN_2_INSTANCE); FLEXCAN_DRV_Init(CAN_2_INSTANCE, &can_2_state, &can_2_config); FLEXCAN_DRV_SetBitrate(CAN_2_INSTANCE, &can_bit_rate_500kbs_50Mhz); /* 500kbs */ FLEXCAN_DRV_SetRxMaskType(CAN_2_INSTANCE, kFlexCanRxMaskGlobal); FLEXCAN_DRV_SetRxFifoGlobalMask(CAN_2_INSTANCE, kFlexCanMsgIdStd, 0x7FF); /*initialize can 2 fifo*/ can_2_fifo_id_table.isExtendedFrame = false; can_2_fifo_id_table.isRemoteFrame = false; for(int i = 0; i< NUM_ELEMS(can_2_rx_msg_ids) ;i++) { can_2_rx_fifo_id[i] = can_2_rx_msg_ids[i]; } can_2_fifo_id_table.idFilter = can_2_rx_fifo_id; FLEXCAN_DRV_ConfigRxFifo(CAN_2_INSTANCE, kFlexCanRxFifoIdElementFormatA, &can_2_fifo_id_table); } void CAN_Receive() { if(FLEXCAN_DRV_GetReceiveStatus(CAN_2_INSTANCE) == kStatus_FLEXCAN_Success) { FLEXCAN_DRV_RxFifo(CAN_2_INSTANCE, &can_2_fifo); /* process message here...*/ } } void CAN_Task() { CAN_Init(); /*trigger MSG reception*/ FLEXCAN_DRV_RxFifo(CAN_2_INSTANCE, &can_2_fifo); for (;;) { CAN_Receive(); } } /* Implementation of CAN0 handler named in startup code. */ void CAN1_ORed_Message_buffer_IRQHandler(void) { FLEXCAN_DRV_IRQHandler(1); }
i'm using freeRTOS and the CAN_Task() has a 10ms periodicity.
here's what i'm trying to achieve:
i successfully got the CAN1_ORed_Message_buffer_IRQHandler interrupt to be called and i saw that when the task runs, it passed the check FLEXCAN_DRV_GetReceiveStatus == kStatus_FLEXCAN_Success and FLEXCAN_DRV_RxFifo returns me the msg received which i'm able to process.
here's some questions and doubts:
Thank you so much for your support, feel free to point me to any other discussions in the forum or to useful documentation.
Regards,
Simone
Hi,
I have exactly same questions. Is there anyone can give answer. Previously there was such a interrupt function
void ComCAN_OnFullRxBuffer(LDD_TUserData *UserDataPtr, LDD_CAN_TMBIndex BufferIdx)
{
/* Write your code here ... */
handleRxBuffer(BufferIdx);
}
and since I knew the bufferID, I was getting frame with the function below
ComCAN_ReadFrame(canPtr, BufferIdx, &(canMsgList[bufferID].frame));
Now, how can I know which message buffer has new message.
Regards,
Okan,