<?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>EGU to SWI occasionally missing flags</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60409/egu-to-swi-occasionally-missing-flags</link><description>I have an application built on the 52840 which is using a software interrupt triggered by the event generator unit. Occasionally my SWI function is being passed a zero for the flags value, despite the EGU being triggered by one of the task addresses.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 25 May 2020 10:24:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60409/egu-to-swi-occasionally-missing-flags" /><item><title>RE: EGU to SWI occasionally missing flags</title><link>https://devzone.nordicsemi.com/thread/251446?ContentTypeID=1</link><pubDate>Mon, 25 May 2020 10:24:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab927452-daf9-4cb0-9989-71ff96918276</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Ok, glad to hear that you found a workaround &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EGU to SWI occasionally missing flags</title><link>https://devzone.nordicsemi.com/thread/251387?ContentTypeID=1</link><pubDate>Mon, 25 May 2020 07:04:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7bab9cd9-9fed-4d26-817e-44bdd10e8f72</guid><dc:creator>Benjamin</dc:creator><description>&lt;p&gt;The SWI is only triggered via PPI. When only one timer (which triggers the SWI via PPI) is running, the flags are always set correctly. When more than one timer is running, most of the time, the flags are set correctly, but very occasionally, the flags are missing.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve not looked more closely at the SWI library&amp;nbsp;to try to figure out could happen if a 2nd IRQ is triggered during the ISR since I have an adequate work-around.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EGU to SWI occasionally missing flags</title><link>https://devzone.nordicsemi.com/thread/251382?ContentTypeID=1</link><pubDate>Mon, 25 May 2020 06:31:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:478a6470-e97c-4c3b-95b7-10d2c67a318e</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Benjamin,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;OK, so the SWI ISR is triggered and executed as often as you are expecting, but if one or more timers trigger the SWI while the SWI ISR is running, then the user flag passed with the pending interrupts are zero.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Looking at the nrfx_swi.c code, it does seem feasible that the&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void nrfx_swi_trigger(nrfx_swi_t swi, uint8_t flag_number)
{
    NRFX_ASSERT(swi_is_allocated(swi));

#if NRFX_SWI_EGU_COUNT

    NRF_EGU_Type * p_egu = nrfx_swi_egu_instance_get(swi);
#if (NRFX_SWI_EGU_COUNT &amp;lt; SWI_COUNT)
    if (p_egu == NULL)
    {
        m_swi_flags[swi - NRFX_SWI_EGU_COUNT] |= (1 &amp;lt;&amp;lt; flag_number);
        NRFX_IRQ_PENDING_SET(swi_irq_number_get(swi));
    }
    else
#endif // (NRFX_SWI_EGU_COUNT &amp;lt; SWI_COUNT)
    {
        nrf_egu_task_trigger(p_egu,
            nrf_egu_task_trigger_get(p_egu, flag_number));
    }

#else // -&amp;gt; #if !NRFX_SWI_EGU_COUNT

    m_swi_flags[swi - NRFX_SWI_EGU_COUNT] |= (1 &amp;lt;&amp;lt; flag_number);
    NRFX_IRQ_PENDING_SET(swi_irq_number_get(swi));

#endif
}

static void swi_irq_handler(nrfx_swi_t swi)
{
#if (NRFX_SWI_FIRST &amp;gt; 0)
    NRFX_ASSERT(swi &amp;gt;= NRFX_SWI_FIRST);
#endif
    NRFX_ASSERT(swi &amp;lt;= NRFX_SWI_LAST);
    nrfx_swi_handler_t handler = m_swi_handlers[swi];
    NRFX_ASSERT(handler != NULL);

    nrfx_swi_flags_t flags = m_swi_flags[swi - NRFX_SWI_EGU_COUNT];
    m_swi_flags[swi - NRFX_SWI_EGU_COUNT] &amp;amp;= ~flags;

    handler(swi, flags);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When you&amp;#39;re triggering the SWI through PPI and not with the&amp;nbsp;nrfx_swi_trigger() function from SW,&amp;nbsp;then I do not think that the&amp;nbsp;m_swi_flags variable is set. So when the&amp;nbsp;&lt;span&gt;&lt;span&gt;swi_irq_handler is executed, then&amp;nbsp;&lt;/span&gt;&lt;/span&gt;m_swi_flags could&amp;nbsp;zero. Do you agree?&lt;/p&gt;
&lt;p&gt;-Bjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EGU to SWI occasionally missing flags</title><link>https://devzone.nordicsemi.com/thread/251317?ContentTypeID=1</link><pubDate>Fri, 22 May 2020 19:43:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a04d494-06c3-4cf0-bebf-1fc38cd9fa80</guid><dc:creator>Benjamin</dc:creator><description>&lt;p&gt;I dug into this more (and also forgot to update the ticket) and i&amp;#39;m pretty sure what happens is that sometimes a 2nd (or more) SWI IRQ fires while the SWI ISR is running, and&amp;nbsp;when the follow-up ISR is run, the flags value is passed in as 0.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see any missing flags when I only have 1 &amp;#39;channel&amp;#39; enabled, and the frequency of misses seems to increase with the number of channels enabled.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EGU to SWI occasionally missing flags</title><link>https://devzone.nordicsemi.com/thread/251262?ContentTypeID=1</link><pubDate>Fri, 22 May 2020 12:43:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85438dc3-0135-4e42-a552-2dca41be55aa</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Benjamin,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Apologies for the very late reply.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So if I understand the issue correct, the SWI function is not called as often as you are expecting and the flag value passed with the SWI function is often zero?&lt;/p&gt;
&lt;p&gt;Could you try to replace the SWI trigger task with a GPIOTE OUT task that toggles a GPIO? Im just thinking that it would be nice to verify that the COMPARE events are triggering as often as you are expecting them to trigger.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Bjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EGU to SWI occasionally missing flags</title><link>https://devzone.nordicsemi.com/thread/245676?ContentTypeID=1</link><pubDate>Mon, 20 Apr 2020 23:18:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66ace309-44a5-4072-a3e1-f6ba890eba87</guid><dc:creator>Benjamin</dc:creator><description>&lt;p&gt;At ~2 MHz, that&amp;#39;s on the order of microseconds, not milliseconds.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: EGU to SWI occasionally missing flags</title><link>https://devzone.nordicsemi.com/thread/245653?ContentTypeID=1</link><pubDate>Mon, 20 Apr 2020 19:14:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68e74ae0-8e36-457f-9e1b-a9111ec87524</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Benjamin,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;please note that in the worst case there might be up-to two 16MHz clock cycles delay from an event to the task being triggered, see&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/ppi.html?cp=4_0_0_5_15"&gt;PPI — Programmable peripheral interconnect&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;On each PPI channel, the signals are synchronized to the 16 MHz clock, to avoid any internal violation of setup and hold timings. As a consequence, events that are synchronous to the 16 MHz clock will be delayed by one clock period, while other asynchronous events will be delayed by up to one 16 MHz clock period.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Also, If I remember correctly&amp;nbsp;the ARM Cortex M4 has a interrupt entry/exit&amp;nbsp; latency of 12 cycles( the M4 is running at 64MHz). So without accounting for tail chained interrupts, the latency of entering and exiting the ISR is 24 cycles, so the maximum frequency one would be able to enter the ISR would be 2.66 MHz if my math is right. If we take into account tail chained interrupts the latency is 18 cycles, resulting in a maximum frequency of 3.55 MHz.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And then we&amp;#39;re not taking into account the code running in the ISR, which needs to be added. So it could be that this all adds up to something in the ms range.&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Bjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>