Detect calling context (ISR or task)

Hello

I need to provide a way to an external library to stop timers.
The problems is that it call it from interruptions or not.
In my stopTimer function, that I need to provide, if I’m calling xTimerStopFromISR or xTimerStop in the wrong context, I’m going into an error.

Would you have a solution for this?

Maybe I’m not seeing another way of doing it…

Thank you
CBL

What if following the FreeRTOS convention and provide stopTimer and stopTimerFromISR ?

Thanks for your answer.
Sadly, I can’t modify the library that is calling stopTimer

Ahh … you’ve to provide a callback with a fixed API…
To the rescue some ports as Cortex-M3/4 provide xPortIsInsideInterrupt() in portmacro.h which can be used to detect ISR context. AFAIK some other 3rd party libs use this mechanism to provide generic APIs, too.

Exactly…
Thank you, that should do the job! I am using an STM32L746 so it should be Cortex M4 but I can’t find it in my portmacro.h. I will dig into this! Thank you for your help!

Here it is - https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/portable/GCC/ARM_CM4F/portmacro.h#L172

Thank you for your help, I have included it inside my portmacro.h and it works perfectly!

The identical function could be made available for the M0, if anyone wanted it enough