nRF5 SDK v15.0.0
Modules | Data Structures | Functions
FIFO implementation

FIFO implementation. More...

Modules

 Software FIFO implementation configuration
 

Data Structures

struct  app_fifo_t
 A FIFO instance structure. More...
 

Functions

uint32_t app_fifo_init (app_fifo_t *p_fifo, uint8_t *p_buf, uint16_t buf_size)
 Function for initializing the FIFO. More...
 
uint32_t app_fifo_put (app_fifo_t *p_fifo, uint8_t byte)
 Function for adding an element to the FIFO. More...
 
uint32_t app_fifo_get (app_fifo_t *p_fifo, uint8_t *p_byte)
 Function for getting the next element from the FIFO. More...
 
uint32_t app_fifo_peek (app_fifo_t *p_fifo, uint16_t index, uint8_t *p_byte)
 Function for looking at an element in the FIFO, without consuming it. More...
 
uint32_t app_fifo_flush (app_fifo_t *p_fifo)
 Function for flushing the FIFO. More...
 
uint32_t app_fifo_read (app_fifo_t *p_fifo, uint8_t *p_byte_array, uint32_t *p_size)
 Function for reading bytes from the FIFO. More...
 
uint32_t app_fifo_write (app_fifo_t *p_fifo, uint8_t const *p_byte_array, uint32_t *p_size)
 Function for writing bytes to the FIFO. More...
 

Detailed Description

FIFO implementation.

Function Documentation

uint32_t app_fifo_flush ( app_fifo_t p_fifo)

Function for flushing the FIFO.

Parameters
[in]p_fifoPointer to the FIFO.
Return values
NRF_SUCCESSIf the FIFO was flushed successfully.
uint32_t app_fifo_get ( app_fifo_t p_fifo,
uint8_t *  p_byte 
)

Function for getting the next element from the FIFO.

Parameters
[in]p_fifoPointer to the FIFO.
[out]p_byteByte fetched from the FIFO.
Return values
NRF_SUCCESSIf an element was returned.
NRF_ERROR_NOT_FOUNDIf there are no more elements in the queue.
uint32_t app_fifo_init ( app_fifo_t p_fifo,
uint8_t *  p_buf,
uint16_t  buf_size 
)

Function for initializing the FIFO.

Parameters
[out]p_fifoFIFO object.
[in]p_bufFIFO buffer for storing data. The buffer size must be a power of two.
[in]buf_sizeSize of the FIFO buffer provided. This size must be a power of two.
Return values
NRF_SUCCESSIf initialization was successful.
NRF_ERROR_NULLIf a NULL pointer is provided as buffer.
NRF_ERROR_INVALID_LENGTHIf size of buffer provided is not a power of two.
uint32_t app_fifo_peek ( app_fifo_t p_fifo,
uint16_t  index,
uint8_t *  p_byte 
)

Function for looking at an element in the FIFO, without consuming it.

Parameters
[in]p_fifoPointer to the FIFO.
[in]indexWhich element to look at. The lower the index, the earlier it was put.
[out]p_byteByte fetched from the FIFO.
Return values
NRF_SUCCESSIf an element was returned.
NRF_ERROR_NOT_FOUNDIf there are no more elements in the queue, or the index was too large.
uint32_t app_fifo_put ( app_fifo_t p_fifo,
uint8_t  byte 
)

Function for adding an element to the FIFO.

Parameters
[in]p_fifoPointer to the FIFO.
[in]byteData byte to add to the FIFO.
Return values
NRF_SUCCESSIf an element has been successfully added to the FIFO.
NRF_ERROR_NO_MEMIf the FIFO is full.
uint32_t app_fifo_read ( app_fifo_t p_fifo,
uint8_t *  p_byte_array,
uint32_t *  p_size 
)

Function for reading bytes from the FIFO.

This function can also be used to get the number of bytes in the FIFO.

Parameters
[in]p_fifoPointer to the FIFO. Must not be NULL.
[out]p_byte_arrayMemory pointer where the read bytes are fetched from the FIFO. Can be NULL. If NULL, the number of bytes that can be read in the FIFO are returned in the p_size parameter.
[in,out]p_sizeAddress to memory indicating the maximum number of bytes to be read. The provided memory is overwritten with the actual number of bytes read if the procedure was successful. This field must not be NULL. If p_byte_array is set to NULL by the application, this parameter returns the number of bytes in the FIFO.
Return values
NRF_SUCCESSIf the procedure is successful. The actual number of bytes read might be less than the requested maximum, depending on how many elements exist in the FIFO. Even if less bytes are returned, the procedure is considered successful.
NRF_ERROR_NULLIf a NULL parameter was passed for a parameter that must not be NULL.
NRF_ERROR_NOT_FOUNDIf the FIFO is empty.
uint32_t app_fifo_write ( app_fifo_t p_fifo,
uint8_t const *  p_byte_array,
uint32_t *  p_size 
)

Function for writing bytes to the FIFO.

This function can also be used to get the available size on the FIFO.

Parameters
[in]p_fifoPointer to the FIFO. Must not be NULL.
[in]p_byte_arrayMemory pointer containing the bytes to be written to the FIFO. Can be NULL. If NULL, this function returns the number of bytes that can be written to the FIFO.
[in,out]p_sizeAddress to memory indicating the maximum number of bytes to be written. The provided memory is overwritten with the number of bytes that were actually written if the procedure is successful. This field must not be NULL. If p_byte_array is set to NULL by the application, this parameter returns the number of bytes available in the FIFO.
Return values
NRF_SUCCESSIf the procedure is successful. The actual number of bytes written might be less than the requested maximum, depending on how much room there is in the FIFO. Even if less bytes are written, the procedure is considered successful. If the write was partial, the application should use subsequent calls to attempt writing the data again.
NRF_ERROR_NULLIf a NULL parameter was passed for a parameter that must not be NULL.
NRF_ERROR_NO_MEMIf the FIFO is full.

Documentation feedback | Developer Zone | Subscribe | Updated