CMSIS-FreeRTOS icon indicating copy to clipboard operation
CMSIS-FreeRTOS copied to clipboard

Configurable number of sub priorites

Open CezaryGapinski opened this issue 2 months ago • 0 comments

CMSIS-RTOS2 priorities available to user (Low, BelowNormal, Normal, AboveNormal, High, Realtime) are extended with a 3-bit sub priority and CMSIS-RTOS2 implementation can support flexible number of sub priorities (1, 2, 4 or 8).

Is it possible to implement reduced number of priorities for CMSIS-FreeRTOS port? I think it is a simple bit shift operation in few parts of the code.

Currently configMAX_PRIORITIES must be set to 56. Each priority needs a slot in RAM memory. For 56 priorities it causes high memory consumption. Maybe configMAX_PRIORITIES can be configurable?

configMAX_PRIORITIES 56 support all 8 sub priorities => shift = 0 configMAX_PRIORITIES 28 support 4 sub priorities (ex. Low..Low+1 are effectively the same) => shift = 1 configMAX_PRIORITIES 14 support 2 sub priorities (ex. Low..Low+3 are effectively the same) => shift = 2 configMAX_PRIORITIES 7 support 1 sub priority (ex. Low..Low+8 are effectively the same) => shift = 3

In the simplest form osPriority numbering can be scaled down (ex. for 1 sub priority => shift = 3):

osPriorityLow           =  8,   (8 >> 3) => FreeRTOS priority = 1
osPriorityLow1          =  8+1, ((8+1) >> 3) => FreeRTOS priority = 1
osPriorityLow2          =  8+2, ((8+2) >> 3) => FreeRTOS priority = 1
...
osPriorityLow7          =  8+7, ((8+7) >> 3) => FreeRTOS priority = 1
osPriorityBelowNormal   = 16,   (16 >> 3) => FreeRTOS priority = 2
...
osPriorityRealtime      = 48,   (48 >> 3) => FreeRTOS priority = 6

CezaryGapinski avatar May 01 '24 16:05 CezaryGapinski