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

How do I block until any flash writes are finished by fstorage?

My application uses SDK 11 and s130 on an nRF51822. In certain cases I want to delete all my bonds and go into sys off.

I presume that when I call pm_peers_delete(), that results in a flash write using fstorage. How do I wait for that to complete before I go into sys off?

Parents
  • Perhaps I can do this in the main context? (Adapted from the approach I had with pstorage in the past)

    printf("Blocking till flash write completes.\n");
    
    uint32_t queued_flash_operations = 0;
    do {
        app_sched_execute();
        fs_queued_op_count_get(&queued_flash_operations);
    }
    while (queued_flash_operations > 0);
    
    app_system_off();
    
  • @Eliot Yes, something like that. The nRF51 will wake up on any interrupt, so when PM_EVT_PEERS_DELETE_SUCCEEDED is received, the nRF51 will wake up, execute pm_evt_handler() and then it will continue execution in the main thread.

    As in the example, to only continue execution in the main thread when you receive the PM_EVT_PEERS_DELETE_SUCCEEDED event, you can set a flag before going to sleep, which you check every time you wake up. When the PM_EVT_PEERS_DELETE_SUCCEEDED event is received you clear the flag and then execution will continue in the main thread.

Reply
  • @Eliot Yes, something like that. The nRF51 will wake up on any interrupt, so when PM_EVT_PEERS_DELETE_SUCCEEDED is received, the nRF51 will wake up, execute pm_evt_handler() and then it will continue execution in the main thread.

    As in the example, to only continue execution in the main thread when you receive the PM_EVT_PEERS_DELETE_SUCCEEDED event, you can set a flag before going to sleep, which you check every time you wake up. When the PM_EVT_PEERS_DELETE_SUCCEEDED event is received you clear the flag and then execution will continue in the main thread.

Children
No Data
Related