Quality RTOS & Embedded Software

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


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

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

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

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

Cadence Tensilica Cortes

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