<?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>Interrupt context to main context with nRF Connect SDK 2.3.0</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/101696/interrupt-context-to-main-context-with-nrf-connect-sdk-2-3-0</link><description>Dear Support Team, 
 
 I would like to learn about delegating tasks from interrupt context to main context using nRF Connect SDK 2.3.0? Could you please provide an example? 
 
 
 Thank you very much in advance and all the best, 
 Viktor</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Jul 2023 12:50:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/101696/interrupt-context-to-main-context-with-nrf-connect-sdk-2-3-0" /><item><title>RE: Interrupt context to main context with nRF Connect SDK 2.3.0</title><link>https://devzone.nordicsemi.com/thread/435738?ContentTypeID=1</link><pubDate>Tue, 11 Jul 2023 12:50:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5d6aa57-a425-4c39-ab7c-5be16d3796c3</guid><dc:creator>ViktorVarjas</dc:creator><description>&lt;p&gt;Hi Hieu!&lt;/p&gt;
&lt;p&gt;Thank you very much, this is what I was looking for. Especially the &amp;quot;system workqueue&amp;quot; is the option I need, which is not really the focus of the fundamental course. It seems that the&amp;nbsp;&lt;span&gt;&amp;quot;system workqueue&amp;quot; is preferred solution as long as it is not full.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Important parameter in proj.conf:&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE = 2048 (default size)&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;To offload work from interrupt context:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;struct k_work work;

void offload_function(struct k_work *work_tem)
{
	//do work here
}

void IRQ_handler(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
	k_work_submit(&amp;amp;work);       // submit to queue from the interrupt handler
}

void main(void)
{
    //other initializations such as BLE, IRQ handlers, etc
    
    k_work_init(&amp;amp;work, offload_function);
}&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;All the best,&lt;/p&gt;
&lt;p&gt;Viktor&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interrupt context to main context with nRF Connect SDK 2.3.0</title><link>https://devzone.nordicsemi.com/thread/435589?ContentTypeID=1</link><pubDate>Tue, 11 Jul 2023 00:31:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f1421db-f88c-4570-93d3-594b03bc7de3</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Viktor,&lt;/p&gt;
&lt;p&gt;For this, you could refer to&amp;nbsp;our free &lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/"&gt;nRF Connect SDK Fundamental course&lt;/a&gt;. Of immediate interest to your question would be&amp;nbsp;&lt;a href="https://academy.nordicsemi.com/lessons/lesson-7-multithreaded-applications/"&gt;Lesson 7: Multithreaded applications&lt;/a&gt;, and &lt;a href="https://academy.nordicsemi.com/lessons/lesson-8-thread-synchronization/"&gt;Lesson 8: Thread synchronization&lt;/a&gt;. However, I recommend going over the entire course if you are new to the nRF Connect SDK.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>