Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Queue block

Posted by Grigore-Mihai Dobra on May 2, 2009
I have the following code which reads characters from a queue and puts them on the LCD:

portTASK_FUNCTION_PROTO(vLCDTask, pxParameters)
portCHAR ch;
lcdInit(); /*initialize LCD*/
for (; ;)
if ((qLCD != 0) && (xQueueReceive(qLCD, &ch, portMAX_DELAY) == pdPASS))

and the following code to feed up a queue(from another task):

unsigned portSHORT lcdPutS(unsigned portCHAR* str)
while ((str) && (*str) && (qLCD != 0) && (xQueueSend(qLCD, str++, portMAX_DELAY) == pdTRUE)) ;
return 1;

But my system seems to be blocked somewhere. I expect it to print on the LCD as I feed the queue with data.

Aren't the tasks supposed to YIELD if queue empty on receive or queue full on send? This way, whichever event comes first, will allow the other task to do its job(send on queue empty or receive on queue full).

RE: Queue block

Posted by Richard on May 2, 2009
Could it be tat qLCD is NULL?
Do you know that lcdDispCh() works correctly?
Are you sure str points to printable characters?

Separate to your question, portTASK_FUNCTION_PROTO can be used to define the function prototype, rather than the actual function. In nearly all cases you don't need to use these macros at all and you can just use
void vLCDTask( void *pxParameters)


RE: Queue block

Posted by Grigore-Mihai Dobra on May 2, 2009
qLCD being null won't hang the whole system.
lcdDispCh() working or not won't hang the whole system.
str points to "Hello there!" and nothing more, that won't hang the whole system either.

Finally, the watchdog eats me up because I seem to hang up here:

for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*in vListInsert*/

pxIterator seems to be 0x00 and pxIterator->pxNext seems to be 0x00 too.

If my expectations from the two initial functions is right, then I might found another bug in my shitty compiler. So please confirm the expected behaviour should be the one described in the first post.


RE: Queue block

Posted by Grigore-Mihai Dobra on May 2, 2009
Anyway, the hangup won't occur if either receive or send is commented up.

RE: Queue block

Posted by Grigore-Mihai Dobra on May 2, 2009
Ok... The faulty system seems to be me... :)) The task which is sending gets run before the task which creates the queue gets run. qLCD is thus not initialized, nor it was initialized to 0. So, the task that's sending will send to a bogus queue, eventually thrashing out some variables. This results in the described hang.

xQueueHandle qLCD = 0;

helped me a lot.

RE: Queue block

Posted by Samuel Tardieu on May 2, 2009
Why are you creating the queue in a task, rather than before starting the scheduler? You would not need to test that the queue is not null anymore, and won't run into those problems.

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

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.0 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner