<?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>Concurrency, mutexes, scheduler...</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/11090/concurrency-mutexes-scheduler</link><description>Hi, 
 I am writing an application on top of NRF51, using a S130 Softdevice. I wonder about the concurrenceness (?) of the code I write, and especially if I need to use critical sections, mutexes (muticies?) or similar to protect critical sections in</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Jan 2016 08:24:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/11090/concurrency-mutexes-scheduler" /><item><title>RE: Concurrency, mutexes, scheduler...</title><link>https://devzone.nordicsemi.com/thread/41502?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2016 08:24:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a0da48d-a9a5-4d37-b342-f0cdc8682a1b</guid><dc:creator>Elm</dc:creator><description>&lt;p&gt;Thanks a lot. This is exactly what I hoped for.  The scheduler makes my application a lot less complex. :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Concurrency, mutexes, scheduler...</title><link>https://devzone.nordicsemi.com/thread/41501?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 15:18:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5fb60216-b71d-4dcd-8d0d-e1fcca8dbc04</guid><dc:creator>Anders Strand</dc:creator><description>&lt;p&gt;The softdevice will take of all timing critical BLE protocol business. It will do this in high priority, and will therefore interrupt anything that you might be doing. These interrupts are periodically based on various parameters, and last between a couple of us to a couple of ms at the most.&lt;/p&gt;
&lt;p&gt;Check out the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.132.sds.v1.0.0/processor_avail_interrupt_latency/processor_avail.html?cp=1_2_0_0_12_1"&gt;infocenter page&lt;/a&gt; on processor availability when using a softdevice. It describes the different interrupt priorities in the system.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ble events are run from a software interrupt with priority APP_LOW.&lt;/li&gt;
&lt;li&gt;Application timer priority is set at initiation, either APP_LOW or APP_HIGH. Default (and recommended is APP_LOW). A timer event with APP_LOW will be queued after a BLE event in progress (which is also at APP_LOW).&lt;/li&gt;
&lt;li&gt;Buttons can also be assigned priority, but i recommend APP_LOW (default).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you use APP_HIGH for anything, it will not interrupt BLE transmissions, but it will interrupt processing of BLE packets and in that way impact BLE performance. Only use this priority for very short and important tasks. None of your APP_LOW tasks will interrupt one another.&lt;/p&gt;
&lt;p&gt;If you are using the app_scheduler, you put events in a queue and execute them from main() context, which is the lowest priority. This is a good thing to do in most cases, unless something has to happen right away. The app_scheduler is documented &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v10.0.0/lib_scheduler.html?cp=4_0_1_3_20"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you design you application correctly, i do not see any need for mutexes or critical sections. The tasks that interrupt you (the softdevice) will not use any common resources with your application.&lt;/p&gt;
&lt;p&gt;-Anders&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>