/* Function to determine if a flash access in in progress. If it is the case, we can not start advertising until it is finished. attempted restart in ble_advertising_on_sys_evt.  */
static bool flash_access_in_progress()
/* Function to determine if a flash access in in progress. If it is the case, we can not start advertising until it is finished. attempted restart in ble_advertising_on_sys_evt.  */
static bool flash_access_in_progress()
{
    uint32_t err_code;
    uint32_t count = 0;
    err_code = pstorage_access_status_get(&count);
    if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_SUCCESS))
    {
        ADV_LOG("[ADV]: pstorage_access_status_get returned %d.\r\n", err_code);
        return true;
    }
    if (err_code == NRF_ERROR_INVALID_STATE)
    {
        err_code = fs_queued_op_count_get(&count);
        if (err_code != FS_SUCCESS)
        {
            return false;
        }
        ADV_LOG("[ADV]: fs_queued_op_count_get gives count %d.\r\n", count);
    }
    if(count != 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}