00001 #ifndef BUFFER_H 00002 #define BUFFER_H 00003 00004 #include <stdlib.h> 00005 #include <math.h> 00006 #include <oulib.h> 00007 00012 typedef struct { 00014 char *buffer; 00016 uint16_t size; 00018 volatile int16_t front; 00020 volatile int16_t back; 00021 } BUFFER; 00022 00023 00024 extern BUFFER* buffer_create(uint16_t size); 00025 extern void buffer_add(BUFFER* buf, char c); 00026 extern char buffer_remove(BUFFER* buf); 00027 extern int8_t buffer_state(BUFFER* buf); 00028 extern void buffer_reset(BUFFER* buf, uint16_t front, uint16_t back); 00029 extern uint16_t buffer_nbytes(BUFFER* buf); 00030 extern void buffer_flush(BUFFER* buf); 00031 00045 #define BUFFER_FULL(buf) (buffer_nbytes(buf) == ((buf)->size - 1)) 00046 00060 #define BUFFER_EMPTY(buf) ((buf)->front == (buf)->back) 00061 00062 00063 #endif