Circular Buffer C implementation, must create a buffer structure instance in your main and then dinamically allocate memory for the buffer array.
circularBuff.h@0:f6f6750994d2, 2019-05-17 (annotated)
- Committer:
- ivaariasga
- Date:
- Fri May 17 13:06:31 2019 +0000
- Revision:
- 0:f6f6750994d2
Circular Buffer C implementation, must create an instance of the buffer structure and then allocate memory dinamically for the buffer.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ivaariasga | 0:f6f6750994d2 | 1 | #include "mbed.h" |
ivaariasga | 0:f6f6750994d2 | 2 | |
ivaariasga | 0:f6f6750994d2 | 3 | #ifndef CIRCULARBUFF_H |
ivaariasga | 0:f6f6750994d2 | 4 | #define CIRCULARBUF_H |
ivaariasga | 0:f6f6750994d2 | 5 | |
ivaariasga | 0:f6f6750994d2 | 6 | typedef struct { |
ivaariasga | 0:f6f6750994d2 | 7 | uint8_t *buffer; |
ivaariasga | 0:f6f6750994d2 | 8 | size_t head; |
ivaariasga | 0:f6f6750994d2 | 9 | size_t tail; |
ivaariasga | 0:f6f6750994d2 | 10 | size_t size; //of the buffer |
ivaariasga | 0:f6f6750994d2 | 11 | } circ_buf_t; |
ivaariasga | 0:f6f6750994d2 | 12 | |
ivaariasga | 0:f6f6750994d2 | 13 | int circ_buf_rst(circ_buf_t * cbuf); |
ivaariasga | 0:f6f6750994d2 | 14 | int circ_buf_put(circ_buf_t * cbuf, uint8_t data); |
ivaariasga | 0:f6f6750994d2 | 15 | int circ_buf_get(circ_buf_t * cbuf, uint8_t * data); |
ivaariasga | 0:f6f6750994d2 | 16 | bool circ_buf_empty(circ_buf_t cbuf); |
ivaariasga | 0:f6f6750994d2 | 17 | bool circ_buf_full(circ_buf_t cbuf); |
ivaariasga | 0:f6f6750994d2 | 18 | |
ivaariasga | 0:f6f6750994d2 | 19 | #endif |