<?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>GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52314/gpiote-high-accuracy-interrupt-latency</link><description>Hello, 
 Our product is configured to use 3 total GPIOTE channels –– 2 sensors configured for &amp;quot;high accuracy&amp;quot; GPIOTE events, each around 10Hz refresh rate, and 1 using &amp;quot;low accuracy&amp;quot; at 1Hz rate. In our interrupt handlers for each respective sensor, we</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 27 Sep 2019 11:58:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52314/gpiote-high-accuracy-interrupt-latency" /><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/212271?ContentTypeID=1</link><pubDate>Fri, 27 Sep 2019 11:58:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4854fff-d174-42c5-9964-c1858f6eeea7</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the logic trace. It&amp;#39;s interesting that the IRQ is asserted&amp;nbsp;but the flag ist still read as zero afterward from main the context. The timing looks as expected at least.&lt;/p&gt;
&lt;p&gt;I think you can test the theory related to pipelined instructions by placing instruction barriers (__ISB())&amp;nbsp;and maybe __MSB for good measure.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;By the way,&amp;nbsp;are you testing with or without compiler optimization, and is link-time optimization enabled? And could you verify if&amp;nbsp;&lt;span&gt;s_imu_data_ready&amp;nbsp;is loaded from RAM in the conditional check?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/212117?ContentTypeID=1</link><pubDate>Thu, 26 Sep 2019 15:58:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24d89729-4399-45f2-a06e-3133a6830ec7</guid><dc:creator>erik_fw</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;I have some test results and was able to capture this issue occurring while recording with a logic analyzer, the results are attached below.&lt;/p&gt;
&lt;p&gt;In the top row (DIO 1), a GPIO is being set during the ISR that sets our data ready flag.&lt;/p&gt;
&lt;p&gt;In the middle row (DIO 0) is the sensor&amp;#39;s interrupt pin (active low).&lt;/p&gt;
&lt;p&gt;The bottom row (DIO 6) follows a GPIO that is being set on the first line inside this conditional where the sensor&amp;#39;s interrupt pin is active but data ready&amp;nbsp;flag&amp;nbsp;hasn&amp;#39;t been set yet.&lt;/p&gt;
&lt;p&gt;The latency between interrupt pin being active and ISR executing doesn&amp;#39;t look concerning, it&amp;#39;s around 8&lt;span&gt;&amp;mu;s on average which seems like what we should be expecting.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Do you see anything concerning here or does it seem like this is just a natural case of the processor completing its pipelined instructions before executing the ISR that we are hitting by coincidence some small&amp;nbsp;% of the time?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks again!&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screen-Shot-2019_2D00_09_2D00_25-at-11.36.38-PM.png" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/211621?ContentTypeID=1</link><pubDate>Tue, 24 Sep 2019 17:35:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2dacfc5c-d1ab-4233-9a35-3127976d3c79</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Ok, thanks. I think I have a better understanding of your code now. Hope a logic trace&amp;nbsp;will&amp;nbsp;give us&amp;nbsp;some more clues.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/211615?ContentTypeID=1</link><pubDate>Tue, 24 Sep 2019 16:41:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ef9fc42-8b00-4dd3-8fd5-9707b10b93db</guid><dc:creator>erik_fw</dc:creator><description>&lt;p&gt;For all 3 sensors, the interrupt pin stays active until we retrieve the frame of data from the sensor. So we should never be seeing two interrupt triggers occur before data is retrieved.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/211473?ContentTypeID=1</link><pubDate>Tue, 24 Sep 2019 09:07:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6fcc734-4d4a-47f4-af60-053726b62cd5</guid><dc:creator>Vidar Berg</dc:creator><description>[quote user="erik_fw"]Yes, only one sensor is setting that particular flag, the other sensors use their own flags. The flag is only cleared when we, in a different section of code, check the flag and retrieve data from the sensor if it is set.&amp;nbsp;[/quote]
&lt;p&gt;&amp;nbsp;Thanks for confirming. But if readout of the sensor is delayed, is it then&amp;nbsp;possible that&amp;nbsp;imu_data_ready()&amp;nbsp;might be called just before the flag is cleared? For debugging, would it make sense to add a check for&amp;nbsp;s_imu_data_ready to see if it&amp;#39;s indeed &amp;#39;0&amp;#39; when you enter&amp;nbsp;imu_data_ready()?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/211358?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 16:16:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1df62219-313c-4579-acb4-c1042152e677</guid><dc:creator>erik_fw</dc:creator><description>&lt;p&gt;Yes, only one sensor is setting that particular flag, the other sensors use their own flags. The flag is only cleared when we, in a different section of code, check the flag and retrieve data from the sensor if it is set.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Great point about using a logic analyzer to measure the latency, we have a logic analyzer and haven&amp;#39;t tried that yet. I&amp;#39;ll try that out and come back with more information!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/211303?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 13:44:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38c7180a-81aa-437e-959f-4490bb51af53</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Is only one of the sensors that set the&amp;nbsp;s_imu_data_ready flag?&amp;nbsp;&lt;/p&gt;
[quote user="erik_fw"]I understand that the processor will still execute its current operation when a hardware interrupt arrives asynchronously, but seeing a full conditional execute in between the logic level change and ISR execution seems bizarre to us.[/quote]
&lt;p&gt;Agree.&amp;nbsp;CPU should stop execution and fetching of new instructions immediately after an&amp;nbsp;interrupt has been triggered.&amp;nbsp; And it&amp;nbsp;should only return to the main context when there are no pending interrupts left.&amp;nbsp;This makes me think&amp;nbsp;that either the IN event is not triggered or the&amp;nbsp;s_imu_data_ready flag is cleared before&amp;nbsp;it&amp;#39;s read by the&amp;nbsp;if statement.&lt;/p&gt;
&lt;p&gt;I think a logic analyzer/scope could help us understand the problem better if that&amp;#39;s an option in your case. If you have enough IOs available, you could use PPI and configure a GPIOTE output task to toggle the output&amp;nbsp;when an&amp;nbsp;IN occurs. That way you could verify the time it takes from&amp;nbsp;the sensor IRQ line is pulled low to the GPIOTE IN event and possibly&amp;nbsp;detect missed IRQs.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/210999?ContentTypeID=1</link><pubDate>Fri, 20 Sep 2019 15:26:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c979c82-5f51-4ca4-961d-614e6e7bb426</guid><dc:creator>erik_fw</dc:creator><description>&lt;p&gt;Yes&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/210860?ContentTypeID=1</link><pubDate>Fri, 20 Sep 2019 08:19:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08431373-e85b-4867-a899-480ad80c2f79</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Is the s_imu_data_ready variable declared &lt;strong&gt;volatile&lt;/strong&gt;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/210789?ContentTypeID=1</link><pubDate>Thu, 19 Sep 2019 20:56:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bae167fb-6b0b-4968-8755-fabe6835d70a</guid><dc:creator>erik_fw</dc:creator><description>&lt;p&gt;Additional information,&amp;nbsp;GPIOTE interrupt is configured as follows:&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);

