<?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>Possible race in NUS service - are there limitation on where to call ble_nus_data_send() from?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/43876/possible-race-in-nus-service---are-there-limitation-on-where-to-call-ble_nus_data_send-from</link><description>In my previous question , where I wanted to atomically send a large bulk of data, the solution was to keep track of p_bus-&amp;gt; free_buffers , in order to calculate the amount of available space in the SD. 
 I&amp;#39;ve noticed that p_bus-&amp;gt; free_buffers is modified</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 20 Feb 2019 08:18:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/43876/possible-race-in-nus-service---are-there-limitation-on-where-to-call-ble_nus_data_send-from" /><item><title>RE: Possible race in NUS service - are there limitation on where to call ble_nus_data_send() from?</title><link>https://devzone.nordicsemi.com/thread/172032?ContentTypeID=1</link><pubDate>Wed, 20 Feb 2019 08:18:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00189805-615c-44d6-80cb-a4f419c5ba95</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Sorry for the obscure answer. If you want to protect writes to the variable the easiest way would probably be to use a critical region (disable interrupts before updating it and enable them afterwards), like calling the ble_nus_send_data() from an interrupt handler. You could have a look through \components\libraries\atomic\nrf_atomic.h as well to see if any of the operations does what you need, but I&amp;#39;d recommend disabling interrupts.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Possible race in NUS service - are there limitation on where to call ble_nus_data_send() from?</title><link>https://devzone.nordicsemi.com/thread/171942?ContentTypeID=1</link><pubDate>Tue, 19 Feb 2019 15:17:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1c0afb9-12df-46db-affb-63497ea76f3f</guid><dc:creator>Boaz</dc:creator><description>[quote userid="75734" url="~/f/nordic-q-a/43876/possible-race-in-nus-service---are-there-limitation-on-where-to-call-ble_nus_data_send-from/171912"]Do they interrupt each other when the code runs?[/quote]
&lt;p&gt;Probably - the method called from main() runs in application scheduler context (i.e. main context), and is triggered by a timer.&lt;/p&gt;
&lt;p&gt;Can you please elaborate on the &amp;quot;use SD interrupt handler&amp;quot;? Do you mean posting the timer event to an SD IRQ?&lt;/p&gt;
&lt;p&gt;Alternatively, does nRF have an atomic increment/decrement operation, which &lt;strong&gt;does not&lt;/strong&gt; include disabling all interrupts?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Possible race in NUS service - are there limitation on where to call ble_nus_data_send() from?</title><link>https://devzone.nordicsemi.com/thread/171912?ContentTypeID=1</link><pubDate>Tue, 19 Feb 2019 14:01:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e79a3144-bf52-4d53-9049-84e5ce3cd340</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is difficult for me to tell if this is a race condition or not, but it seems likely. Do they interrupt each other when the code runs? You can use an SD interrupt handler, probably the easiest way.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>