Teensy 4.1 FreeRTOS and FlexCAN: reading from 2 CAN busses to multiple tasks

Nicc

Member
Hello,

I'm working on a project that involves using all three CAN busses, using FlexCAN_T4, and managing tasks using FreeRTOS.

Of the three CAN busses, CAN1 and CAN2 is Rx and Tx, CAN3 is only Rx. From CAN1 and CAN2, both will receive data/commands that, in the end, need to be sent to multiple RTOS tasks; so CAN1 may send to task1 and task2 while CAN2 may need to send to task 1 and task 2 as well. My question is how to best receive, sort, and distribute these received CAN messages. Regardless of how this is done, the tasks that receive the CAN messages aren't awoken by the CAN messages and sleep for a consistent amount of time. Although I expect a set of non-duplicate unique-ID CAN messages to be received when the task awakens, it's not an issue if they are not sent (well that's my problem but not a hardware/software problem :rolleyes:).

I currently have two ideas in mind, the first with two variants:

1) Use a Rx interrupt on each CAN bus that:
A) sorts and sends each CAN message to a queue for each task large enough for the expected number of message for that task plus a small buffer for duplicates.
B) sorts and sends each CAN message to a queue set for each task of semaphores to carry one of each message I'm expecting
Either approach would have their queues/queue sets read from each respective task once awoken.

2) Set up a filter for each mailbox in a CAN channel for each task that I want and use the mailboxes as the storage with each task reading from the hardware mailboxes. So let's say MB0 - MB10 are just for task1 and MB11 - MB20 is for task 2, each task would read the specific mailboxes they need and check for new messages.

My concerns with A): seems like a lot of queues or interrupts or semaphores; how many is too many? Is it too complicated?
My concerns with B): The FlexCAN_T4 library does not support reading from specific mailboxes currently, although looking at the source code it doesn't appear to be too hard to do I'm not sure if there's a hardware reason it's not possible. Also I worry about task to task safety: what if a task is in the middle of accessing a resource in CAN1 and another task interrupts and and reads from another MB in CAN1? I don't know if this would cause issues.

Any thoughts and suggestions are appreciated.
Thanks
 
Back
Top