Is There a Programmatic Way to Discover if Code is Running In An ISR Context?

vawheeler63 wrote on Thursday, November 26, 2015:


I’m running FreeRTOSv8.2.3 on a PIC32MZ. I have code that may run IN or OUTSIDE an ISR context, and I was wondering if there is a way to programmatically discover if the execution is occurring in an ISR context.

Kind regards,

edwards3 wrote on Thursday, November 26, 2015:

You can always read the info from the hardware registers, but easier:

extern UBaseType_t uxInterruptNesting;
// in task
} else {
// in isr