<?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>All interrupt seems to be triggered twice ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/70220/all-interrupt-seems-to-be-triggered-twice</link><description>Hi, 
 I noticed at least using pwr_mgmt we are calling two times nrf_pwr_mgmt_run for every interrupts ! All interrupt seems to be triggered twice ! Or wakes from idle state 2 times ! Why ? 
 In my case, it is the case for every app_timer interrupt, IO</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 15 Jan 2021 13:04:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/70220/all-interrupt-seems-to-be-triggered-twice" /><item><title>RE: All interrupt seems to be triggered twice ?</title><link>https://devzone.nordicsemi.com/thread/289417?ContentTypeID=1</link><pubDate>Fri, 15 Jan 2021 13:04:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc18a666-03f6-4d4b-9634-7a9c78407dd4</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;I can&amp;#39;t pinpoint exactly why, but it has to do with the CPU Usage check. Try to disable the&amp;nbsp;NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED in sdk_config.h.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: All interrupt seems to be triggered twice ?</title><link>https://devzone.nordicsemi.com/thread/289312?ContentTypeID=1</link><pubDate>Thu, 14 Jan 2021 23:38:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:adcd8398-3a13-4a68-8a31-de0e58e12498</guid><dc:creator>Salmat</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the response !&lt;/p&gt;
&lt;p&gt;It seems to work.&lt;br /&gt;In fact, it is the exact same code as in nrf_pwr_mgmt_run without CRITICAL_REGION_ENTER / EXIT.&lt;/p&gt;
&lt;p&gt;I imagine it was there for something ! I would remove it if I understand why it was there in the first place ...&lt;br /&gt;Neither I understand why critical region is waking ?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Matt&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: All interrupt seems to be triggered twice ?</title><link>https://devzone.nordicsemi.com/thread/289079?ContentTypeID=1</link><pubDate>Thu, 14 Jan 2021 08:15:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4182a6e0-effb-4c9b-8be7-62f3502e5c16</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;It looks like it is actually CRITICAL_REGION_ENTER() and CRITICAL_REGION_EXIT() that triggers the main loop one extra time. These are being called inside&amp;nbsp;nrf_pwr_mgmt_run();&lt;/p&gt;
&lt;p&gt;If you want to skip the whole nrf_pwr_mgmt_run(), you can replace it with:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    // Wait for an event.
#ifdef SOFTDEVICE_PRESENT
    if (nrf_sdh_is_enabled())
    {
        ret_code_t ret_code = sd_app_evt_wait();
        ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
        UNUSED_VARIABLE(ret_code);
    }
    else
#endif // SOFTDEVICE_PRESENT
    {
        // Wait for an event.
        __WFE();
        // Clear the internal event register.
        __SEV();
        __WFE();
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: All interrupt seems to be triggered twice ?</title><link>https://devzone.nordicsemi.com/thread/288234?ContentTypeID=1</link><pubDate>Fri, 08 Jan 2021 17:14:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e8f56c84-d054-44c2-8c62-ee3486260a7c</guid><dc:creator>Salmat</dc:creator><description>&lt;p&gt;I am not talking at all about app_timer. I have just done an example with App_timer, but it is not only en app_timer problem.&lt;br /&gt;It is the same with any interrupt !&lt;/p&gt;
&lt;p&gt;By the way I am not using app timer scheduler at all : #define APP_TIMER_CONFIG_USE_SCHEDULER 0&lt;/p&gt;
&lt;p&gt;Regard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: All interrupt seems to be triggered twice ?</title><link>https://devzone.nordicsemi.com/thread/288228?ContentTypeID=1</link><pubDate>Fri, 08 Jan 2021 16:36:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2968314d-e2dc-44e1-a74d-7efeee7b2ae4</guid><dc:creator>Edvin</dc:creator><description>[quote user="salmat"]I have looked the source files, and for me all the app_timer functions are taking care of configurations in &amp;quot;rtc_irq&amp;quot; in &amp;quot;app_timer2.c&amp;quot; ... gaving the hand to the user handler, but all in the same irq level ![/quote]
&lt;p&gt;&amp;nbsp;Remember that the app_timer has it&amp;#39;s own scheculer. All the tasks of the app timer is not necessarily done by the time you reach main(), and some may be handled later.&lt;/p&gt;
&lt;p&gt;I have not researched this exact question before, but similar. When customers are starting and stopping the app timer in the main loop they ask why the device never goes to sleep. The answer has always been that the app timer&amp;#39;s scheduler is woken up. Then they started a new app_timer in the main context, and stopped it when some work was done. The stop call then triggered an event in the app timer scheduler that woke the device up again.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now, in your case, that is not an issue, because you don&amp;#39;t start/stop any app timers from your main loop, but what I am saying is that it is the app timer that wakes up the CPU from time to time.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: All interrupt seems to be triggered twice ?</title><link>https://devzone.nordicsemi.com/thread/288221?ContentTypeID=1</link><pubDate>Fri, 08 Jan 2021 15:49:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f67f891c-4b00-4661-811f-c27e7abf3339</guid><dc:creator>Salmat</dc:creator><description>&lt;p&gt;I have looked the source files, and for me all the app_timer functions are taking care of configurations in &amp;quot;rtc_irq&amp;quot; in &amp;quot;app_timer2.c&amp;quot; ... gaving the hand to the user handler, but all in the same irq level !&lt;br /&gt;As does nrfx_spim_XXX_irq_handler, and&amp;nbsp;nrfx_gpiote_irq_handler ...&lt;/p&gt;
&lt;p&gt;I am also nearly sure it is not only going to the main loop, but going to sleep, and so processing 2 times all what is in the main loop for all wanted interrupts. Also waking two time from sleep, ...&lt;br /&gt;Doing it two times is not what we want, and is a waste of processing time, and so power ...&lt;/p&gt;
&lt;p&gt;What I think is making it sometime 202, is the processing and print of : &amp;quot;&amp;lt;info&amp;gt; pwr_mgmt: CPU Usage: 0%&amp;quot;, that is also using app timer one time per seconds ! I am calling it 100 times per seconds.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Matt&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: All interrupt seems to be triggered twice ?</title><link>https://devzone.nordicsemi.com/thread/288199?ContentTypeID=1</link><pubDate>Fri, 08 Jan 2021 14:00:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be19ff5f-834f-461c-a38c-3cc29292eb22</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;So your main loop is called twice as often as your timer handler, that is what you are saying, right?&lt;/p&gt;
&lt;p&gt;Without being able to pinpoint exactly what&amp;#39;s causing this, I would say that this is not something you need to worry about.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can dig a bit to see if you can figure out exactly what happens, but my guess is:&lt;/p&gt;
&lt;p&gt;Your timeout handler is triggered, causing your timer_handler_count to increment.&lt;/p&gt;
&lt;p&gt;This triggers your main loop when the timer handler is done.&lt;/p&gt;
&lt;p&gt;After this (but probably scheduled before) the app_timer needs to do some internal work to set up the timeout register value for your next timeout. This also triggers the main_loop.&lt;/p&gt;
&lt;p&gt;From time to time, you can see that there is 202. It may be the RTC (app_timer) that rolls over, and it requires a few extra operations to set up the next timeout.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>