nRF5 SDK v16.0.0
Data Structures | Typedefs | Functions

A wait-free bounded FIFO of pointers for single producer/single consumer use. More...

Data Structures

struct  nrf_fifo_t
 FIFO data structure. More...
 

Typedefs

typedef uint32_t(* fifo_wait_fn )(void)
 Wait function for blocking enqueue/dequeue. More...
 
typedef void(* fifo_flush_fn )(void *p_data)
 Flush function called on deinit. More...
 

Functions

uint32_t nrf_fifo_init (nrf_fifo_t *p_fifo, uint32_t nmemb, fifo_wait_fn wait_fn, fifo_flush_fn flush_fn)
 Function for initializing the FIFO. More...
 
void nrf_fifo_deinit (nrf_fifo_t *p_fifo)
 Function for deinitializing the FIFO. More...
 
uint32_t nrf_fifo_enq (nrf_fifo_t *p_fifo, void *p_ctx, bool wait)
 Function for enqueuing an element on the FIFO. More...
 
uint32_t nrf_fifo_deq (nrf_fifo_t *p_fifo, void **pp_ctx, bool wait)
 Function for dequeuing an element from the FIFO. More...
 
bool nrf_fifo_empty (nrf_fifo_t *p_fifo)
 Function for checking if the FIFO is empty. More...
 
bool nrf_fifo_full (nrf_fifo_t *p_fifo)
 Function for checking if the FIFO is full. More...
 

Detailed Description

A wait-free bounded FIFO of pointers for single producer/single consumer use.

This FIFO is safe to use in single producer/single consumer patterns. In addition, the following restrictions apply for init/deinit:

a) nrf_fifo_enq() and nrf_fifo_deq() may only be called after nrf_fifo_init() is called.

b) All calls to nrf_fifo_enq() and nrf_fifo_deq() must be finished and no new calls must be made before nrf_fifo_deinit() is called.

These restrictions must be handled by the user of the module, for instance by using a mutex.

Typedef Documentation

typedef void(* fifo_flush_fn)(void *p_data)

Flush function called on deinit.

On deinit, this function will be called with each remaining element in the FIFO as argument. This can be used to ensure that memory is deallocated properly.

Parameters
[in]p_dataPointer to data that is flushed from FIFO.
typedef uint32_t(* fifo_wait_fn)(void)

Wait function for blocking enqueue/dequeue.

Should return NRF_SUCCESS as long as there are no errors while waiting.

Function Documentation

void nrf_fifo_deinit ( nrf_fifo_t p_fifo)

Function for deinitializing the FIFO.

Frees all memory allocated by this FIFO. All elements are removed. If a flush function was specified in nrf_fifo_init(), the function will be called for each remaining element in the FIFO.

Parameters
[in,out]p_fifoThe FIFO to deinitialize.
uint32_t nrf_fifo_deq ( nrf_fifo_t p_fifo,
void **  pp_ctx,
bool  wait 
)

Function for dequeuing an element from the FIFO.

Parameters
[in,out]p_fifoThe FIFO to dequeue elements from.
[out]pp_ctxPointer to where the dequeued element should be stored.
[in]waitIf true, this function will block until the FIFO has elements for dequeuing. Any errors returned by this function will be propagated to the caller.
Return values
NRF_SUCCESSif the element was queued.
NRF_ERROR_NO_MEMif wait was set to false and no space was available.
bool nrf_fifo_empty ( nrf_fifo_t p_fifo)

Function for checking if the FIFO is empty.

Parameters
[in]p_fifoThe FIFO to check.
Returns
true if empty, false if not.
uint32_t nrf_fifo_enq ( nrf_fifo_t p_fifo,
void *  p_ctx,
bool  wait 
)

Function for enqueuing an element on the FIFO.

Parameters
[in,out]p_fifoThe FIFO to enqueue elements on.
[in]p_ctxThe pointer to enqueue.
[in]waitIf true, this function will block until the FIFO has available space. Any errors returned by this function will be propagated to the caller.
Return values
NRF_SUCCESSif the element was queued.
NRF_ERROR_NO_MEMif wait was set to false and no space was available.
bool nrf_fifo_full ( nrf_fifo_t p_fifo)

Function for checking if the FIFO is full.

Parameters
[in]p_fifoThe FIFO to check.
Returns
true if full, false if not.
uint32_t nrf_fifo_init ( nrf_fifo_t p_fifo,
uint32_t  nmemb,
fifo_wait_fn  wait_fn,
fifo_flush_fn  flush_fn 
)

Function for initializing the FIFO.

Parameters
[out]p_fifoThe FIFO to initialize.
[in]nmembThe maximum number of elements in the FIFO.
[in]wait_fnThe wait function to use for blocking enqueue/dequeue. If NULL, the enq/deq functions will never block.
[in]flush_fnThe flush function to call on deinit. If NULL, the flush function will not be called.
Return values
NRF_SUCCESSif fifo was initialized successfully.

Documentation feedback | Developer Zone | Subscribe | Updated