Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Queuing Question - Different Integral Types

Posted by Westmoreland Engineering on October 12, 2012
Hello Richard and Fellow FreeRTOS'ers,

I have a question about Queuing - can I use one queue that is large - large being 128 bytes in an embedded system - for different integral types or is that just a no-no?

For instance - I would like to use one General Q for a UART, let's say - but, I need to pass different types of packets. I am finding the overhead of doing something like vPrintString() (have written my own which is similar) - could be a little excessive in some cases - but will the Q 'behave' properly if I were to pass something like:

1) a structure pointer to a communications packet that is, let's say, 48 bytes; and then
2) a structure pointer for a 3 byte 'ACK' packet
3) just a byte of some sort,
...

Does the Q only support one integral type? For instance; if I have sized a Q for chars but one of my structure's has unsigned shorts, for instance - will the Q operate properly? I can unwrap this on the other end char-by-char - but I would like to be able to use the Qing facilities and not have to declare a specific Q for each specific type of packet.

Thanks In Advance,
John W.

RE: Queuing Question - Different Integral Types

Posted by Richard Damon on October 13, 2012
A queue only supports items of one type (or more precisely one size). This item could be a union of the various types of object you want to queue (or a struct with a flag to indicate the type and then a union).

It could also be a void* pointer (or a structure with a flag and a void* pointer), with the pointer pointing to the data. In this case the queue will NOT save the data pointed by, so the program needs to manage the life of these buffers and keep track of when they are free to reuse or still busy. One way to do this is to heap allocate them and free them when done. Many design rules don't like using the heap in embedded environments, due to the fact that you need to make sure you can handle a failed allocation gracefully.

Another option is to enqueue a packet in smaller pieces, where some packet use fewer pieces than others to reduce queue space used for the smaller packets (if that is important). One thing to watch out for is that if multiple tasks might be adding or removing packets from the queue, that side will need a mutex or equivalent to avoid interleaving or splitting of packets.

The third option is to just queue up a maximal size packet. This wastes queue space for small packets, but simplifies the code significantly which may be a very positive result.

Which one to use depends a lot on the application and the sizes and likelihood of different types of packets. In general large packets are normally best to send via pointers, to avoid all the data copying that otherwise happens. 48 byte packets, particularly if a lot of the packets are of that size, may qualify as large here. It may not be large enough that variable size buffers are important and perhaps ALL packets are make 48 bytes, and take the loss of space efficiency to greatly limit program complexity. Perhaps if most packets are 48 or 3, it might make sense to have two buffer sizes, especially of the ratio of the number of needed packets of each size is known.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists