#ifndef FIFO_H #define FIFO_H #include #define FIFO_LEN 32 struct fifo { uint8_t head; uint8_t tail; uint8_t data[FIFO_LEN]; }; static inline uint8_t fifo_pop(struct fifo *fifo) { uint8_t ret = fifo->data[fifo->head]; if (++fifo->head >= LENGTH(fifo->data)) fifo->head = 0; return ret; } static inline void fifo_push(struct fifo *fifo, uint8_t v) { fifo->data[fifo->tail] = v; if (++fifo->tail >= LENGTH(fifo->data)) fifo->tail = 0; } static inline bool fifo_empty(const struct fifo *fifo) { return (fifo->head == fifo->tail); } static inline void fifo_clear(struct fifo *fifo) { fifo->head = 0; fifo->tail = 0; } #endif // FIFO_H