<?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>Reentrant event handling</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14243/reentrant-event-handling</link><description>I am using esb in SDK 11 and my understanding is that the radio causes interrupts that are forcing and cannot be disabled. These in turn causes software interrupt 10 to be triggered and my callback is called. Am I right in this description? 
 To my question</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 07 Jun 2016 05:56:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14243/reentrant-event-handling" /><item><title>RE: Reentrant event handling</title><link>https://devzone.nordicsemi.com/thread/54400?ContentTypeID=1</link><pubDate>Tue, 07 Jun 2016 05:56:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb28ef40-e65e-47af-b763-cb779cb0a8a0</guid><dc:creator>Alexander Schrab</dc:creator><description>&lt;p&gt;I write/read from both places. This is the general idea:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;onEvent() {  
  servoController-&amp;gt;setDirection(stuffBasedOnWhatArrivedOnRadio); 
}

main() { 
  while(1) {   
    wait(1);   
    servoController-&amp;gt;tick(); // Makes sure that servo behaves. We have sensors that when triggered needs to quickly stop the servo for instance. 
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reentrant event handling</title><link>https://devzone.nordicsemi.com/thread/54399?ContentTypeID=1</link><pubDate>Mon, 06 Jun 2016 12:23:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:674f412a-1664-4835-b11e-17bc558a8500</guid><dc:creator>Anders Strand</dc:creator><description>&lt;p&gt;Yes, but can you clarify one thing: Will you just read, or read+write to the shared data from main context?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reentrant event handling</title><link>https://devzone.nordicsemi.com/thread/54398?ContentTypeID=1</link><pubDate>Fri, 03 Jun 2016 16:02:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbdc86d1-f2b7-41dc-aa69-870d69c9165b</guid><dc:creator>Alexander Schrab</dc:creator><description>&lt;p&gt;Or let me rephrase... If I, in the ESB event handler, simple schedule an app event which is handled through app_sched_execute in the main loop and all other shared data manipulation is also done from the main loop (through events or directly) I should be fine? :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reentrant event handling</title><link>https://devzone.nordicsemi.com/thread/54397?ContentTypeID=1</link><pubDate>Fri, 03 Jun 2016 15:52:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e1b2438-6169-4b24-a208-8e91973a2c50</guid><dc:creator>Alexander Schrab</dc:creator><description>&lt;p&gt;So, if I do everything (reading/writing of shared data) through events in the app scheduler that could be one way to solve this?&lt;/p&gt;
&lt;p&gt;If I use critical region, do I risk missing the software interrupt or is simple delayed until I exit critical region in the main loop?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reentrant event handling</title><link>https://devzone.nordicsemi.com/thread/54396?ContentTypeID=1</link><pubDate>Fri, 03 Jun 2016 15:28:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7e8cd76-2586-4fc5-88d2-92f4b5aa2aa9</guid><dc:creator>Anders Strand</dc:creator><description>&lt;p&gt;Hello.&lt;/p&gt;
&lt;p&gt;You are correct in your description of the event flow in the top of your post.&lt;/p&gt;
&lt;p&gt;If you want to avoid race conditions when reading/writing to shared variables, you can use the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/group__app__util__platform.html?cp=5_0_0_6_8_28"&gt;critical region API&lt;/a&gt;. You will find this functions inside the header file &amp;quot;\nRF5_SDK_11\components\libraries\util\app_util_platform.h&amp;quot;&lt;/p&gt;
&lt;p&gt;Alternatively, you can process the data inside the event handler. You will have to make sure that you are done before the next event though, or you might lose some events.&lt;/p&gt;
&lt;p&gt;The &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/lib_scheduler.html?cp=5_0_0_3_22"&gt;app_scheduler&lt;/a&gt; api is made for taking events and processing them in main context. This will not let you write to the common data structure however. If you need to write to them from the main context, critical sections is the way to go. If not, you should probably go with the app scheduler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>