<?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>Work queues</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59156/work-queues</link><description>Hi 
 Technically this is a Zephyr question, but googling the issue gave no success. Also, reading the Zephyr docs gavve me no clue. 
 I have a custom nrf9160 board with an accelerometer (ADXL343). I have two scheduled tasks (starting and stopping GPS</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 16 Apr 2020 11:31:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59156/work-queues" /><item><title>RE: Work queues</title><link>https://devzone.nordicsemi.com/thread/244957?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 11:31:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81e98d47-42a4-430f-adf9-2e445cc7bbe1</guid><dc:creator>Tron</dc:creator><description>&lt;p&gt;I totally redesigned the solution, and now got it to work.&lt;/p&gt;
&lt;p&gt;The way I solved it was to start the GSensor in the regular thread, and submit a delayed work to the normal work queue in order to stop the interupt.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I thank you for your patience.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Work queues</title><link>https://devzone.nordicsemi.com/thread/241428?ContentTypeID=1</link><pubDate>Tue, 24 Mar 2020 15:53:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ae6a03e-08ea-43ea-af8f-3012e1ac0120</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Have you tried calling k_delayed_work_cancel() outside of the ISR? I tested this and it works, but calling it inside gave me a hardfault.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Work queues</title><link>https://devzone.nordicsemi.com/thread/241079?ContentTypeID=1</link><pubDate>Mon, 23 Mar 2020 10:28:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22991e13-ebea-4826-91fa-7938214cbb9f</guid><dc:creator>Tron</dc:creator><description>&lt;p&gt;First start on GPS, I get error code -22:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;]Turning gsensor ON
[3.23 11.26.58.090]Turning LNA	ON
[3.23 11.26.58.090]Turned LNA ON
[3.23 11.26.58.090]Cancel GPS work resutlt: -22
[3.23 11.26.59.098]GPS	thread_id: 0x20028ce0
[3.23 11.26.59.098]GPS	started	successfully.
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Work queues</title><link>https://devzone.nordicsemi.com/thread/241048?ContentTypeID=1</link><pubDate>Mon, 23 Mar 2020 09:12:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a42ff757-f7ac-4213-9e95-a925699a953c</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Have you checked the return code for when you run k_delayed_work_cancel() in gps_control_start()?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Work queues</title><link>https://devzone.nordicsemi.com/thread/240726?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2020 19:31:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a75e4be-206b-4ef6-bac4-d96bc5f1ad30</guid><dc:creator>Tron</dc:creator><description>&lt;p&gt;GSensor custom defined worker thread has priority 5, I am a lazy bugger, and this was the suggested priority in the sample.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Main thread has pri 7 (according to the prj.conf) file, and system work queue has default priority(whatever that is), I havent found any files where it has been changed from the default config.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Work queues</title><link>https://devzone.nordicsemi.com/thread/240706?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2020 16:10:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f562ddb-7ae7-45d2-97b9-6063a01110c7</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;What priorities do you have on the work queues and on main?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Work queues</title><link>https://devzone.nordicsemi.com/thread/240461?ContentTypeID=1</link><pubDate>Wed, 18 Mar 2020 13:55:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44ee7bb6-7979-4997-8b83-ece65cd7d1f4</guid><dc:creator>Tron</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is how I use the system work queue (GPS work item):&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void  gps_control_stop(u32_t delay_ms) {
#if !defined(CONFIG_GPS_SIM)
    if (gps_control_is_active()) {
        setLNAState(false);
        atomic_set(&amp;amp;gps_is_active, 0);

        k_delayed_work_cancel(&amp;amp;gps_work.work);
        gps_work.type = GPS_WORK_STOP;
        k_delayed_work_submit(&amp;amp;gps_work.work, delay_ms);
    }
#endif
}

void gps_control_start(u32_t delay_ms) {
#if !defined(CONFIG_GPS_SIM)
    setLNAState(true);
    atomic_set(&amp;amp;gps_is_active, 1);
    //    setLedState(LED_RED, true);
    k_delayed_work_cancel(&amp;amp;gps_work.work);
    gps_work.type = GPS_WORK_START;
    k_delayed_work_init(&amp;amp;gps_work.work, gps_work_handler);

    k_delayed_work_submit(&amp;amp;gps_work.work, delay_ms);
#endif
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The code for using the dedicated work queue is as follows:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void nRFGSensorInit(void) {
    printk(&amp;quot;Starting GSensor init\n&amp;quot;);
    gpio_vdd_sensor(true);
    i2c_gpio_init();

    nRFGSensorInitWorkQueue();
    printk(&amp;quot;Gsensor work queue init complete\n&amp;quot;);
    //set Shock	Level for the accelerometer
    adxl343_init(GSENSOR_STARTUP_SHOCKLEVEL);

    gpio_vdd_sensor(false);
    //Turn on all axes
    //setActivityXYZ(true, true, true);
    gpio_adxl343_interrupt_configure(gpio_adxl_interrupt_handler);

    k_delayed_work_init(&amp;amp;gsensor_work.work, gsensor_handler);

    printk(&amp;quot;i2c	gsensor	init complete!\n&amp;quot;);
    
    k_delayed_work_submit_to_queue(&amp;amp;gsensor_work_q, &amp;amp;gsensor_work.work,	K_SECONDS(240));
    printk(&amp;quot;Starting gsensor process in	4 minutes\n&amp;quot;);
}


void gpio_adxl_interrupt_handler(struct	device *port, struct gpio_callback *cb,	u32_t pins) {
    printk(&amp;quot;Interrupt from GSensor received!\n&amp;quot;);
    if (callback != NULL) {
	callback(NULL);
    }
    k_delayed_work_cancel(&amp;amp;gsensor_work.work);
    gsensor_work.type=GSENSOR_STOP;
    k_delayed_work_submit_to_queue(&amp;amp;gsensor_work_q, &amp;amp;gsensor_work.work,	K_NO_WAIT);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As far as I can see, there is no API call to cansel a delayed work item from a specific work queue, Therefore the k_delayed_work_cancel without the queue parameter.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hope this helps&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Work queues</title><link>https://devzone.nordicsemi.com/thread/240454?ContentTypeID=1</link><pubDate>Wed, 18 Mar 2020 13:41:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:755ea44b-f282-4c96-8dfe-b3caff3833b6</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;can you share the code where you use the system work queue, and also the rest of the code where you use a dedicated work queue. That way I can see if you are doing something wrong in the code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>