<?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>Concept of pending registers in interrupt handlers in nRF</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75771/concept-of-pending-registers-in-interrupt-handlers-in-nrf</link><description>Is clearing the NRF_UART_EVENT_RXDRDY really sufficient before exiting the IRQ handler? Since Cortex M4 is used, there&amp;#39;s no need to clear the pending register (to avoid the interrupt from firing continually) or that&amp;#39;s done by nordic internally?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 03 Jun 2021 09:15:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75771/concept-of-pending-registers-in-interrupt-handlers-in-nrf" /><item><title>RE: Concept of pending registers in interrupt handlers in nRF</title><link>https://devzone.nordicsemi.com/thread/313321?ContentTypeID=1</link><pubDate>Thu, 03 Jun 2021 09:15:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08e3d5d2-6c2f-42bf-be0d-ed957beeb3a8</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thanks for the additional input &lt;a href="https://devzone.nordicsemi.com/members/hmolesworth"&gt;hmolesworth&lt;/a&gt;.&amp;nbsp; The designers are aware of DSB instruction, but they still ended up with the recommendation to perform a dummy read. I&amp;#39;m not sure what the reasoning was. Although I agree it&amp;#39;s not perfect considering it may get optimized away by the compiler. Either way, I think both the DSB instruction and dummy read should be redundant in most cases unless you are implementing a very minimal interrupt service routine. &lt;/p&gt;
[quote userid="91233" url="~/f/nordic-q-a/75771/concept-of-pending-registers-in-interrupt-handlers-in-nrf/313222#313222"]Looking at Figure 1&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf52833%2Fperipheral_interface.html"&gt;here&lt;/a&gt;&amp;nbsp;and trying to relate to your description:&amp;nbsp;does writing 0 to the event register result in a signal with a value of 0 which is sent out to the NVIC? [/quote]
&lt;p&gt;Hmolesworth explained this best. The interrupt will be trigger again instantly if the peripheral event register still reads&amp;nbsp; &amp;#39;1&amp;#39; when you exit the interrupt handler.&lt;/p&gt;
&lt;p&gt;The other signal is going to the &lt;span class="item"&gt;&lt;a title="PPI &amp;mdash; Programmable peripheral interconnect" href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/ppi.html?cp=4_1_0_5_14"&gt;PPI &amp;mdash; Programmable peripheral interconnect&lt;/a&gt;&lt;/span&gt;, a module which let you connect EVENT registers from one peripheral to a TASK register in another. As an example, you can use the PPI to make a periodic TIMER event trigger the SAADC sample task with no CPU involvement. &lt;/p&gt;
[quote userid="91233" url="~/f/nordic-q-a/75771/concept-of-pending-registers-in-interrupt-handlers-in-nrf/313222#313222"]Is there a circuit diagram that involves both the pending register [/quote]
&lt;p&gt;The (IRQ) pending register is in the NVIC, which is a part of the ARM Cortex M4 architecture. This module is covered by the documentation from ARM.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Concept of pending registers in interrupt handlers in nRF</title><link>https://devzone.nordicsemi.com/thread/313223?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 21:45:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f90b6c57-a7c1-4a09-9084-205701b555f6</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I would argue that instead of reading back the register and worrying about optimisation issues the DSB instruction should instead be used as that also handles bus latency. I have tested this and had no failures:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  // Data Synchronization Barrier: continues when all explicit memory accesses before this instruction complete
  __DSB();&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I should add that enabled interrupts from hardware events are generally level-sensitive, not edge-triggered, so unless the event is set to &amp;#39;0&amp;#39; it will continue to generate interrupts when the interrupt handler exits. Once the hardware event register has been set to &amp;#39;0&amp;#39; since many peripherals use a 16MHz clock instead of the 64-MHz clock it can take up to 4 clock cycles from the clear instruction in some cases. Being picky, I would suggest the DSB instruction to ensure the memory address (hardware event register) write completed, then take some extra NOPs depending on the number of cycles DSB requires; not sure if DSB is single-cycle. Edit: yes single cycle but will use 0, 1, 2 or 3 waitstates depending on cache enabled. Hmm, so how many NOPs worst-case, maybe 3 with no cache, 1 with cache hit or execute from SRAM.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Concept of pending registers in interrupt handlers in nRF</title><link>https://devzone.nordicsemi.com/thread/313222?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 21:37:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86fcbbc6-2daa-4ab7-8145-63b815d8909a</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Looking at Figure 1&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf52833%2Fperipheral_interface.html"&gt;here&lt;/a&gt;&amp;nbsp;and trying to relate to your description:&amp;nbsp;does writing 0 to the event register result in a signal with a value of 0 which is sent out to the NVIC? Where&amp;#39;s what we write (0 to event register) indicated in the figure? Also, what&amp;#39;s PPI?&lt;br /&gt;&lt;br /&gt;Is there a circuit diagram that involves both the pending register and the event register? I was curious to see how does writing 0 to event register really stops further interrupts from reocurring till the next one arrives.&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/75771/concept-of-pending-registers-in-interrupt-handlers-in-nrf/313031#313031"]To avoid an interrupt reoccurring before a new event has come, the program should perform a read from one of the peripheral registers[/quote]
