nRF5 SDK v17.1.0
Modules | Data Structures | Macros | Enumerations | Functions

Functions that handle the queue instances. More...

Modules

 Queue module configuration
 

Data Structures

struct  nrf_queue_cb_t
 Queue control block. More...
 
struct  nrf_queue_t
 Instance of the queue. More...
 

Macros

#define NRF_QUEUE_LOG_NAME   queue
 Name of the module used for logger messaging.
 
#define __NRF_QUEUE_ASSIGN_POOL_NAME(_name)
 
#define NRF_QUEUE_DEF(_type, _name, _size, _mode)
 Create a queue instance. More...
 
#define NRF_QUEUE_ARRAY_DEF(_type, _name, _size, _mode, _num)
 Create multiple queue instances. More...
 
#define NRF_QUEUE_ARRAY_INSTANCE_ELEMS_DEC(_num, _type, _name, _size, _mode)
 Helping macro used to declare elements for nrf_queue_t instance. Used in NRF_QUEUE_ARRAY_DEF. More...
 
#define NRF_QUEUE_ARRAY_INSTANCE_INIT(_num, _type, _name, _size, _mode)
 Helping macro used to initialize nrf_queue_t instance in an array fashion. Used in NRF_QUEUE_ARRAY_DEF. More...
 
#define NRF_QUEUE_INTERFACE_DEC(_type, _name)
 Declare a queue interface. More...
 
#define NRF_QUEUE_INTERFACE_DEF(_type, _name, _p_queue)
 Define a queue interface. More...
 
#define nrf_queue_pop(_p_queue, _p_element)   nrf_queue_generic_pop((_p_queue), (_p_element), false)
 Pop element from the front of the queue. More...
 
#define nrf_queue_peek(_p_queue, _p_element)   nrf_queue_generic_pop((_p_queue), (_p_element), true)
 Peek element from the front of the queue. More...
 

Enumerations

enum  nrf_queue_mode_t {
  NRF_QUEUE_MODE_OVERFLOW,
  NRF_QUEUE_MODE_NO_OVERFLOW
}
 Supported queue modes. More...
 

Functions

ret_code_t nrf_queue_push (nrf_queue_t const *p_queue, void const *p_element)
 Function for pushing an element to the end of queue. More...
 
ret_code_t nrf_queue_generic_pop (nrf_queue_t const *p_queue, void *p_element, bool just_peek)
 Generic pop implementation. More...
 
ret_code_t nrf_queue_write (nrf_queue_t const *p_queue, void const *p_data, size_t element_count)
 Function for writing elements to the queue. More...
 
size_t nrf_queue_in (nrf_queue_t const *p_queue, void const *p_data, size_t element_count)
 Function for writing a portion of elements to the queue. More...
 
ret_code_t nrf_queue_read (nrf_queue_t const *p_queue, void *p_data, size_t element_count)
 Function for reading elements from the queue. More...
 
size_t nrf_queue_out (nrf_queue_t const *p_queue, void *p_data, size_t element_count)
 Function for reading a portion of elements from the queue. More...
 
bool nrf_queue_is_full (nrf_queue_t const *p_queue)
 Function for checking if the queue is full. More...
 
bool nrf_queue_is_empty (nrf_queue_t const *p_queue)
 Function for checking if the queue is empty. More...
 
size_t nrf_queue_utilization_get (nrf_queue_t const *p_queue)
 Function for getting the current queue utilization. More...
 
size_t nrf_queue_available_get (nrf_queue_t const *p_queue)
 Function for getting the size of available space. More...
 
size_t nrf_queue_max_utilization_get (nrf_queue_t const *p_queue)
 Function for getting the maximal queue utilization. More...
 
void nrf_queue_max_utilization_reset (nrf_queue_t const *p_queue)
 Function for resetting the maximal queue utilization. More...
 
void nrf_queue_reset (nrf_queue_t const *p_queue)
 Function for resetting the queue state. More...
 

Detailed Description

Functions that handle the queue instances.

Macro Definition Documentation

#define NRF_QUEUE_ARRAY_DEF (   _type,
  _name,
  _size,
  _mode,
  _num 
)
Value:
MACRO_REPEAT_FOR(_num, NRF_QUEUE_ARRAY_INSTANCE_ELEMS_DEC, _type, _name, _size, _mode) \
static const nrf_queue_t _name[] = \
{ \
MACRO_REPEAT_FOR(_num, NRF_QUEUE_ARRAY_INSTANCE_INIT, _type, _name, _size, _mode) \
}; \
STATIC_ASSERT(ARRAY_SIZE(_name) == _num)

