This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTX with CMSIS RTOS : dynamically create MUTEX

hi

i'm searching how to dynamically create mutex in CMSIS-RTOS/KEIL.

i saw the osMutexCreate only accept const osMutexDef_t *

do you know how i can manage to create a mutex, runtime and dynamically allocated in memory please ?

i'm porting a code where there is Mutex_Create(); everywhere so i didn't found other possibilities, yet.

thank you

best regards
KArl

Parents
  • Hi,

    I thank you for your answer. My difficulty with a pool of mutex is the following one : I'm porting a library which use a lot of mutex allocation.

    - I don't know how many mutex I need in advance, so i'll need to create a big pool and try to profile with a variable how many mutex creation is done in runtime.

    - the other drawback of the CMSIS-RTOS/RTX implementation is the initialization process : - first osMutexDef(mutex_name) as a global variable. - then mutex_id=osMutexCreate(osMutex (mutex_name)); this is hard to automatize when there is a important number of semaphore, like a pool described before. This process is very static.

    - it seems that some other os have a more adapted (dynamic) process like FREERTOS (xSemaphoreCreateMutex( void ) or some proprietary ones like TI SYSBIOS or even Linux.

    best regards
    Etienne

Reply
  • Hi,

    I thank you for your answer. My difficulty with a pool of mutex is the following one : I'm porting a library which use a lot of mutex allocation.

    - I don't know how many mutex I need in advance, so i'll need to create a big pool and try to profile with a variable how many mutex creation is done in runtime.

    - the other drawback of the CMSIS-RTOS/RTX implementation is the initialization process : - first osMutexDef(mutex_name) as a global variable. - then mutex_id=osMutexCreate(osMutex (mutex_name)); this is hard to automatize when there is a important number of semaphore, like a pool described before. This process is very static.

    - it seems that some other os have a more adapted (dynamic) process like FREERTOS (xSemaphoreCreateMutex( void ) or some proprietary ones like TI SYSBIOS or even Linux.

    best regards
    Etienne

Children
  • Don't forget that what Linux does is irrelevant when you get to embedded systems with often very limited amount of RAM.

    The design is made on the assumption that you should be able to write applications with zero involvement of malloc/free, which means there will not be any issues with any fragmented heap making the software fail after having been run for a longer time. The smaller heap you have, the more danger you have of fragmentation killing the application.

    So what is done is a general-purpose OS is irrelevant when discussing an implementation for smaller microcontrollers.

    It's possible to abuse the original macros a bit to make it easy to set up a pool of mutex as an array.