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


Tasks of equal priority after unblocking

Posted by Amon-Ra on March 13, 2012
Hello again.
Still using FreeRTOS (preemptive multitasking) on STM32F103VE and GCC.

If I have two tasks of equal priority, both of them are blocked, and then another task gives two different samaphores, one unblocking fist task, another - unblocking second.
In which order will sheduler choose tasks to enter running state?

This is essential for me, because both of these tasks are accessing shared peripheral (DMA), so if sheduler will always choose, for example, first one, then this task will block DMA, and second, after switching to it, will just block again on new semaphore.

Here is an example:

xSemaphoreHandle DataSent; //New data arrives with acknoledge of success transmit,
xSemaphoreHandle NewDataArrived; //so thees two are given simultaneously
xSemaphoreHandle DMAFree; //Controls access to DMA

static void taskIRQHandler(void *pvParameters) //not ISR, just high priority task

static void taskTx()

static void taskRx()

RE: Tasks of equal priority after unblocking

Posted by Richard on March 13, 2012
With respect to each other, the task that is unblocked first will run before the task that unblocked second. That is not a good way or architecting the system however, because the two tasks are of equal priority, you can make no guarantees about how far the task will get through its code before a context switch to the other task will occur. If it is essential that one task executes to a certain point before the other task executes then it should be assigned a higher priority than the other task.


RE: Tasks of equal priority after unblocking

Posted by Amon-Ra on March 13, 2012
Thanks again!
Yes, I thought about making RX task's priority higher than Tx, but then changed my mind.
It may cause Tx FIFO buffer of tranciever get empty, because instead of posting new data, system will continue reading Rx FIFO.
Ideal case, I suppose, is reading one Rx FIFO item (if available), then posting one Tx FIFO item, and so on.
So, may be, I'll make just one diver task for transmitting an receiving, instead of two separate, and will switch between Rx and Tx activity manually.

RE: Tasks of equal priority after unblocking

Posted by Amon-Ra on March 13, 2012
*dRiver task, ofcourse)

RE: Tasks of equal priority after unblocking

Posted by Richard Damon on March 13, 2012
First, it isn't THAT bad for the second task to start to shortly hit a second block on the DMA not being free. Unless you are really tight on CPU resources,

A second option might be to have taskIRQHandler only give 1 semaphore (the one to the task you want to run first), after setting a flag to that task to tell it that when it is done, as well as giving the DMA flag, to give the other task flag. This does add complexity and coupling between tasks, so I would only do this if you can show that the performance of allowing the possible extra block is significant.

Note that if the first task to start normally would run to the point of giving the DMA semaphore without blocking, and takes significantly less time than a timer tick, most of the time the second task may actually never get started until the semaphore is free, and you don't pay the cost of the block normally. If the first task normally has to block during its operation between taking and giving the DMA semaphore, so the second task does run and block, then the time for the first task to be blocking generally will override the cost for the second task's block, making it insignificant.

RE: Tasks of equal priority after unblocking

Posted by Amon-Ra on March 13, 2012
richard_damon, you are probably right about "isn't THAT bad for the second task to start to shortly hit a second block on the DMA not being free", because when traciver is in half-duplex mode (awaiting acknoledge after each transmission before asserting DATA_SENT_IRQ), interval between two interrupts are much longer than it takes to receive payload and transmint next package via DMA.

But I am actually is stuck on another problem, there is terrible bug in blocking, (here is my question about it https://sourceforge.net/projects/freertos/forums/forum/382005/topic/5113026)
and I can not continue working with Tx/Rx - just sucking in Tx. I'll appreciate if you'll take a look.

[ 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