add unified compile target
[avr_work.git] / common / queue.h
blob6d627d87f9b2f2139a23859cc1f0a66594079ce8
1 /*
2 * queue.h
3 */
4 #ifndef _QUEUE_H_
5 #define _QUEUE_H_
6 #include <stdint.h>
7 #include <stdbool.h>
9 #define QUEUE_BASE_T uint8_t
10 #define QUEUE_INDEX_T uint8_t
12 typedef volatile struct {
13 QUEUE_BASE_T *restrict buffer; // buffer
14 QUEUE_INDEX_T first; // position of first element
15 QUEUE_INDEX_T last; // position of last element (should be eliminated)
16 QUEUE_INDEX_T ct; //
17 const QUEUE_INDEX_T sz; // size of the buffer
18 } queue_t;
20 #define Q_DEF(buff) { .buffer = (buff), .first = 0, .last = 0, .ct = 0, .sz = sizeof(buff) / sizeof(QUEUE_BASE_T) }
22 // adds a new element
23 int8_t q_push(queue_t *q, QUEUE_BASE_T x);
24 int8_t q_push_o(queue_t *q, QUEUE_BASE_T x); // overwrites old data on q full
26 QUEUE_BASE_T q_pop(queue_t *q); // takes oldest element
27 QUEUE_BASE_T q_remove(queue_t *q); // takes newest element
29 void q_flush(queue_t *q);
30 bool q_empty(queue_t *q);
31 bool q_full(queue_t *q);
33 #endif