<?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>Atomic variable access (locking)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17461/atomic-variable-access-locking</link><description>Hi All, 
 I&amp;#39;m implementing system clock using approach similar to
 devzone.nordicsemi.com/.../ 
 The idea: 
 NRF_RTC_EVENT_COMPARE_0 -&amp;gt; PPI -&amp;gt; NRF_TIMER_TASK_COUNT 
(translate 125ms RTC ticks to counter mode TIMER 1sec ticks) 
 All works great,</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Nov 2016 13:35:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17461/atomic-variable-access-locking" /><item><title>RE: Atomic variable access (locking)</title><link>https://devzone.nordicsemi.com/thread/67101?ContentTypeID=1</link><pubDate>Wed, 02 Nov 2016 13:35:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00609d69-6591-46a3-9d26-4e82a6bbad86</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Alex,&lt;/p&gt;
&lt;p&gt;You are disabling interrupt at the timer peripheral level so if there should have been any interrupt in these race period then it will be lost because the peripheral will not produce and hence cannot pend it.&lt;/p&gt;
&lt;p&gt;In your case it will be better if you can disable it at NVIC level, because NVIC have pend bits then the incoming interrupt will be pended instead of being lost. So when you enable it, and if there was timer interrupt from peripheral in the mean time that caused a pendbit then it will be serviced and not lost.&lt;/p&gt;
&lt;p&gt;Proposed solution is to do below, assuming that this is not ISR&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NVIC_DisableIRQ(time_you_are_using_IRQn);
m_epoch_time += cval;
NVIC_EnableIRQ(time_you_are_using_IRQn);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>