cbufer added

This commit is contained in:
2022-12-03 20:52:05 +01:00
parent 841e30913e
commit a2401f45cc
2 changed files with 99 additions and 0 deletions

37
cbuffer/circular_buffer.h Normal file
View File

@@ -0,0 +1,37 @@
#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__ */