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

what's the safest way to wait for pstorage_store

when I call pstorage_store so store a block of data, sometimes I call just after pstorage_store: the following code

do {
	pstorage_access_status_get(&count);
} while (count);

sometimes I want for a flag while(!flashWriteTerminated); which is set to false on flash callback handler

    static void flash_callback_handler(pstorage_handle_t * p_handle,
        uint8_t             op_code,
        uint32_t            result,
        uint8_t           * p_data,
        uint32_t            data_len)
    {
        switch (op_code) {
        case PSTORAGE_STORE_OP_CODE:
            if (result == NRF_SUCCESS) {
                flashWriteTerminated = true;
            }
            else {
                APP_ERROR_CHECK(result);    // Store operation failed.
            }
            break;
        case PSTORAGE_LOAD_OP_CODE:
            if (result == NRF_SUCCESS) {
    					flashWriteTerminated = true;
            }
            else {
                APP_ERROR_CHECK(result);    // Store operation failed.
            }
            break;
        case PSTORAGE_CLEAR_OP_CODE:
            if (result == NRF_SUCCESS) {
    					flashWriteTerminated = true;
            }
            else {
                APP_ERROR_CHECK(result);    // Store operation failed.
            }
            break;
        case PSTORAGE_UPDATE_OP_CODE:
            if (result == NRF_SUCCESS) {
flashWriteTerminated = true;
            }
            else {
                APP_ERROR_CHECK(result);    // Store operation failed.
            }
            break;
        default:
            break;
        }
    }

what's the effective way to wait for pstorage_store load clear functions to ensure that flash data is successfuly handled

Parents
  • store,update and clear operations are enqueued within the pstorage module, so you don't have to wait for a previous operation to complete before issuing the next one. However, the read operation is not added to the queue, so you need to wait if there is an ongoing flash operation on the same page to complete in order to be sure that the data is valid.

    One way to check if it's safe to read a block is to check that there are no pending flash operations by using the pstorage_access_status_get() function.

Reply
  • store,update and clear operations are enqueued within the pstorage module, so you don't have to wait for a previous operation to complete before issuing the next one. However, the read operation is not added to the queue, so you need to wait if there is an ongoing flash operation on the same page to complete in order to be sure that the data is valid.

    One way to check if it's safe to read a block is to check that there are no pending flash operations by using the pstorage_access_status_get() function.

Children
Related