Am I in task or ISR ?

michaeln32 wrote on Sunday, March 11, 2018:


Can you please tell me how can I know if I am in task or ISR ?

Is there an freeRTOS API for this issue ?

Thank You


rtel wrote on Monday, March 12, 2018:

You can always query the hardware itself, other than that it depends
which port you are using. If you are using Cortex-M then you can call

michaeln32 wrote on Monday, March 12, 2018:

I’m using MIPS.

Is the function port_IsInISR() is good for that purpose ?


rtel wrote on Monday, March 12, 2018:

The PIC32 MIPS port? If so you can just check the uxInterruptNesting
variable, which is declared in the port.c file for that port. If its
not zero then you are in an ISR.

michaeln32 wrote on Tuesday, March 13, 2018:

Thank you very much Richard

But not the M0 port, right?

// Martin

On the M0 you can query the hardware registers directly to know if you are in an interrupt. The M3/4 ports have a macro in portmacro.h for doing that, can’t remember if the M0 does to, but it is just testing a bit in a register.