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


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 ]    [ 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