41 lines
1.3 KiB
C
41 lines
1.3 KiB
C
/** \file
|
|
* \brief This file contains definitions for a circular buffer.
|
|
*
|
|
*/
|
|
|
|
#ifndef UTIL_CIRCULARBUFFER_H
|
|
#define UTIL_CIRCULARBUFFER_H
|
|
|
|
/* Definitions */
|
|
|
|
typedef enum
|
|
{
|
|
//! The result could not be determined.
|
|
UTIL_CIRCULARBUFFERRESULT_UNKNOWN = 0,
|
|
//! The requested action completed successfully.
|
|
UTIL_CIRCULARBUFFERRESULT_SUCCESS,
|
|
//! There is no more room in the buffer.
|
|
UTIL_CIRCULARBUFFERRESULT_ERROR_OVERFLOW,
|
|
//! There is no data left in the buffer.
|
|
UTIL_CIRCULARBUFFERRESULT_ERROR_UNDERFLOW
|
|
} UTIL_CircularBufferResult_T;
|
|
|
|
//! Circular buffer data structure.
|
|
typedef struct
|
|
{
|
|
uint8_t * buffer;
|
|
uint16_t size;
|
|
volatile uint16_t head;
|
|
volatile uint16_t tail;
|
|
volatile uint16_t count;
|
|
} UTIL_CircularBuffer_T;
|
|
|
|
/* Function Declarations */
|
|
|
|
void UTIL_InitCircularBuffer(UTIL_CircularBuffer_T * const this, uint8_t * buffer, uint16_t size);
|
|
UTIL_CircularBufferResult_T UTIL_PushToCircularBuffer(UTIL_CircularBuffer_T * const this, uint8_t value);
|
|
UTIL_CircularBufferResult_T UTIL_PopFromCircularBuffer(UTIL_CircularBuffer_T * const this, uint8_t * const value);
|
|
bool UTIL_IsCircularBufferEmpty(UTIL_CircularBuffer_T * const this);
|
|
bool UTIL_IsCircularBufferFull(UTIL_CircularBuffer_T * const this);
|
|
|
|
#endif // UTIL_CIRCULARBUFFER_H
|