<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://test-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>USB IRQ Latency</title><link>https://test-devzone.nordicsemi.com/f/nordic-q-a/88941/usb-irq-latency</link><description>Hello, 
 We&amp;#39;re working with nRF52833 &amp;amp; nRF52840 and I&amp;#39;m trying to figure out why we&amp;#39;ve ~0.3ms IRQ Latency from the moment I call the function &amp;quot; uart_irq_tx_enable (dev ); &amp;quot; until I actually get to the callback I&amp;#39;ve registered at &amp;quot; uart_irq_callback_set</description><dc:language>en-US</dc:language><generator>Telligent Community 13 Non-Production</generator><lastBuildDate>Thu, 16 Jun 2022 06:53:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://test-devzone.nordicsemi.com/f/nordic-q-a/88941/usb-irq-latency" /><item><title>RE: USB IRQ Latency</title><link>https://test-devzone.nordicsemi.com/thread/372707?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 06:53:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f77df4a7-467e-42e0-b194-19c0a1988b3c</guid><dc:creator>user115118</dc:creator><description>&lt;p&gt;Interesting, I&amp;#39;m also getting ~30us using &lt;strong&gt;cdc_acm&lt;/strong&gt; example.&lt;/p&gt;
&lt;p&gt;What is different in my scenario (which takes ~300us) is that the interruption is &amp;quot;enabled&amp;quot; in the end of an &lt;strong&gt;esb callback&lt;/strong&gt; (set in &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;esb_config.event_handler&lt;/span&gt; at &amp;quot;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;esb_init()&lt;/span&gt;&amp;quot;).&lt;/p&gt;
&lt;p&gt;So it seems that as you stated, the&amp;nbsp;scheduler is busy on something else right after it exits this callback function.&lt;/p&gt;
&lt;p&gt;(pseudo) Code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void event_handler(struct esb_evt const *event)
{
	switch (event-&amp;gt;evt_id) {
	case ESB_EVENT_TX_SUCCESS:
	    // ...
		break;
	case ESB_EVENT_TX_FAILED:
	    // ...
		break;
	case ESB_EVENT_RX_RECEIVED:
		// ...
		break;
	}
	startMeasurement = Timestamp_us();
	uart_irq_tx_enable(dev);
	(void)uart_fifo_fill(dev, &amp;quot; &amp;quot;, 1);
}

// ...

static void serial_interrupt_handler(const struct device *dev, void *user_data)
{	
	// ...
	if (uart_irq_tx_ready(dev)) 
	{
		long long now = Timestamp_us();
	    serial_response_offset += sprintf(&amp;amp;serial_response[serial_response_offset], 
    		&amp;quot;, t_irq: %llu###&amp;quot;,
    		(now - startMeasurement)
    		);			
		(void)uart_fifo_fill(dev, serial_response, serial_response_offset);
		serial_response[serial_response_offset] = 0;
		serial_response_offset = 0;
		// mark we&amp;#39;ve concluded the sending, otherwise it will remain stuck here
		uart_irq_tx_disable(dev);		
	}
    // ...
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is the&amp;nbsp;scenario&amp;#39;s big picture (I&amp;#39;ve omitted the details).&lt;/p&gt;
&lt;p&gt;Let me know if there is some&amp;nbsp;trick to&amp;nbsp;increase the UART priority.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB IRQ Latency</title><link>https://test-devzone.nordicsemi.com/thread/372426?ContentTypeID=1</link><pubDate>Tue, 14 Jun 2022 14:49:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95b6c84e-30a3-441f-9420-5dc2630e2520</guid><dc:creator>user2115</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Vagner Landskron"]&lt;p&gt;The units are:&lt;/p&gt;
&lt;p&gt;axis-Y (milliseconds)&lt;br /&gt;&lt;span style="font-family:inherit;"&gt;axis-X (iterations)&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;thank you for explaining. I see that its between 200 - 500 us, depending on the iteration, based on your graph.&lt;/p&gt;
&lt;p&gt;It is a scheduled operation within the kernel, where it executes based on what else is running in your application, it will take a bit of time.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you see the same timing if you run the zephyr/samples/subsys/usb/cdc_acm example as well? I see a delay of approx. 28 us when setting a GPIO, calling uart_irq_tx_enable(), then clearing it again in the handler.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB IRQ Latency</title><link>https://test-devzone.nordicsemi.com/thread/372415?ContentTypeID=1</link><pubDate>Tue, 14 Jun 2022 14:01:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5b3e764-94af-46ed-a293-bfc39309d4af</guid><dc:creator>user115118</dc:creator><description>&lt;p&gt;Hi Hakon, thanks for your reply.&lt;/p&gt;
&lt;p&gt;Oh, I see it now. Is there a way to increase priority or reduce this latency somehow?&lt;/p&gt;
&lt;p&gt;The units are:&lt;/p&gt;
&lt;p&gt;axis-Y (milliseconds)&lt;br /&gt;&lt;span style="font-family:inherit;"&gt;axis-X (iterations)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;For now, this latency is around &lt;strong&gt;~0.3ms&lt;/strong&gt; (measured by the board itself, so I could use higher resolutions).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: USB IRQ Latency</title><link>https://test-devzone.nordicsemi.com/thread/372374?ContentTypeID=1</link><pubDate>Tue, 14 Jun 2022 12:21:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9b3c573-e0a4-4395-836d-5fcde56336d3</guid><dc:creator>user2115</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is submitting an item to the workqueue, and then calling the callback function:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/subsys/usb/device/class/cdc_acm.c#L553"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/subsys/usb/device/class/cdc_acm.c#L553&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Depending on what else is happening in your system, it will take a bit of time for switching context.&lt;/p&gt;
&lt;p&gt;What is the accuracy of your timing diagram? It is a bit hard to understand your graphs directly.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>