32 #ifndef MCU_COMMON_FIFO_H
33 #define MCU_COMMON_FIFO_H
52 #define FIFO_INIT(fifo, elem_size, fifo_capacity) \
54 static char buffer[(elem_size)*((fifo_capacity)+1)]; \
55 (fifo)->buffer = buffer; \
56 (fifo)->element_size = (elem_size); \
57 (fifo)->buffer_capacity = (fifo_capacity)+1; \
size_t fifo_read(struct fifo *fifo, void *dst, size_t count)
Reads data from FIFO.
Definition: fifo.c:145
size_t fifo_readable(const struct fifo *fifo)
Returns number of elements which can be read from the FIFO.
Definition: fifo.c:101
size_t fifo_write(struct fifo *fifo, const void *src, size_t count)
Writes data to FIFO.
Definition: fifo.c:183
size_t fifo_gets(struct fifo *fifo, char *str)
Reads null-terminated string from FIFO.
Definition: fifo.c:223
size_t fifo_writable(const struct fifo *fifo)
Returns number of elements which can be written to the FIFO.
Definition: fifo.c:123
bool fifo_init(struct fifo *fifo)
Initializes FIFO.
Definition: fifo.c:67
size_t fifo_capacity(const struct fifo *fifo)
Returns number of elements the FIFO can hold.
Definition: fifo.c:87
size_t fifo_puts(struct fifo *fifo, const char *str)
Writes null-terminated string to FIFO.
Definition: fifo.c:259
FIFO instance.
Definition: fifo.h:63
size_t element_size
Size of a single element.
Definition: fifo.h:68
void * buffer
Pointer to the buffer holding FIFO elements.
Definition: fifo.h:66
volatile size_t tail
Read index (handled internally)
Definition: fifo.h:74
volatile size_t head
Write index (handled internally)
Definition: fifo.h:76
size_t buffer_capacity
Number of elements the buffer can hold (The actual capacity of the FIFO is buffer_capacity-1 as one e...
Definition: fifo.h:72