<?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>How to avoid interrupt handling is not missed with sd_app_evt_wait()?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/19252/how-to-avoid-interrupt-handling-is-not-missed-with-sd_app_evt_wait</link><description>For example, I have the following code: 
 bool interruptFlag;

void interruptHanler(void)
{
 interruptFlag = true;
}

void main(void)
{
 while (true)
 {
 if (interruptFlag)
 { interruptFlag = false;
 processThings(); // process heavier things</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 07 Feb 2017 08:35:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/19252/how-to-avoid-interrupt-handling-is-not-missed-with-sd_app_evt_wait" /><item><title>RE: How to avoid interrupt handling is not missed with sd_app_evt_wait()?</title><link>https://devzone.nordicsemi.com/thread/74587?ContentTypeID=1</link><pubDate>Tue, 07 Feb 2017 08:35:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e450c42b-22cd-446a-b9a5-543bc07c5a27</guid><dc:creator>Jarmo</dc:creator><description>&lt;p&gt;Thanks for comment, I have to check the documents some day :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to avoid interrupt handling is not missed with sd_app_evt_wait()?</title><link>https://devzone.nordicsemi.com/thread/74585?ContentTypeID=1</link><pubDate>Mon, 06 Feb 2017 18:43:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27d3644a-662e-458d-862d-a815875816da</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;single WFI would have been enough to make sure that it makes the chip to sleep. But then there could be race conditions with WFI. WFE is not guarenteed to sleep because of its internal event set register. You can read more about the difference in this forum or ARM infocenter. It is well documented i think.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to avoid interrupt handling is not missed with sd_app_evt_wait()?</title><link>https://devzone.nordicsemi.com/thread/74586?ContentTypeID=1</link><pubDate>Sun, 05 Feb 2017 18:12:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b30a874a-bf45-4ff6-92f6-cb8a5c7bd2a8</guid><dc:creator>Jarmo</dc:creator><description>&lt;p&gt;Yeah, it sounds like there&amp;#39;s no problem with that, then. However, I don&amp;#39;t quite understand why a single __WFE() call is not enough?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to avoid interrupt handling is not missed with sd_app_evt_wait()?</title><link>https://devzone.nordicsemi.com/thread/74583?ContentTypeID=1</link><pubDate>Sun, 05 Feb 2017 16:41:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9923c538-64a6-48d9-8298-5a4c764b7297</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;please update this thread, with new info Jarmo&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to avoid interrupt handling is not missed with sd_app_evt_wait()?</title><link>https://devzone.nordicsemi.com/thread/74584?ContentTypeID=1</link><pubDate>Thu, 26 Jan 2017 17:13:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:250b86f4-93c3-4e05-a5d9-ba99412a592e</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Jarmo,&lt;/p&gt;
&lt;p&gt;sd_app_evt_wait() calls wait in the sequence of
__WFE()
__SEV()
__WFE()&lt;/p&gt;
&lt;p&gt;This way if the interrupt happened just before calling sd_app_evt_wait, then the above sequence will not sleep because&lt;br /&gt;
__WFE() -&amp;gt; The internal event was set as an interrupt occured just before this , now the event is cleared and this _WFE does nothing, means it wont go to sleep&lt;/p&gt;
&lt;p&gt;__SEV()-&amp;gt; Set the event register explicitly&lt;/p&gt;
&lt;p&gt;__WFE-&amp;gt; since we set event register explicitly, this __WFE will also not do anything apart from clearing the event register.&lt;/p&gt;
&lt;p&gt;The above sequence will also work perfectly if no interrupt happened before calling sd_app_evt_wait&lt;br /&gt;
__WFE()-&amp;gt; since no internal event is set, this will make chip go to sleep (system idle)&lt;/p&gt;
&lt;p&gt;__SEV -&amp;gt; executing this means the chip has woken up now or before in other context, we are setting internal event just to make sure&lt;/p&gt;
&lt;p&gt;__WFE -&amp;gt; clear the internal event and do nothing, so now we are awake and all events handled and cleared.&lt;/p&gt;
&lt;p&gt;sd_app_evt_wait also keeps track of application interrupts forwarded and acked by softdevice. So it avoids any race condition.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>