Files
imbal_opto/Core/Src/CBuffer/circular_buffer.h
2022-12-04 11:17:16 +01:00

37 lines
971 B
C

#ifndef __CIRCULAT_BUFFER__
#define __CIRCULAT_BUFFER__
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdio.h>
typedef enum
{
CB_OK = 0x00,
CB_ERROR = -0x01,
CB_EMPTY = -0x02,
CB_FULL = -0x03
} CB_StatusTypeDef;
typedef struct
{
void *buffer; // data buffer
void *buffer_end; // end of data buffer
uint16_t capacity; // maximum number of items in the buffer
uint16_t count; // number of items in the buffer
uint8_t item_size; // size of each item in the buffer
void *head; // pointer to head
void *tail; // pointer to tail
} CB_TypeDef;
CB_StatusTypeDef cb_init(CB_TypeDef *cb, void *buffer, uint16_t capacity, uint8_t item_size);
CB_StatusTypeDef cb_push_back(CB_TypeDef *cb, const void *item);
CB_StatusTypeDef cb_pop_front(CB_TypeDef *cb, void *item);
#ifdef __cplusplus
}
#endif
#endif /* __CIRCULAT_BUFFER__ */