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

Handling FDS_ERR_NO_SPACE_IN_QUEUES in loop

I thought I would be able to do the following, but when FDS_ERR_NO_SPACE_IN_QUEUES occurs m_fds_no_space_in_queue never becomes false. Is there any way I can wait for space in the FDS queue or do I have to handle it asynchronously?

static bool volatile m_fds_no_space_in_queue = false;

static void fds_evt_handler(fds_evt_t const * p_evt)
{
 #if FDS_EVENT_LOGGING
    NRF_LOG_INFO("Event: %s received (%s)",
                  fds_evt_str[p_evt->id],
                  fds_err_str[p_evt->result]);
#endif

    m_fds_no_space_in_queue = false;
    
    // other event handling removed
}

void write_something() {
    ret_code_t err_code;
    // some code ommitted here
    err_code = FDS_SUCCESS + 1;
    while(err_code != FDS_SUCCESS) {
        NRF_LOG_DEBUG("Creating record");
        err_code = fds_record_write(&m_blister_fds_descriptors[cell], &new_record);
        switch(err_code) {
        case FDS_SUCCESS:
            NRF_LOG_INFO("Cell state storing...");
            break;
        case FDS_ERR_NOT_INITIALIZED:
            APP_ERROR_CHECK(NRF_ERROR_MODULE_NOT_INITIALIZED);
            err_code = FDS_SUCCESS;
            break;
        case FDS_ERR_NULL_ARG:
            // shouldn't happen since we set it above
            err_code = FDS_SUCCESS;
            break;
        case FDS_ERR_INVALID_ARG:
            // shouldn't happen since file id is fixed and record key is within a fixed range
            err_code = FDS_SUCCESS;
            break;
        case FDS_ERR_UNALIGNED_ADDR:
            // shouldn't happen since we compute length to be aligned to 4 byte words
            err_code = FDS_SUCCESS;
            break;
        case FDS_ERR_RECORD_TOO_LARGE:
            // shouldn't happen since record is fixed size
            err_code = FDS_SUCCESS;
            break;
        case FDS_ERR_NO_SPACE_IN_QUEUES:
            // probably will happen. Wait for an operation to complete and try again
            m_fds_no_space_in_queue = true;
            while(m_fds_no_space_in_queue) {
                        nrf_pwr_mgmt_run();
                    }
            break;
        case FDS_ERR_NO_SPACE_IN_FLASH:
            // will happen after some time
            while(1) {
                err_code = fds_gc();
                if(err_code == FDS_ERR_NO_SPACE_IN_QUEUES) {
                    m_fds_no_space_in_queue = true;
                    while(m_fds_no_space_in_queue) {
                        nrf_pwr_mgmt_run();
                    }
                } else {
                    m_fds_gc_in_progress = true;
                    while(m_fds_gc_in_progress) {
                        nrf_pwr_mgmt_run();
                    }
                    // retry write now
                    err_code = FDS_SUCCESS + 1;
                    break;
                }
            }
            break;
        default:
            // unknown error
            err_code = FDS_SUCCESS;
            break;
        }
    }

Parents
  • Hi,

    Your m_fds_no_space_in_queue should be set to false whenever there is a FDS event with the code snippets you have pasted, provided you have registered your FDS event handler with a call do fds_register(). Have you?

    The way you wait for space in the queue should work, but you should probably consider increasing the queue size if you often experience FDS_ERR_NO_SPACE_IN_QUEUES errors.

Reply
  • Hi,

    Your m_fds_no_space_in_queue should be set to false whenever there is a FDS event with the code snippets you have pasted, provided you have registered your FDS event handler with a call do fds_register(). Have you?

    The way you wait for space in the queue should work, but you should probably consider increasing the queue size if you often experience FDS_ERR_NO_SPACE_IN_QUEUES errors.

Children
No Data
Related