<?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>Zephyr Power Management PM_STATE_SOFT_OFF</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/90464/zephyr-power-management-pm_state_soft_off</link><description>I am having trouble figuring out how to put system in PM_STATE_SOFT_OFF from inside workqueue. If I put system to sleep inside workqueue it does&amp;#39;t go to sleep, looks like execution continues. How should I approach this problem? 
 
 In current example</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 08 Aug 2022 12:32:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/90464/zephyr-power-management-pm_state_soft_off" /><item><title>RE: Zephyr Power Management PM_STATE_SOFT_OFF</title><link>https://devzone.nordicsemi.com/thread/380614?ContentTypeID=1</link><pubDate>Mon, 08 Aug 2022 12:32:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7f05a37-cba2-4587-a121-288f92b2f9f9</guid><dc:creator>Michal</dc:creator><description>&lt;p&gt;I understand. Running everything in a lower priority thread than the workqueue is probably the easiest solution.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Michal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr Power Management PM_STATE_SOFT_OFF</title><link>https://devzone.nordicsemi.com/thread/380018?ContentTypeID=1</link><pubDate>Thu, 04 Aug 2022 04:55:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04a965e6-4cfe-4079-b54b-42791e001633</guid><dc:creator>akaun</dc:creator><description>&lt;p&gt;I am using driver for max17262 as a base from zephyr drivers. The only thing I did was added a timer for a trigger, so it reads values every 5 minutes by using a workqueue.&lt;/p&gt;
&lt;p&gt;I will just make sure everything is running in a thread and that powerdown will have highest priority. Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr Power Management PM_STATE_SOFT_OFF</title><link>https://devzone.nordicsemi.com/thread/379443?ContentTypeID=1</link><pubDate>Mon, 01 Aug 2022 07:20:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1893801-2f39-4634-81a3-e2028310c59c</guid><dc:creator>Michal</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;Could you tell me the names of (or send me the links to) the driver and example that you have used? I could take a look at those.&lt;br /&gt;There should be nothing wrong with doing it via a workqueue, but you have to be wary of the thread priorities, especially with the main() thread if you&amp;#39;re using that.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Michal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr Power Management PM_STATE_SOFT_OFF</title><link>https://devzone.nordicsemi.com/thread/379383?ContentTypeID=1</link><pubDate>Fri, 29 Jul 2022 22:16:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9586521f-cffc-4396-ac59-eca9466315f6</guid><dc:creator>akaun</dc:creator><description>&lt;p&gt;OK, I understand that, I have a battery gauge thats periodically checking battery level and if battery is low I need to shut down the system. Per driver documentation its best to have any trigger return through a workqueue. But it will never shut down. Should I just avoid using workqueue in driver trigger implementation then?&lt;/p&gt;
&lt;p&gt;As far as k_sleep in power_down, I am not sure why its there, thats how it is written in the SDK example so I figured it needs to be there.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr Power Management PM_STATE_SOFT_OFF</title><link>https://devzone.nordicsemi.com/thread/379344?ContentTypeID=1</link><pubDate>Fri, 29 Jul 2022 14:14:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0bae6af-2d25-4155-8916-c211a6437c4b</guid><dc:creator>Michal</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Running a workqueue thread is not like just calling a function. It is spawning a separate thread. I would recommend reading &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/kernel/services/threads/workqueue.html"&gt;the documentation about Workqueque Threads&lt;/a&gt; (and maybe threads in zephyr in general).&lt;/p&gt;
&lt;p&gt;The main() thread by default has the highest priority. More about that &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/kernel/services/threads/system_threads.html"&gt;HERE&lt;/a&gt;&lt;br /&gt;Your workqueue thread will have lower priority and that&amp;#39;s why it will not work.&lt;/p&gt;
&lt;p&gt;If you suspend the main thread, for example by running k_sleep(K_FOREVER); then your workqueue thread will run properly.&lt;br /&gt;You could also let the main() return.&lt;/p&gt;
&lt;p&gt;Also, the k_sleep in power_down will not work when run properly, since it happens after switching the state to &lt;span&gt;&lt;span&gt;&lt;span&gt;PM_STATE_SOFT_OFF&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; which equals to the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52833/power.html?cp=4_1_0_4_2_2#unique_1983887295"&gt;SYSTEM OFF mode&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Michal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>