HRI board firmware  v2.1
Microcontroller firmware of the board used during the HRI labs.
Data Structures | Functions
Lib / Circular buffer

Bytes queue (FIFO) implemented with a circular buffer. More...

Data Structures

struct  cb_CircularBuffer
 Circular buffer structure. More...
 

Functions

void cb_Init (cb_CircularBuffer *cb, uint8_t *buffer, uint16_t bufferSize)
 Initializes a cb_CircularBuffer structure. Initializes a cb_CircularBuffer structure with the given buffer. The buffer has to be provided by the user, to avoid dynamic memory allocation. More...
 
uint16_t cb_ItemsCount (cb_CircularBuffer *cb)
 Gets the number of bytes stored in the queue. More...
 
bool cb_IsEmpty (cb_CircularBuffer *cb)
 Check if the queue is empty. More...
 
bool cb_IsFull (cb_CircularBuffer *cb)
 Check if the queue is full. More...
 
void cb_Push (cb_CircularBuffer *cb, uint8_t newElem)
 Add a item at the back of the queue. More...
 
uint8_t cb_Pull (cb_CircularBuffer *cb)
 Extract the item at the front of the queue. Returns the value of the item at the front of the queue, and remove this item from the queue. More...
 

Detailed Description

Bytes queue (FIFO) implemented with a circular buffer.

This bytes container works as a queue, which means "first in, first out". Create a cb_CircularBuffer structure, and initialize it with cb_Init(). Then, add bytes using cb_Push(), and extract them with cb_Pull().

Function Documentation

◆ cb_Init()

void cb_Init ( cb_CircularBuffer cb,
uint8_t *  buffer,
uint16_t  bufferSize 
)

Initializes a cb_CircularBuffer structure. Initializes a cb_CircularBuffer structure with the given buffer. The buffer has to be provided by the user, to avoid dynamic memory allocation.

Parameters
cbthe cb_CircularBuffer structure to initialize.
bufferpointer to an existing array.
bufferSizelength of the circular buffer. The given buffer should have a size greater or equal to this value.

◆ cb_IsEmpty()

bool cb_IsEmpty ( cb_CircularBuffer cb)

Check if the queue is empty.

Parameters
cbthe cb_CircularBuffer to check.
Returns
1 if there are no bytes stored in the queue, 0 otherwise.

◆ cb_IsFull()

bool cb_IsFull ( cb_CircularBuffer cb)

Check if the queue is full.

Parameters
cbthe cb_CircularBuffer to check.
Returns
1 if the queue is full, 0 otherwise.

◆ cb_ItemsCount()

uint16_t cb_ItemsCount ( cb_CircularBuffer cb)

Gets the number of bytes stored in the queue.

Parameters
cbthe cb_CircularBuffer to check.
Returns
the number of bytes stored in the queue.

◆ cb_Pull()

uint8_t cb_Pull ( cb_CircularBuffer cb)

Extract the item at the front of the queue. Returns the value of the item at the front of the queue, and remove this item from the queue.

Parameters
cbthe cb_CircularBuffer to affect.
Returns
the value of the byte that has been extracted from the queue.
Warning
If the queue is empty and CPU_TRAPS_ENABLED is 0, this function returns 0. If CPU_TRAPS_ENABLED is 1, this function will block forever the program execution, so the problem can be found with the debugger.

◆ cb_Push()

void cb_Push ( cb_CircularBuffer cb,
uint8_t  newElem 
)

Add a item at the back of the queue.

Parameters
cbthe cb_CircularBuffer to affect.
newElemthe byte to add to the back of the queue.
Warning
If the queue is already full, this function does nothing if CPU_TRAPS_ENABLED is 0. If CPU_TRAPS_ENABLED is 1, this function will block forever the program execution, so the problem can be found with the debugger.