PS_Fgen_FW  4da88f4073c1cc65ea45c3a652a2751e495e50db
Firmware for an Power Supply and Function Generator build from an ATX power supply
Loading...
Searching...
No Matches
CircularBuffer.h
Go to the documentation of this file.
1
8
9#ifndef CIRCULARBUFFER_H_
10#define CIRCULARBUFFER_H_
11
12#include <avr/io.h>
13#include <stddef.h>
14
20template <class T, size_t MaxElements>
22{
23 private:
24 T queue[MaxElements];
25 volatile uint16_t head;
26 volatile uint16_t tail;
27
28 public:
29
34 inline uint8_t empty()
35 {
36 return (head == tail);
37 }
38
43 inline uint8_t full()
44 {
45 return (head == (tail + 1) % MaxElements);
46 }
47
53 inline void enqueue(T* data)
54 {
55 queue[tail] = *data;
56 tail = (tail + 1) % MaxElements;
57 }
58
64 inline T* dequeue()
65 {
66 T* data = &queue[head];
67 head = (head + 1) % MaxElements;
68 return data;
69 }
70};
71
72#endif /* CIRCULARBUFFER_H_ */
Class that is implementing a circular buffer (for queue functionality).
Definition CircularBuffer.h:22
volatile uint16_t tail
Tail index of the circular buffer.
Definition CircularBuffer.h:26
T queue[MaxElements]
Array holding the circular buffer data.
Definition CircularBuffer.h:24
volatile uint16_t head
Head index of the circular buffer.
Definition CircularBuffer.h:25
T * dequeue()
Dequeue data from the queue and return a pointer to the data dequeue() should never be called on an e...
Definition CircularBuffer.h:64
void enqueue(T *data)
Enqueue the data at the given pointer into the queue.
Definition CircularBuffer.h:53
uint8_t empty()
Check if the circular buffer is empty.
Definition CircularBuffer.h:34
uint8_t full()
Check if the circular buffer is full.
Definition CircularBuffer.h:43