MQX CAN bus API usage

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX CAN bus API usage

861 Views
kaif
Contributor I

Hi,

I am writing my first small application using MQX 4.0 and it's CAN bus drivers on a K60 tower board. I've had a look at the kflexcan example code that comes with the MQX bundle. After playing around with it, I'm now wondering if I understand the concept behind it correctly. What I mean is this:

The kflexcan API offers a FLEXCAN_Rx_message() that takes a mailbox as parameter. Now, a mailbox is initialized by FLEXCAN_Initialize_mailbox() that takes a specific CAN ID as parameter. Later you just call _lwevent_wait_ticks() which will block the current task until a message with the requested CAN ID pops up in the mailbox. So far, this is very comfortable and easy to use.

But let's say I'm working with a large number of different CAN IDs. How does this approach work then? Do I have to add a mailbox for every CAN ID that can appear on the bus? That doesnt sound like the way to go..

What I would expect is a function that takes a CAN ID as parameter and then blocks the current task until it receives such a message or hits a timeout. Something like this: can_message_t can_read(can_id_t id, uint_32 timeout). For my purposes this wouldn't need to be thread safe. Do I have to implement such a function myself? How are you guys working with the provided API, regarding multiple CAN IDs?

Thanks for any input!

Regards,

Kai

0 Kudos
3 Replies

403 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Kai,

For your case, I think you may use the RX FIFO feature, which is supported in MQX 4.1. You may download it and find it in K70's BSP.

Hope that helps,


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

403 Views
kaif
Contributor I

Unfortunately this is not an option for me as I'm using MQX 4.0.2 and currently cannot switch to 4.1 because of some troubles I'm having with the Atheros WiFi driver.. :smileysad:

0 Kudos

403 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Kai,

Maybe you can port the flexcan driver from MQX 4.1 to 4.0.2. You may find there is option for TWR-K60N512 as below:

3.png

Or PE drivers can also be a good option, you may disable flexcan in user_config.h and use the  driver code generated by PE instead.

Hope that helps,


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos