cbufer added
This commit is contained in:
37
cbuffer/circular_buffer.h
Normal file
37
cbuffer/circular_buffer.h
Normal 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__ */
|
||||
Reference in New Issue
Block a user