4 #define RINGBUFFER(name, size) uint8_t name[(size)+4] = { (size)+1, 0, 0 }
6 static inline uint8_t ringbuffer_size(const uint8_t *buffer)
11 static inline uint8_t ringbuffer_fill(const uint8_t *buffer)
13 const uint8_t size = buffer[0];
14 uint8_t head = buffer[1];
15 uint8_t tail = buffer[2];
21 static inline uint8_t ringbuffer_space(const uint8_t *buffer)
23 return ringbuffer_size(buffer)-ringbuffer_fill(buffer);
26 static inline void ringbuffer_push(uint8_t *buffer, uint8_t value)
28 const uint8_t size = buffer[0];
29 uint8_t head = buffer[1];
30 buffer[3+head] = value;
37 static inline void ringbuffer_blocking_push(uint8_t *buffer, uint8_t value)
39 const uint8_t size = buffer[0];
40 uint8_t next_head = buffer[1]+1;
43 const volatile uint8_t *tail = buffer+2;
44 while(next_head==*tail) ;
45 ringbuffer_push(buffer, value);
48 static inline uint8_t ringbuffer_pop(uint8_t *buffer)
50 const uint8_t size = buffer[0];
51 uint8_t tail = buffer[2];
52 uint8_t value = buffer[3+tail];
60 static inline uint8_t ringbuffer_blocking_pop(uint8_t *buffer)
62 const volatile uint8_t *head = buffer+1;
63 uint8_t tail = buffer[2];
65 return ringbuffer_pop(buffer);