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

**URL:** <https://forums.freertos.org/t/is-there-a-programmatic-way-to-discover-if-code-is-running-in-an-isr-context/1255>\
**Category:** Kernel\
**Created:** [November 26, 2015, 12:21am UTC](https://forums.freertos.org/t/is-there-a-programmatic-way-to-discover-if-code-is-running-in-an-isr-context/1255 "2015-11-26T00:21:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 26, 2015, 12:21am UTC](https://forums.freertos.org/t/is-there-a-programmatic-way-to-discover-if-code-is-running-in-an-isr-context/1255/1 "2015-11-26T00:21:30Z")

</div>

**[vawheeler63](https://sourceforge.net/u/vawheeler63/)** wrote on [Thursday, November 26, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/35e3746e/#4732):

Hi!

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,  
VW

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 26, 2015, 6:33am UTC](https://forums.freertos.org/t/is-there-a-programmatic-way-to-discover-if-code-is-running-in-an-isr-context/1255/2 "2015-11-26T06:33:55Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Thursday, November 26, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/35e3746e/#2598):

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

extern UBaseType\_t uxInterruptNesting;  
if(uxInterruptNesting==0){  
// in task  
} else {  
// in isr  
}