&lt;p&gt;So basically after setting the event register to 0, the same register should be read right after to reduce the delay in terms of the number of cycles?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Concept of pending registers in interrupt handlers in nRF</title><link>https://devzone.nordicsemi.com/thread/313031?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 08:11:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15cead6f-1bdf-42dc-aa06-f486188a2010</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;You must write &amp;#39;0&amp;#39; to the event register to clear the event. The only purpose of doing a &amp;quot;dummy&amp;quot; read after is to ensure that write will be performed before exiting the interrupt handler. Here is a more detailed explanation copied from the product specification:&lt;/p&gt;
&lt;div class="section" id="interrupts__section_tsm_hv3_ybb"&gt;
&lt;h3 class="title sectiontitle" style="padding-left:30px;" id="mcetoc_1f75risbv0"&gt;Interrupt clearing&lt;/h3&gt;
&lt;p class="p" style="padding-left:30px;"&gt;Clearing an interrupt by writing &lt;code class="ph codeph"&gt;0&lt;/code&gt; to an event register, or disabling an interrupt using the INTENCLR register, can take up to four CPU clock cycles to take effect. This means that an interrupt may reoccur immediately, even if a new event has not come, if the program exits an interrupt handler after the interrupt is cleared or disabled but before four clock cycles have passed.&lt;/p&gt;
&lt;div class="note note" style="padding-left:30px;"&gt;&lt;span class="notetitle"&gt;Note:&lt;/span&gt; To avoid an interrupt reoccurring before a new event has come, the program should perform a read from one of the peripheral registers. For example, the event register that has been cleared, or the INTENCLR register that has been used to disable the interrupt. This will cause a one to three-cycle delay and ensure the interrupt is cleared before exiting the interrupt handler.&lt;/div&gt;
&lt;p class="p" style="padding-left:30px;"&gt;Care should be taken to ensure the compiler does not remove the read operation as an optimization. If the program can guarantee a four-cycle delay after an event is cleared or an interrupt is disabled, then a read of a register is not required. (&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/peripheral_interface.html"&gt;link&lt;/a&gt;)&lt;/p&gt;
&lt;/div&gt;
[quote userid="91233" url="~/f/nordic-q-a/75771/concept-of-pending-registers-in-interrupt-handlers-in-nrf/312959#312959"]When do clearing the pending register come into the picture?[/quote]
&lt;p&gt;All the program has to do is to clear the peripheral event register(s). Bits in the NVIC IRQ pending register are cleared automatically once the program exits the interrupt handler. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Concept of pending registers in interrupt handlers in nRF</title><link>https://devzone.nordicsemi.com/thread/312959?ContentTypeID=1</link><pubDate>Tue, 01 Jun 2021 17:23:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a8059de-2ff3-471b-8cc1-35afa372d537</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Thanks. So typically certain interrupts are cleared by reading the register itself?&amp;nbsp;When do clearing the pending register come into the picture?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Concept of pending registers in interrupt handlers in nRF</title><link>https://devzone.nordicsemi.com/thread/312630?ContentTypeID=1</link><pubDate>Mon, 31 May 2021 12:14:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8599d087-80ba-4125-85e9-fc15b637990b</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Yes, it&amp;#39;s sufficient to clear the peripheral event register. The IRQ pending bit will become cleared once you exit the ISR. But it might be woth noting that it can take a few CPU cycles for the peripheral event register to become cleared, please see&amp;nbsp; &amp;quot;&lt;a href="https://infocenter.nordicsemi.com/topic/migration_nrf52/MIG/nrf52_migration/functional.html"&gt;Interrupt event clearing&amp;quot; &lt;/a&gt;for more details.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>