<?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>pstorage handler callback without scheduler?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9262/pstorage-handler-callback-without-scheduler</link><description>This should be simple, but I just can&amp;#39;t get it working. 
 Many examples show setting a flag before calling the pstorage clear/store/load functions and then looping, waiting for the pstorage handler to change this flag to signify that it finished. 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 17 Sep 2015 02:35:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9262/pstorage-handler-callback-without-scheduler" /><item><title>RE: pstorage handler callback without scheduler?</title><link>https://devzone.nordicsemi.com/thread/34182?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2015 02:35:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aedb9347-63b4-4538-90c4-a9f5de829ca3</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Yes, sorry for the confusion. Initially I had none of the while() loop stuff at all and everything seemed to be working dandy. Then I figured I should wait for the clear to finish before calling the store, so I looked at examples and they had the while() power_manage() loop, so I added that, which obviously does not work in my case.  Where it prints out &amp;#39;1&amp;#39; forever above, I commented it out.&lt;/p&gt;
&lt;p&gt;So it looks like the best way to go is to convert this to use the scheduler, which I sort of tried yesterday, but then everything broke. I am not the original author of this code and am basically taking over a &amp;#39;half-working&amp;#39; project - going through and fixing things.&lt;/p&gt;
&lt;p&gt;Thanks for the help and look out for me asking questions about using the scheduler :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage handler callback without scheduler?</title><link>https://devzone.nordicsemi.com/thread/34181?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2015 02:11:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4319302d-5e35-4c9c-9b35-3db7776337ee</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;but there&amp;#39;s a call to power_manage() in the code you posted for &amp;#39;store()&amp;#39; which is not your main loop. Or is that not your real code?&lt;/p&gt;
&lt;p&gt;yes a timer timeout handler is called in interrupt context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage handler callback without scheduler?</title><link>https://devzone.nordicsemi.com/thread/34180?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2015 02:08:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7da23f18-56d5-4325-acc1-a1b95202fff3</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;The only place I am calling power_manage() is from the main loop:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Enter main loop.
for(;;) {
	power_manage();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I am assuming that a timer timeoutHandler() is an &amp;#39;interrupt handler&amp;#39;? Then any function that gets called from inside the timeoutHandler() would be running with APP_HIGH interrupt priority? And any following functions that are called from within the initially-called function would also be APP_HIGH interrupt priority - creating a giant chain of APP_HIGH interrupt priority &amp;#39;functions&amp;#39;? Then I see the problem...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage handler callback without scheduler?</title><link>https://devzone.nordicsemi.com/thread/34179?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2015 00:58:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d557d346-1c63-4ecd-ae4d-8f00c121c366</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;store(), I&amp;#39;m guessing that&amp;#39;s called from an interrupt handler, one running with APP_HIGH interrupt priority. If that&amp;#39;s the case you never leave the interrupt handler which means the lower-priority SWI which does all the event handling can never run, you&amp;#39;ve deadlocked yourself.&lt;/p&gt;
&lt;p&gt;Don&amp;#39;t put power_manage() in the interrupt handlers, put it in your main context, or run it at a lower interrupt priority (not a fan of that myself, interrupt handlers should be fast if possible). If you put it in your main thread then you&amp;#39;ll have to keep some kind of state machine variables to tell you you have started a store() operation and are waiting for the pstorage_clear() to finish in order to do the store.&lt;/p&gt;
&lt;p&gt;So no you don&amp;#39;t need a scheduler, there&amp;#39;s a ton of ways to do what you want, you may however find a scheduler, which runs in main thread context, it the easiest.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage handler callback without scheduler?</title><link>https://devzone.nordicsemi.com/thread/34178?ContentTypeID=1</link><pubDate>Wed, 16 Sep 2015 19:19:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13e14467-cd37-451d-8d7c-9e416832a355</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;If I remove the while() loop, then I will get the printf from the device_cd_handler(), &amp;quot;pstorage_clear success&amp;quot;.&lt;/p&gt;
&lt;p&gt;With the while() loop in place, it gets stuck in there. Changing power_manage() to __wfe() made no difference.  I changed it to this and it prints outs out &amp;#39;1&amp;#39; forever.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while(pstorageState) {
	//power_manage();
	//__wfe();
	SEGGER_RTT_printf(0, &amp;quot;pstorageState = %d\n&amp;quot;, pstorageState);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I am asking again, just to make sure, is a scheduler required for this to work?&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage handler callback without scheduler?</title><link>https://devzone.nordicsemi.com/thread/34177?ContentTypeID=1</link><pubDate>Wed, 16 Sep 2015 09:33:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1b58a8f-9a14-4ed7-abe4-56309a8690bb</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Is device_cb_handler() being called by the pstorage module? If so is it setting the pStorageState variable? If you run, wait a second and then hit break in the debugger, what&amp;#39;s the value of pStorageState? If it&amp;#39;s &amp;#39;1&amp;#39; then the issue is you&amp;#39;re not getting out of power_manage().&lt;/p&gt;
&lt;p&gt;If that&amp;#39;s the case - change it to __wfe()&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>