#ifndef BUFFER_H #define BUFFER_H #include #include #include /** Buffer structure. Implementation of a circular byte buffer. */ typedef struct { /** Pointer to the storage space. */ char *buffer; /** Total number of bytes available for storage. */ uint16_t size; /** Current index of the next byte to be removed. */ volatile int16_t front; /** Current index of the next location to receive a byte. */ volatile int16_t back; } BUFFER; extern BUFFER* buffer_create(uint16_t size); extern void buffer_add(BUFFER* buf, char c); extern char buffer_remove(BUFFER* buf); extern int8_t buffer_state(BUFFER* buf); extern void buffer_reset(BUFFER* buf, uint16_t front, uint16_t back); extern uint16_t buffer_nbytes(BUFFER* buf); extern void buffer_flush(BUFFER* buf); /** Indicate whether the buffer is full

@param buf A pointer to an existing and initialized BUFFER structure. @return 1 if the buffer is full (with size-1 bytes), or
0 if the buffer is not full @author Andrew H. Fagg (fagg@cs.ou.edu) \ingroup buffer */ #define BUFFER_FULL(buf) (buffer_nbytes(buf) == ((buf)->size - 1)) /** Indicate whether the buffer is empty

@param buf A pointer to an existing and initialized BUFFER structure. @return 1 if the buffer is empty (with 0 bytes), or
0 if the buffer is not empty @author Andrew H. Fagg (fagg@cs.ou.edu) \ingroup buffer */ #define BUFFER_EMPTY(buf) ((buf)->front == (buf)->back) #endif