5 years, 10 months ago.

mbed Queue vs FreeRTOS Queue

From what I gather, freeRTOS has queues that pass data by value, rather than reference. This link explain why: http://www.freertos.org/Embedded-RTOS-Queues.html

But what I gather from the mbed handbook, mbed queues work by reference. Using an osEvent to contain the pointer. I have found this to be particularly annoying. So my question is: Why?

1 Answer

5 years, 10 months ago.

Because someone at ARM considered it a better idea?

Values are easier if you just have to pass one variable. Pointers are better when it is a larger buffer. They also mention this in the FreeRTOS documentation, where they then use their values as pointers. I guess if you really want you could also in CMSIS-RTOS just put the value of your variable as pointer location, as long as it is a 32-bit one, although it would be ugly.

But what is the problem with it? It is just a single operation to go from pointer to value.

Accepted Answer

Im trying to put CANMessages in a queue. CANMessages are bigger than 32 bit, so I cannot put them in a pointer. I furthermore try to avoid allocating and deallocating memory, as there will be a lot of CANMessages. If I give the pointer to the CANMessage and then return from the interrupt, the CANMessage is removed from the stack and the pointer will point to invalid data.

posted by Xander Houtman 11 Jan 2015

MemoryPool might help you with it, but it is true, you will need to allocale/deallocate the data, which I agree is another step you prefer not to take, especially due to risk of memory leaks.

That said especially since a CAN message is more than 32-bit, from performance pov it makes sense to use pointers.

posted by Erik - 11 Jan 2015