<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>detect if in critical region</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/12064/detect-if-in-critical-region</link><description>Is there a way to know if we are in critical region?
ie: between sd_nvic_critical_region_enter(&amp;amp;foo) and sd_nvic_critical_region_exit(0) without explicitly using a global variable to memorize the state</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 23 Feb 2016 08:02:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/12064/detect-if-in-critical-region" /><item><title>RE: detect if in critical region</title><link>https://devzone.nordicsemi.com/thread/45665?ContentTypeID=1</link><pubDate>Tue, 23 Feb 2016 08:02:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8dd8d7ef-81ac-4735-bc21-86db666dd4e2</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Let us say that your app is using TIMER1 and has enabled its interrupt. Then you can check if this interrupt is temporarily disabled when inside the critical region.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if(NVIC-&amp;gt;ISER[0] &amp;amp; ((1 &amp;lt;&amp;lt; (uint32_t)TIMER1_IRQn)))
{
   // interrupt is still enabled so NOT inside critical section
}
else
{
   // inside the critical section
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The basic idea is to see if any interrupt enabled by the app is temporarily disabled between &lt;code&gt;sd_nvic_critical_region_enter&lt;/code&gt; and &lt;code&gt;sd_nvic_critical_region_exit&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>