i am trying to implement CMSIS RTOS on my project using ThreadX. how ever i found in the file cmsis_os2.c that it is obligatory to have a max priority of 64. i would like to keep it to 32 (ram optimisation) so does anyone has an explication on why i should use 64 and not 32. and does it bother to use 32 and simply modify the cmsis file? this is the code i found:
/* Ensure the maximum number of priorities is modified by the user to 64. */
#if(TX_MAX_PRIORITIES != 64)
#error "CMSIS RTOS ThreadX Wrapper: TX_MAX_PRIORITIES must be fixed to 64 in tx_user.h file"
#endif
CMSIS enumerates the priority with enum osPriority_t
. This is a bad idea in my opinion, but it rather constrains the implementation, and would be hard to change without breaking the abstraction.
In ThreadX having 64 rather 32 priorities carries a 128 byte overhead (so not much of a RAM optimisation). If that is really a problem, then you could in the porting layer map the CMSIS 64 priorities to 32 levels simply by dividing the priority by 2 when creating the task with the native API. That might however modify the scheduling because tasks at priorities Nx2 and (Nx2)+1 would both map to the same priority N.
Another issue with changing the number of priorities is that porting your code to a different CMSIS RTOS2 implementation could change the scheduling behaviour, which rather defeats the object of the abstraction.
You have to take care with CMSIS RTOS2 priorities because in fact only 47 from 8 to 55 are normally used for user tasks, as can be seen from the enumeration. With 0, 1 and 56 reserved and 2 to 7 given no enumeration. How those map to native priorities is implementation dependent, and if you were to change the implementation you would still have to account for the reserved values. It is therefore not advisable to simply pass integer priorities without ensuring that they are in the range osPriorityLow
to osPriorityRealtime7
. It is on the whole not a perfect abstraction.
ThreadX is perhaps unusual in having this overhead related to the number of priority levels. It is also unusual in having a configurable number of priority levels in any case. In many RTOS it is an 8 or 16 bit integer.