<?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>Which bit of which register gets set when a TWI interrupt is fired and where is it being reset?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/83253/which-bit-of-which-register-gets-set-when-a-twi-interrupt-is-fired-and-where-is-it-being-reset</link><description>Which bit of which register gets set upon the triggering of an interrupt? Is there something equivalent to EXTI_PR (pending register) from STM32 which gets set upon triggering and reset before IRQ handler is exited? To be precise, this is in the context</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 07 Jan 2022 20:19:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/83253/which-bit-of-which-register-gets-set-when-a-twi-interrupt-is-fired-and-where-is-it-being-reset" /><item><title>RE: Which bit of which register gets set when a TWI interrupt is fired and where is it being reset?</title><link>https://devzone.nordicsemi.com/thread/346765?ContentTypeID=1</link><pubDate>Fri, 07 Jan 2022 20:19:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03b498fa-0827-4867-a2c5-d555231ecbe0</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;__disable_irq() disables all interrupts, yes. Note that you should not use this if you are using&amp;nbsp; a SoftDevice, though (I don&amp;#39;t know if you do). If you are using the nRF5 SDK then you could look at the&amp;nbsp;app_util_critical_region_enter() et in components\libraries\util\app_util_platform.c, which is the implementatino used for&amp;nbsp;CRITICAL_REGION_ENTER()/EXIT(). This use&amp;nbsp;__disable_irq() when a SoftDevice is not used, and&amp;nbsp;sd_nvic_critical_region_enter() if a SoftDevice is used. In the latter case&amp;nbsp;sd_nvic_critical_region_enter() only disables application interrupts. SoftDevice interrupts may still happen.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Which bit of which register gets set when a TWI interrupt is fired and where is it being reset?</title><link>https://devzone.nordicsemi.com/thread/346759?ContentTypeID=1</link><pubDate>Fri, 07 Jan 2022 18:20:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed750602-a902-4f6f-a91a-ad4815b9ca4e</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Yes, I was referring more to the case where an interrupt modifying a FIFO and the next moment it&amp;nbsp;gets preempted by an interrupt of higher priority that accesses the same FIFO. Mutex can&amp;#39;t really be used in the context of interrupts and in FreeRTOS, there&amp;#39;s a way to disable all the interrupts via&amp;nbsp; taskenter_critical_from_isr but what&amp;#39;s the way to do so in ARM?&amp;nbsp;__disable_irq? does it disable ALL the interrupts? If so, in this case, the higher priority interrupt would not trigger/not preempt?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Which bit of which register gets set when a TWI interrupt is fired and where is it being reset?</title><link>https://devzone.nordicsemi.com/thread/345874?ContentTypeID=1</link><pubDate>Tue, 04 Jan 2022 11:36:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e99661a1-7786-4970-b037-7e499aea9efd</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="morpho"]Also, what&amp;#39;s the way to acquire mutual exclusion within the context of ISRs? to disable any other interrupt that may potentially access the same resources as used within the current ISR?[/quote]
&lt;p&gt;I am not sure why this would be needed in the drivers, as they are typically independent, and normally only use a single interrupt ID. But if you have your own code where you have two interrupts or two threads or similar that share data, this can be important. Generally, you have two fundamental methods. One is to use critical sections, where all interrupts are disabled whenever you need to do something that cannot be interrupted (like updating a mutex). Alternatively, you can use the Load-Exclusive and Store-Exclusive (LDREX/STREX) instructions in the cortex core, which is less intrusive. These are used in the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__nrfx__atomic.html"&gt;nrfx_atomic library&lt;/a&gt;. This in turn is used by&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__nrf__mtx.html"&gt;nRF Mutx&lt;/a&gt;, which implements a mutex that you can use.&lt;/p&gt;
[quote user="morpho"]The twi_sensor application invokes&amp;nbsp;nrf_drv_twi_enable to enable the TWI instance and not interrupts? which call sets INTENSET register with the respective flags?[/quote]
&lt;p&gt;Interrupts are enabled by the driver implementation. If you use the TWI peripheral (no DMA), you find that in&amp;nbsp;modules\nrfx\drivers\src\nrfx_twi.c. If yo use TWIM (with DMA), you see it in&amp;nbsp;modules\nrfx\drivers\src\nrfx_twim.c. Then search for &amp;quot;int_enable&amp;quot; in these files to see where it is. (This is implementation details that you normally do not need to consider when you are just using the driver.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Which bit of which register gets set when a TWI interrupt is fired and where is it being reset?</title><link>https://devzone.nordicsemi.com/thread/345779?ContentTypeID=1</link><pubDate>Tue, 04 Jan 2022 01:46:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c014c6e7-4be3-4898-9cca-5d545ee7b788</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;thanks for the response.&lt;/p&gt;
&lt;p&gt;so in&amp;nbsp;twi_transfer(), the interrupts of the respective flags that got triggered are cleared and at the end, the callback handler is invoked which is a part of the&amp;nbsp;user application.&lt;/p&gt;
&lt;p&gt;Also, what&amp;#39;s the way to acquire mutual exclusion within the context of ISRs? to disable any other interrupt that may potentially access the same resources as used within the current ISR?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The twi_sensor application invokes&amp;nbsp;nrf_drv_twi_enable to enable the TWI instance and not interrupts? which call sets INTENSET register with the respective flags?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Which bit of which register gets set when a TWI interrupt is fired and where is it being reset?</title><link>https://devzone.nordicsemi.com/thread/345670?ContentTypeID=1</link><pubDate>Mon, 03 Jan 2022 12:55:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1df6b32-1ab7-4f85-8d94-890f1fc0814a</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The concept of pending interrupts is related to the Cortex core and NVIC are generic. That includes enabling and disabling interrupts with a specific ID. All interrupts from the same peripheral has the same ID (and thus same interrupt handler). I interpret the question here to be more related to how interrupts are generated and cleared in the peripherals, though and specifically the TWI.&lt;/p&gt;
&lt;p&gt;I want to first highlight the&amp;nbsp;&lt;span&gt;Tasks, events, shortcuts, and interrupts figure under &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/peripheral_interface.html?cp=4_0_0_5_0"&gt;peripheral interface&lt;/a&gt;. As you see here, events are always enabled, but only trigger interrupt when interrupt has been enabled for that specific interrupt. So for instance, in order to get an interrupt for&amp;nbsp;EVENT_TXDSENT, you first need to enable interrupts for TWI in the NVIC, and then also need to enable interrupt for&amp;nbsp;TXDSENT in&amp;nbsp;INTENSET. Once that is in place, you will get an interrupt for any&amp;nbsp;TXDSENT event.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In order to clear this event, you need to write 0 to&amp;nbsp;EVENTS_TXDSENT.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Looking at the driver (nrfx_twi.c in SDK 17.1.0) you can see that the event is cleared when appropriate&amp;nbsp;using&amp;nbsp;nrf_twi_event_clear(). For instance, on line 365:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_TXDSENT);&lt;/pre&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>