Circular Buffer C implementation, must create a buffer structure instance in your main and then dinamically allocate memory for the buffer array.
Diff: circularBuff.h
- Revision:
- 0:f6f6750994d2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/circularBuff.h Fri May 17 13:06:31 2019 +0000 @@ -0,0 +1,19 @@ +#include "mbed.h" + +#ifndef CIRCULARBUFF_H +#define CIRCULARBUF_H + +typedef struct { + uint8_t *buffer; + size_t head; + size_t tail; + size_t size; //of the buffer +} circ_buf_t; + +int circ_buf_rst(circ_buf_t * cbuf); +int circ_buf_put(circ_buf_t * cbuf, uint8_t data); +int circ_buf_get(circ_buf_t * cbuf, uint8_t * data); +bool circ_buf_empty(circ_buf_t cbuf); +bool circ_buf_full(circ_buf_t cbuf); + +#endif \ No newline at end of file