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


Task Priority define

Posted by vincent on July 31, 2013

Is there a rule to define each task's priority ?
eg, A task is used to collect data. B task digest the data. B priority should be higher than A task ?

in STM32 demo code with LWIP , I found that ethernet task priorty is lower than TCPIP task priorty .
but i think that ethernet task is collecting input packet, TCPIP digest those packets, ethernet priority should be higher than
TCPIP tas,, am I right ?


RE: Task Priority define

Posted by Richard on July 31, 2013
There are no rules as such, you just need to make a judgement which is dependent on the application you are writing.

Using Ethernet as an example - what do you want the Ethernet to achieve? What are the resource constraints of the system?


+ You want a received packets to be processed as quickly as possible, or

+ You have a limited number of network buffers, and must therefore free used buffers as quickly as possible so they can be reused by packets that arrive in the future


Make the task that processes the TCP/IP stack (say task A) lower priority than the task that handles received packets (say task B). You can then see a scenario where:

Task A receives a packet and puts it through the TCP/IP stack.
Task A sends the packet to Task B
Task B is higher priority so preempts task A, so the packet is processed immediately
Task B finishes with the packet, freeing up the buffer that contained the packet
Task A runs again with the buffer that contained the packet it passed to task B already free and available for re-use.

Then consider a scenario where you don't have to worry about running out of buffers. In that case it might (depending on the application) be better to have task A higher priority than task B. That way if another packet comes in before task B has finished processing the first packet task A can run immediately to buffer the new packet with risk of it being lost. Then the new packet is already available for Task B when it has completed processing the first.


[ 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