<?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>SOFTDEVICE_HANDLER_APPSH_INIT + pstorage</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/29161/softdevice_handler_appsh_init-pstorage</link><description>ble_senso4s_v_0_7_poenostavljena4_1 power_manager.rar Hi 
 I read a lot about p_storage library and I tested it and works great if I use SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL). On the other hand, If SOFTDEVICE_HANDLER_APPSH_INIT</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 24 Jan 2018 13:10:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/29161/softdevice_handler_appsh_init-pstorage" /><item><title>RE: SOFTDEVICE_HANDLER_APPSH_INIT + pstorage</title><link>https://devzone.nordicsemi.com/thread/115900?ContentTypeID=1</link><pubDate>Wed, 24 Jan 2018 13:10:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a265700f-5a3f-4a0b-93fc-762000c4ac3c</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have looked closer at your code and you are right of course. The timers are run from main context since you are using a scheduler. However, several places in your code you have these lines of code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while(pstorage_wait_flag)
{
    power_manage();	
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And I think you are suspicious about this yourself since at one point you have this comment&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// if power_manage() function is replaced by  app_sched_execute() then the program passes the timer 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is probably the core of the matter. These while loops effectively act as deadlocks because you are waiting for an event that sets pstorage_wait_flag to false, but you never allow the scheduler to process the event. In other words, the system might trigger an interrupt when your flash operation is completed, but unless you call app_sched_execute() the event is never processed and the flag never cleared.&lt;/p&gt;
&lt;p&gt;What you can try to do is to add app_sched_execute() to your while loops like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while(pstorage_wait_flag)
{
    app_sched_execute();
    power_manage();	
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SOFTDEVICE_HANDLER_APPSH_INIT + pstorage</title><link>https://devzone.nordicsemi.com/thread/115899?ContentTypeID=1</link><pubDate>Sun, 21 Jan 2018 15:36:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4af7fa8b-2420-476d-b565-593cda4ce61e</guid><dc:creator>samo</dc:creator><description>&lt;p&gt;I agree with your conclusion if I use app_timer without a scheduler. If you will look carefully at my code you will see that app_timer uses a scheduler and thus app_timer is not executed in interrupt context. If I know correctly the problem with interrupt context can arise only if the app_timer does not use a scheduler. The attached code is the simplified version of the original code in which the pstorage functions are called a few times. Due to this fact, it is good to track a flag.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SOFTDEVICE_HANDLER_APPSH_INIT + pstorage</title><link>https://devzone.nordicsemi.com/thread/115898?ContentTypeID=1</link><pubDate>Wed, 17 Jan 2018 13:58:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e72ba3f-b118-4c5d-8f78-8cb9ad0ec653</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;This looks very similar to this:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/question/29547/pstorage-update-problem-call-back-is-not-getting-called/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;and this:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/question/51431/pstorage-handler-callback-without-scheduler/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It seems like you are starting the pstorage operation from within an interrupt context (app_timer) and then wait in a while loop in that very same interrupt for another interrupt to happen (example_cb_handler). But example_cb_handler() never gets called and your flag never gets set.&lt;/p&gt;
&lt;p&gt;Do you even need the while loop in your timer handler?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SOFTDEVICE_HANDLER_APPSH_INIT + pstorage</title><link>https://devzone.nordicsemi.com/thread/115896?ContentTypeID=1</link><pubDate>Wed, 10 Jan 2018 21:45:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b78bab1-aaac-4fb9-bf70-1f81f255c592</guid><dc:creator>control</dc:creator><description>&lt;p&gt;I added the program to my first post, in which I implemented a similar situation which happened in my original code. I use one time called m_mass_battery_timer_id and it is executed 2500ms after power on. When the timer is executed four bytes are stored in flash but the program does not pass through the while loop where the power_manage()  is located. If I replace power_manage() function with app_sched_execute() then the program works fine. the program is located in the pca 10028 file. I will be very pleased with any feedback.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SOFTDEVICE_HANDLER_APPSH_INIT + pstorage</title><link>https://devzone.nordicsemi.com/thread/115897?ContentTypeID=1</link><pubDate>Tue, 09 Jan 2018 22:42:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e6c41d08-74e5-4fa5-8eb3-380e27f49402</guid><dc:creator>control</dc:creator><description>&lt;p&gt;Hi Martin,&lt;/p&gt;
&lt;p&gt;I use app_timer library and APP_TIMER_APPSH_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, true) function for the timer scheduler.Tomorrow I will try to do additional experiments and I will reply to your second question as fast as possible&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SOFTDEVICE_HANDLER_APPSH_INIT + pstorage</title><link>https://devzone.nordicsemi.com/thread/115895?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2018 13:10:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3764557-cb54-44fc-9df0-31b30808f896</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;What kind of timers are you using? The app_timer library? With scheduler?&lt;/li&gt;
&lt;li&gt;Can you confirm that your code is actually looping in this standard power_manage function&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void power_manage(void)
{
    uint32_t err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And that no other code is executed? If this is an issue with interrupt priorities and the softdevice it seems strange that you don&amp;#39;t get hard faults.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SOFTDEVICE_HANDLER_APPSH_INIT + pstorage</title><link>https://devzone.nordicsemi.com/thread/115894?ContentTypeID=1</link><pubDate>Sat, 30 Dec 2017 13:15:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d5df54e-e78c-4fd5-bfaa-f7019d60cf49</guid><dc:creator>control</dc:creator><description>&lt;p&gt;Hi Martin,&lt;/p&gt;
&lt;p&gt;I think that I found out the problem. I will be really appreciated if you can confirm my assumption. In my code, the times are executed in the main loop because I am using the scheduler. The softdevice is also executed in the main loop which means that BLE event does not have higher priority compared to the application timers (where pstorage_update function and subsequently power_manage() function are called). Both of them are loaded in the queue according to schedule rule. Because BLE event and timers are executed with the same priority, the code waits for a p_storage flag longer than the critical interval for execution of BLE event. Due to this fact, I guess that BLE event cannot be executed just in time. I use SDK 10. If my assumption is not true then I will upload the code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SOFTDEVICE_HANDLER_APPSH_INIT + pstorage</title><link>https://devzone.nordicsemi.com/thread/115893?ContentTypeID=1</link><pubDate>Thu, 28 Dec 2017 10:29:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bdac0003-2f7d-4e70-a436-8a4b89f27c3c</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;What SDK and softdevice versions are you using?&lt;/li&gt;
&lt;li&gt;Do you mind uploading your code? (You can edit your first questions and attach files)&lt;/li&gt;
&lt;li&gt;power_manage() is located in the main while forever loop in main() right? What do you mean stuck? The code is supposed to loop forever and wake up on system and BLE events.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>