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

nrf queue NRF_ERROR_NOT_FOUND with NRF_QUEUE_MODE_OVERFLOW declared

Hi,

I am using nrf_queue to store data in queue which is inserted with time based interrupt at several milliseconds. Also same data from queue is fetched at bulk.

I am using NRF_QUEUE_MODE_OVERFLOW so that previous data is erased if data isn't fetched and queue is full.

The problem is I am getting NRF_ERROR_NOT_FOUND which occurs when element_count > queue utilization as in function nrf_queue_read.

Why is that problem occuring and how to prevent it. It is mentioned that "If NRF_QUEUE_MODE_NO_OVERFLOW mode is selected and there is not enough space, NRF_ERROR_NO_MEM will be returned." but since I have NRF_QUEUE_MODE_OVERFLOW mode, I shouldn't get this error.

In queue buffer docs it is mentioned "The queue library provides interrupt secure implementation of the circular buffer to store predefined objects." so I don't have to worry about it.

Below is the declaration and usage of my queue.

NRF_QUEUE_DEF(uint16_t, m_queue, 36, NRF_QUEUE_MODE_OVERFLOW);
NRF_QUEUE_INTERFACE_DEC(uint16_t, my_queue);
NRF_QUEUE_INTERFACE_DEF(uint16_t, my_queue, &m_queue)

err_code = my_queue_write(data_in, len_out);
APP_ERROR_CHECK(err_code);

if (!nrf_queue_is_empty())
{
    err_code = my_queue_read(data_out, len_out);
    APP_ERROR_CHECK(err_code);
}

SDK 15.2

  • I am sorry for the delay, I have been sick lately, which is why I haven't been able to answer you. I will look into your issue the next couple of days.

    Best regards,

    Simon

  • You should not get NRF_QUEUE_MODE_OVERFLOW  when trying to read from the queue, overflow happens when you try to push/write/add to a queue that is full, not when you are trying to read from (pop) a queue. If you look at the explanatory text above the function nrf_queue_read() inside <..>\sdk15\components\libraries\queue\nrf_queue.h, you can see that the error NRF_ERROR_NOT_FOUND means "There is not enough elements in the queue". In order to avoid this error you have to either decrease the size of element_count (third argument of nrf_queue_read(..)) or add more elements to the queue through nrf_queue_write(..)nrf_queue_in(..) or nrf_queue_push(..).

    /**@brief Function for reading elements from the queue.
     *
     * @param[in]   p_queue             Pointer to the nrf_queue_t instance.
     * @param[out]  p_data              Pointer to the buffer where elements will be copied.
     * @param[in]   element_count       Number of elements to read.
     *
     * @return      NRF_SUCCESS         If an element was returned.
     * @return      NRF_ERROR_NOT_FOUND There is not enough elements in the queue. <--- This is the reason it fails
     */
    ret_code_t nrf_queue_read(nrf_queue_t const * p_queue,
                              void              * p_data,
                              size_t              element_count);

    Best regards,

    Simon

Related