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

How to check pstorage operation is complete ?

Hi, When I write data synchronously to memory (nRF51822), I do :

APP_ERROR_CHECK(pstorage_block_identifier_get(flash_handler, 2, &block_handler));
APP_ERROR_CHECK(pstorage_clear(&block_handler, 16));
// check here ?
APP_ERROR_CHECK(pstorage_store(&block_handler, data_to_store, 16, 0)); 
// check here ?

Where I say 'check here' : I wonder if I should wait to move to next line by checking pstorage_access_status_get returns 0 or by having a variable that waits for the flash callback to be called.

Is it equivalent (apart from the details you get in the callback) ? Thanks

EDIT :

I call this synchronous function after every flash operation (clear or write), and this seems like the proper way to go. In the flash callback handler, I reset if there is anything else than a success

void wait_pstorage_access() {
    uint32_t count;
    do {
        app_sched_execute();
        pstorage_access_status_get(&count);
    } while (count > 0);
}
Related