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


wrong use of #defines in xQUEUE type, v9.0.0

Posted by odman on May 25, 2017

~~~ In queue.c, typedef struct QueueDefinition #if ( configUSETRACEFACILITY == 1 ) UBaseTypet uxQueueNumber; uint8t ucQueueType; //<-- Line 162 #endif


In xQueueGenericReceive(), line 1279 #if ( configUSEMUTEXES == 1 ) { if( pxQueue->uxQueueType == queueQUEUEIS_MUTEX ) {

In my FreeRTOSConfig.h:

define configUSE_MUTEXES ( 1 )
define configUSETRACEFACILITY ( 0 )

~~~ I'm not sure how this even compiles, but it does with GNU ARM 4.9.3. The result is that illegal memory is written with unpredictable consequences.

cheers Knut

wrong use of #defines in xQUEUE type, v9.0.0

Posted by heinbali01 on May 25, 2017

Please have a look at the large comment around line 97, and these defines :


define pxMutexHolder pcTail
define uxQueueType pcHead


In case a queue object is in fact a mutex, the two fields are not used in their normal way (head, tail). These are pointers, not characters. uxQueueType will be set to NULL (queueQUEUE_IS_MUTEX).

It may look a bit confusing, but it is entirely local to tasks.c. I'm sure it was done to save a few bytes of RAM.

In another C project a union could be used for this, but union's are not supported by all compilers that are used to compile the FreeRTOS kernel.

The member used when tracing: ucQueueType is indeed an 8-bit field that holds a copy of 'ucQueueType' that was used during creation.

In short: there is nothing wrong with it.

wrong use of #defines in xQUEUE type, v9.0.0

Posted by heinbali01 on May 25, 2017

but it is entirely local to tasks.c

Sorry, not task.c but queue.c of course.


wrong use of #defines in xQUEUE type, v9.0.0

Posted by odman on May 25, 2017

wow. Missed that. Thanks. The good news is that FreeRTOS works, the bad news is that something else is messing up my stack...

[ 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