Page MenuHomec4science

circular_buffer.h
No OneTemporary

File Metadata

Created
Wed, May 1, 18:16

circular_buffer.h

#ifndef __CIRCULAR_BUFFER_H
#define __CIRCULAR_BUFFER_H
#include "../main.h"
/** @defgroup CircularBuffer Circular buffer
* @brief 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().
*
* @ingroup Lib
* @addtogroup CircularBuffer
* @{
*/
/**
* @brief Circular buffer structure.
*/
typedef struct
{
uint8_t *buffer; ///< Pointer to the byte buffer.
uint16_t bufferSize; ///< Size of buffer.
volatile uint16_t readIndex, ///< Index of the element at the front of the queue.
writeIndex; ///< Index of the next free location at the end of the queue.
} cb_CircularBuffer;
void cb_Init(cb_CircularBuffer* cb, uint8_t *buffer, uint16_t bufferSize);
uint16_t cb_ItemsCount(cb_CircularBuffer* cb);
bool cb_IsEmpty(cb_CircularBuffer* cb);
bool cb_IsFull(cb_CircularBuffer* cb);
void cb_Push(cb_CircularBuffer* cb, uint8_t newElem);
uint8_t cb_Pull(cb_CircularBuffer* cb);
/**
* @}
*/
#endif

Event Timeline