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


problems with priorities

Posted by Pietro on September 25, 2007
I have some problems using priorities with tasks.

I have two tasks, the first one (t1) must to take chars form UART, check them and fills a queue (q1). Soon after it sends an ACK orNACK via UART; the second one (t2) must to be listening on q1 and when this queue became to be filled it takes the elements and after a little computation send some response to t1 via a second queue (q2); t1 listens q2 and when it receives somthing writes on the UART.

static portTASK_FUNCTION( t1, pvParameters ) //pvParameters is q1
portCHAR rxCharPC;
FramePC DataToUART;

xUART2 = xSerialPortInit( serCOM2, ser9600, serNO_PARITY, serBITS_8, serSTOP_1, mainCOMM2_QUEUE_LENGTH );

for( ;; )
if ( xSerialGetChar( xUART2, &rxCharPC, mainNO_BLOCK ) )
put results inside Frame_PC after checking.
if ( xQueueSend( *( ( xQueueHandle * ) pvParameters ), ( void * ) &Frame_PC, pollqNO_DELAY ) == pdTRUE )
send ACKvia UART
send NACK via UART

while ( uxQueueMessagesWaiting( q2 ) )
xQueueReceive( q2, &DataToUART, pollqNO_DELAY );

SendUART( DataToUART );


t2 is

static portTASK_FUNCTION( t2, pvParameters ) //pvPArameters is q1
FramePC DataRXed;

for( ;; )
while ( ( uxQueueMessagesWaiting( *( ( xQueueHandle * ) pvParameters ) ) ) )
xQueueReceive( *( ( xQueueHandle * ) pvParameters ), &DataRXed, pollqNO_DELAY );

// computations here

switch (DataRXed.cmd)
xQueueSend( q2, ( void * ) &DataRXed, pollqNO_DELAY );
default: break;

The problem is that if I use the some priority for both tasks, t1 and t2 start correctly, but t1 doesn'n work well. It doesn't put the right characters on UART to send ACK or NACK and doesn't perform the operation that follows soon after (sendUART).
Otherwise If I do an operation of sending ACK that post onto UART LESS character (like 4) t1 works well!!!

I obtain the perfect performance when I write only 2 chars in the ACK (or NACK) and 2 chars in the sendUART.

If I try to set a higher prioritiy to t1 rather than t2, t1 send correctly ACK or NACK, but t2 doesn't start.
If I try to set a higher prioritiy to t2 rather than t1, t2 waits on q1 forever as t1 doesn't start.
If I introduce some delays on t1 (after sending NACK or after SendUART) t2 doesn't start.

I introduce delays in this way:

I declare

#define SYS_DELAY( ( portTickType ) 100 / portTICK_RATE_MS ) // 100ms

And then I put

vTaskDelay( SYS_DELAY ); in the locations specified before.

I wrong something surely.
How can I solve this problem?

Thank you,


RE: problems with priorities

Posted by Richard on September 25, 2007
I don't quite follow the sequence here, but it looks like you are not not blocking on your queue send/receives, but instead polling. When the tasks are the same priority this will be inefficient. When the tasks are of different priorities then the low priority task will get starved of processing time and never run. This is because, without blocking, the higher priority task is always wanting processor time.


[ 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