in_config.pull = NRF_GPIO_PIN_PULLUP;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/210787?ContentTypeID=1</link><pubDate>Thu, 19 Sep 2019 19:43:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:087a1028-f67e-4ae1-8e0a-104a6dfa83a3</guid><dc:creator>erik_fw</dc:creator><description>&lt;p&gt;Thank you for the response.&lt;/p&gt;
&lt;p&gt;1. The issue isn&amp;#39;t a matter of latency in terms of time but rather the fact that our own non-interrupt application code is running between polling the GPIO and seeing the ISR get triggered. I&amp;#39;ll paste some example code below to show what I&amp;#39;m trying to describe (no need to set private, this is pretty generic and rudimentary):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Sensor interrupt callback functions
static void imu_data_ready()
{
    s_imu_data_ready = true;
}


...


// Check if interrupt pin is active

// Interrupt active for this sensor is low logic level, so negate result
interrupt_active = !(nrf_gpio_pin_read(ACCEL_DATA_READY_1_PIN));

if(interrupt_active &amp;amp;&amp;amp; !s_imu_data_ready)
{
    interrupt_test = s_imu_data_ready;
    APP_ERROR_HANDLER(ERROR_IMU_INTERRUPT_MISSED);
    
    // Uses segger RTT to minimize effect on program execution
    // Tells us the status of data ready flag immediately after the conditional
    PRINTF_RTT(&amp;quot;data ready flag %d\r\n&amp;quot;, interrupt_test);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So the issue I&amp;#39;m describing is that we can get into this conditional and &amp;#39;interrupt_test&amp;#39; will immediately tell us that data ready flag is now set to 1. In line 14 of this snipped we will see that the sensor&amp;#39;s interrupt pin is active, but then in line 16 we will see that data_ready flag is still 0, meaning that the ISR hasn&amp;#39;t run yet even though we see that the pin is high.&lt;/p&gt;
&lt;p&gt;In every test so far, &amp;#39;interrupt_test&amp;#39;, which is assigned in line 18, will be populated with a 1 when we go to RTT print it, meaning that the ISR was executed between the execution of the conditional (line 16) and the &amp;#39;interrupt_test&amp;#39; assignment.&lt;/p&gt;
&lt;p&gt;This shows conclusively that between our polling of the GPIO and seeing the ISR go off, the conditional is still being executed.&lt;/p&gt;
&lt;p&gt;Is there any debouncing / trigger window on the GPIOTE_IRQHandler that would prevent the IRQ from going off as soon as&amp;nbsp;the logic level on that GPIO line changes to what the GPIOTE interrupt channel is expecting?&lt;/p&gt;
&lt;p&gt;I understand that the processor will still execute its current operation when a hardware interrupt arrives asynchronously, but seeing a full conditional execute in between the logic level change and ISR execution seems bizarre to us. Is it possible that some optimization is combining those operations and that&amp;#39;s why we&amp;#39;re seeing this?&lt;/p&gt;
&lt;p&gt;Any ideas are welcome and appreciated. As for the #2 issue, I will be doing more testing to bring you more information on that scenario and what we know so far. Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE High-accuracy interrupt latency</title><link>https://devzone.nordicsemi.com/thread/210731?ContentTypeID=1</link><pubDate>Thu, 19 Sep 2019 13:42:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8fd3026-eab9-4481-ab57-741c0334b603</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Just to make sure, do you have separate &amp;#39;data ready&amp;#39; flag for each input? The IRQs are not particularly high in frequency so I wouldn&amp;#39;t expect it to be a problem with the Softdevice.&amp;nbsp;It also sounds like your ISRs are kept short, so that helps as well.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1. The GPIOTE IRQ will get blocked by the Softdevice interrupts from time to time, and I think it explains why the update of the flag gets delayed sometimes.&amp;nbsp; But the delay should only be in the micro-second range as long as you&amp;#39;re not erasing flash pages. Are you doing any flash operations when this happens?&amp;nbsp;&lt;span style="font-family:inherit;"&gt;Softdevice execution times inside ISRs are documented here:&amp;nbsp;&lt;/span&gt;&lt;a style="font-family:inherit;" title="Bluetooth Low Energy processor usage patterns" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/processor_avail_interrupt_latency/ble_usage_patterns.html?cp=3_4_2_0_15_2_2"&gt;Bluetooth Low Energy processor usage patterns&lt;/a&gt;&lt;span style="font-family:inherit;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;2. IRQs should&amp;nbsp;become&amp;nbsp;pending while&amp;nbsp;blocked by other higher priority IRQs&amp;nbsp;and should not become lost. Could it be possible that the GPIOTE IRQ gets processed but that there some race condition that causes the program to&amp;nbsp;not properly&amp;nbsp;de-assert the sensor IRQ line afterward?&amp;nbsp;Do you have a way to verify that the&amp;nbsp;GPIOTE IRQ&amp;nbsp;is not triggered when the IRQ lines go from low to high?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>