Assume I’ve received a callback. It could have been from an ISR or from an xTimer expiration.
If I’m inside an ISR, I need to call xTaskNotifyFromISR(). But if it’s an xTimer notification, I believe I need to call xTaskNotify().
So: is there a way to determine dynamically if I need to call xTaskNotifyFromISR() vs xTaskNotify()? Alternatively, do bad things happen if I call xTaskNotifyFromISR() from within an xTimer callback?
(To repeat myself: I’m not defending this as good design. But it could simplify the code design in this specific case…)
For Cortex-M MCUs there is a Processor Status Register IPSR telling the current IRQ number which could be checked in the associated callback.
I think I’d go this way because it’s HW managed and inherently race free (if I’d have to stick to this unfavorable design).
Answer actually depends on the port you are using. Generally, if the port you use supports interrupt nesting (such as Cortex-M, RX, PIC32, etc.) then you can call the FromISR versions from tasks. The opposite is not true - you cannot call the standard versions from interrupts. Maybe this information needs to be added to https://www.freertos.org/FAQ_API.html#IQRAPI