Create multiple queue instances.

Note
This macro reserves memory for array of queue instances.
Parameters
[in]_typeType which is stored.
[in]_nameName of the array with queue instances.
[in]_sizeSize of single queue instance.
[in]_modeMode of single queue instance.
[in]_numNumber of queue instances within array.
#define NRF_QUEUE_ARRAY_INSTANCE_ELEMS_DEC (   _num,
  _type,
  _name,
  _size,
  _mode 
)
Value:
static _type CONCAT_3(_name, _num, _nrf_queue_buffer[(_size) + 1]); \
static nrf_queue_cb_t CONCAT_3(_name, _num, _nrf_queue_cb);

Helping macro used to declare elements for nrf_queue_t instance. Used in NRF_QUEUE_ARRAY_DEF.

#define NRF_QUEUE_ARRAY_INSTANCE_INIT (   _num,
  _type,
  _name,
  _size,
  _mode 
)
Value:
{ \
.p_cb = &CONCAT_3(_name, _num, _nrf_queue_cb), \
.p_buffer = CONCAT_3(_name, _num, _nrf_queue_buffer), \
.size = (_size), \
.element_size = sizeof(_type), \
.mode = _mode, \
},

Helping macro used to initialize nrf_queue_t instance in an array fashion. Used in NRF_QUEUE_ARRAY_DEF.

#define NRF_QUEUE_DEF (   _type,
  _name,
  _size,
  _mode 
)
Value:
static _type CONCAT_2(_name, _nrf_queue_buffer[(_size) + 1]); \
static nrf_queue_cb_t CONCAT_2(_name, _nrf_queue_cb); \
NRF_LOG_INSTANCE_REGISTER(NRF_QUEUE_LOG_NAME, _name, \
NRF_QUEUE_CONFIG_LOG_LEVEL : NRF_LOG_SEVERITY_NONE); \
NRF_SECTION_ITEM_REGISTER(nrf_queue, const nrf_queue_t _name) = \
{ \
.p_cb = &CONCAT_2(_name, _nrf_queue_cb), \
.p_buffer = CONCAT_2(_name,_nrf_queue_buffer), \
.size = (_size), \
.element_size = sizeof(_type), \
.mode = _mode, \
__NRF_QUEUE_ASSIGN_POOL_NAME(_name) \
NRF_LOG_INSTANCE_PTR_INIT(p_log, NRF_QUEUE_LOG_NAME, _name) \
}

Create a queue instance.

Note
This macro reserves memory for the given queue instance.
Parameters
[in]_typeType which is stored.
[in]_nameName of the queue.
[in]_sizeSize of the queue.
[in]_modeMode of the queue.
#define NRF_QUEUE_INTERFACE_DEC (   _type,
  _name 
)
Value:
ret_code_t _name##_push(_type const * p_element); \
ret_code_t _name##_pop(_type * p_element); \
ret_code_t _name##_peek(_type * p_element); \
ret_code_t _name##_write(_type const * p_data, \
size_t element_count); \
ret_code_t _name##_read(_type * p_data, \
size_t element_count); \
size_t _name##_out(_type * p_data, \
size_t element_count); \
size_t _name##_in(_type const * p_data, \
size_t element_count); \
bool _name##_is_full(void); \
bool _name##_is_empty(void); \
size_t _name##_utilization_get(void); \
size_t _name##_available_get(void); \
size_t _name##_max_utilization_get(void); \
void _name##_reset(void)

Declare a queue interface.

Parameters
[in]_typeType which is stored.
[in]_nameName of the queue.
#define NRF_QUEUE_INTERFACE_DEF (   _type,
  _name,
  _p_queue 
)

Define a queue interface.

Parameters
[in]_typeType which is stored.
[in]_nameName of the queue.
[in]_p_queueQueue instance.
#define nrf_queue_peek (   _p_queue,
  _p_element 
)    nrf_queue_generic_pop((_p_queue), (_p_element), true)

Peek element from the front of the queue.

Parameters
[in]_p_queuePointer to the nrf_queue_t instance.
[out]_p_elementPointer where the element will be copied.
Returns
NRF_SUCCESS If an element was returned.
NRF_ERROR_NOT_FOUND If there are no more elements in the queue.
#define nrf_queue_pop (   _p_queue,
  _p_element 
)    nrf_queue_generic_pop((_p_queue), (_p_element), false)

Pop element from the front of the queue.

