rewrite queue struct or use freertos queue

gurushen wrote on Thursday, June 13, 2013:

Hi, I need a queue structure for passing bytes for a uart driver. I was using the freertos queue implementation but a co-worker insist on writing our own queue struct. Is there any benefit of rewriting our own?

richard_damon wrote on Thursday, June 13, 2013:

It might be possible to write a slightly more efficient queue knowing that one end is alway an interrupt routine, and maybe some others knowable special cases (like it is always 1 byte at a time being sent, if that is how you are doing it). I am not sure if the improvements are worth the extra work and risk of bugs.

jakbird1 wrote on Saturday, June 15, 2013:

While the FreeRTOS queue works well and is easy to use it does have some drawbacks.  It’s oriented toward one character at a time rather than block transfers.  I did go the separate FIFO driver route in order to minimize interrupt overhead.  I read and write blocks of data through a FIFO, also making use of DMA to reduce USART TX interrupts by as much as 100 to 1 (sending large Modbus messages).

If your data rate is low use the FreeRTOS queue, but if you have a high data rate your co-worker is right…roll your own buffer management.  USART interrupt overhead can be significant.
  Jack Peacock

rtel wrote on Saturday, June 15, 2013:

It’s oriented toward one character at a time rather than block transfers

A queue can be created to hold blocks of any size, although each block in a queue has to be the same size.  To queue really large blocks you would queue a pointer to the block instead of the block itself.

The FreeRTOS queues are designed for their purpose.

Regards.