AnsweredAssumed Answered

Tasks don't yield to each other with FreeRTOS mutex in KSDK 1.3

Question asked by Marco Aurelio P. Coelho on May 25, 2016
Latest reply on Jun 2, 2016 by Marco Aurelio P. Coelho



I'm still a beginner at FreeRTOS and I have too much to learn yet. So, I apologize for the simple questions...


I'm playing with my FRDM-KL25Z in KDS and created a new project with KSDK v. 1.3 and Processor Expert to see how a mutex works in FreeRTOS.


I have 6 tasks of same prority level which compete for the same mutex. Between taking and giving the mutex, each task increments a global variable (one different variable for each task).


As far as I know, when a mutex is realeased, it gets available for the next task waiting for it and this task, which just released (gave) the mutex, is blocked as it tries to take the mutex again in its while loop. Am I right?


But, that is not what I see as I debug the code. The variable is incremented several times before it yields to the next task, instead of being incremented just once.


The only way to get a task imediately yielding to another one is adding a "Task_Yield" or a "Time_Delay" after "Semaphore_Give". Curiously, the FRDM-K64F FreeRTOS mutex demo project in KSDK v. 2 puts a Task_Yield after "Semaphore_Give". But, that doesn't make any sense, because it is as if the mutex there is useless.


Why this is happening? Can anybody throw me a light on this please?



Thanks and best regards,


Marco Coelho

Applications Engineer

Siletec Eletronica