Bytes queue (FIFO) implemented with a circular buffer.
More...
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().
◆ cb_Init()
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
-
| cb | the cb_CircularBuffer structure to initialize. |
| buffer | pointer to an existing array. |
| bufferSize | length of the circular buffer. The given buffer should have a size greater or equal to this value. |
◆ cb_IsEmpty()
Check if the queue is empty.
- Parameters
-
- Returns
- 1 if there are no bytes stored in the queue, 0 otherwise.
◆ cb_IsFull()
Check if the queue is full.
- Parameters
-
- Returns
- 1 if the queue is full, 0 otherwise.
◆ cb_ItemsCount()
Gets the number of bytes stored in the queue.
- Parameters
-
- Returns
- the number of bytes stored in the queue.
◆ cb_Pull()
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
-
- 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()
Add a item at the back of the queue.
- Parameters
-
- 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.