We are using OS version: V5.18.0.3
We have a function that uses mutex, and it is used inside tasks and in ISR function.
In order to avoid OS error, mutex usage is under condition, checking if caller is in task execution or in ISR exection, using API OS_InInterrupt()
See example code below
Display All
This solution works fine and as expected from embos documentation for API OS_InInterrupt() in both scenarios
BUT, instead, if the same function is used as callback for a timer SW (where caller is OS code that is called in OS sysTick ISR), API OS_InInterrupt() return WRONG value (it returns "NO isr"),
so our code goes in OS_error function for invalid usage of OS API inside an ISR
I didn't see any other way for our code to understand if caller is task code or SW timer, so i think this is an API bug
Attached screenshot from debugging:
(1) timer with callback and mutex create
(2) debug inside function called by SW timer, where isISRtest from OS_InInterrupt() is showed with wrong value
(3) after this, mutex function is called and code goes in OS_error
We have a function that uses mutex, and it is used inside tasks and in ISR function.
In order to avoid OS error, mutex usage is under condition, checking if caller is in task execution or in ISR exection, using API OS_InInterrupt()
See example code below
C Source Code
- void doSomething(void)
- {
- bool isISR = FALSE;
- // check if it is called inside ISR
- isISR = (OS_InInterrupt()) ? TRUE : FALSE;
- // thread safe access if caller is NOT an ISR
- if ( isISR == FALSE )
- {
- OS_Use(&some_mutex);
- }
- // do something code
- // thread safe access if caller is NOT an ISR
- if ( isISR == FALSE )
- {
- OS_Unuse(&some_mutex);
- }
- }
BUT, instead, if the same function is used as callback for a timer SW (where caller is OS code that is called in OS sysTick ISR), API OS_InInterrupt() return WRONG value (it returns "NO isr"),
so our code goes in OS_error function for invalid usage of OS API inside an ISR
I didn't see any other way for our code to understand if caller is task code or SW timer, so i think this is an API bug
Attached screenshot from debugging:
(1) timer with callback and mutex create
(2) debug inside function called by SW timer, where isISRtest from OS_InInterrupt() is showed with wrong value
(3) after this, mutex function is called and code goes in OS_error
The post was edited 2 times, last by pbizzarri ().