Parameters
[in]_p_queuePointer to the nrf_queue_t instance.
[out]_p_elementPointer where the element will be copied.
Returns
NRF_SUCCESS If an element was returned.
NRF_ERROR_NOT_FOUND If there are no more elements in the queue.

Enumeration Type Documentation

Supported queue modes.

Enumerator
NRF_QUEUE_MODE_OVERFLOW 

If the queue is full, new element will overwrite the oldest.

NRF_QUEUE_MODE_NO_OVERFLOW 

If the queue is full, new element will not be accepted.

Function Documentation

size_t nrf_queue_available_get ( nrf_queue_t const *  p_queue)

Function for getting the size of available space.

Parameters
[in]p_queuePointer to the queue instance.
Returns
Size of available space.
ret_code_t nrf_queue_generic_pop ( nrf_queue_t const *  p_queue,
void *  p_element,
bool  just_peek 
)

Generic pop implementation.

Parameters
[in]p_queuePointer to the nrf_queue_t instance.
[out]p_elementPointer where the element will be copied.
[out]just_peekIf true, the returned element will not be removed from queue.
Returns
NRF_SUCCESS If an element was returned.
NRF_ERROR_NOT_FOUND If there are no more elements in the queue.
size_t nrf_queue_in ( nrf_queue_t const *  p_queue,
void const *  p_data,
size_t  element_count 
)

Function for writing a portion of elements to the queue.

Parameters
[in]p_queuePointer to the nrf_queue_t instance.
[in]p_dataPointer to the buffer with elements to write.
[in]element_countNumber of elements to write.
Returns
The number of added elements.
bool nrf_queue_is_empty ( nrf_queue_t const *  p_queue)

Function for checking if the queue is empty.

Parameters
[in]p_queuePointer to the queue instance.
Returns
True if the queue is empty.
bool nrf_queue_is_full ( nrf_queue_t const *  p_queue)

Function for checking if the queue is full.

Parameters
[in]p_queuePointer to the queue instance.
Returns
True if the queue is full.
size_t nrf_queue_max_utilization_get ( nrf_queue_t const *  p_queue)

Function for getting the maximal queue utilization.

Parameters
[in]p_queuePointer to the queue instance.
Returns
Maximal queue utilization.
void nrf_queue_max_utilization_reset ( nrf_queue_t const *  p_queue)

Function for resetting the maximal queue utilization.

Parameters
[in]p_queuePointer to the queue instance.
size_t nrf_queue_out ( nrf_queue_t const *  p_queue,
void *  p_data,
size_t  element_count 
)

Function for reading a portion of elements from the queue.

Parameters
[in]p_queuePointer to the nrf_queue_t instance.
[out]p_dataPointer to the buffer where elements will be copied.
[in]element_countNumber of elements to read.
Returns
The number of read elements.
ret_code_t nrf_queue_push ( nrf_queue_t const *  p_queue,
void const *  p_element 
)

Function for pushing an element to the end of queue.

Parameters
[in]p_queuePointer to the nrf_queue_t instance.
[in]p_elementPointer to the element that will be stored in the queue.
Returns
NRF_SUCCESS If an element has been successfully added.
NRF_ERROR_NO_MEM If the queue is full (only in NRF_QUEUE_MODE_NO_OVERFLOW).
ret_code_t nrf_queue_read ( nrf_queue_t const *  p_queue,
void *  p_data,
size_t  element_count 
)

Function for reading elements from the queue.

Parameters
[in]p_queuePointer to the nrf_queue_t instance.
[out]p_dataPointer to the buffer where elements will be copied.
[in]element_countNumber of elements to read.
Returns
NRF_SUCCESS If an element was returned.
NRF_ERROR_NOT_FOUND There is not enough elements in the queue.
void nrf_queue_reset ( nrf_queue_t const *  p_queue)

Function for resetting the queue state.

Parameters
[in]p_queuePointer to the queue instance.
size_t nrf_queue_utilization_get ( nrf_queue_t const *  p_queue)

Function for getting the current queue utilization.

Parameters
[in]p_queuePointer to the queue instance.
Returns
Current queue utilization.
ret_code_t nrf_queue_write ( nrf_queue_t const *  p_queue,
void const *  p_data,
size_t  element_count 
)

Function for writing elements to the queue.

Parameters
[in]p_queuePointer to the nrf_queue_t instance.
[in]p_dataPointer to the buffer with elements to write.
[in]element_countNumber of elements to write.
Returns
NRF_SUCCESS If an element was written.
NRF_ERROR_NO_MEM There is not enough space in the queue. No element was written.

Documentation feedback | Developer Zone | Subscribe | Updated