This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SOFTDEVICE_HANDLER_APPSH_INIT + pstorage

ble_senso4s_v_0_7_poenostavljena4_1 power_manager.rarHi

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 function is used for starting softdevice then the program stucks in while loop where the power_manage() function is located. I will be appreciated for any kind of information why this event happened and what is the reason for this.

best regards

Mike

Parents
  • Hi,

    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:

    while(pstorage_wait_flag)
    {
        power_manage();	
    }
    

    And I think you are suspicious about this yourself since at one point you have this comment

    // if power_manage() function is replaced by  app_sched_execute() then the program passes the timer 
    

    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.

    What you can try to do is to add app_sched_execute() to your while loops like this:

    while(pstorage_wait_flag)
    {
        app_sched_execute();
        power_manage();	
    }
    
Reply
  • Hi,

    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:

    while(pstorage_wait_flag)
    {
        power_manage();	
    }
    

    And I think you are suspicious about this yourself since at one point you have this comment

    // if power_manage() function is replaced by  app_sched_execute() then the program passes the timer 
    

    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.

    What you can try to do is to add app_sched_execute() to your while loops like this:

    while(pstorage_wait_flag)
    {
        app_sched_execute();
        power_manage();	
    }
    
Children
No Data
Related