forked from jappel/VersaMCU
Initial commit
This commit is contained in:
commit
b49984b9c0
32 changed files with 2394 additions and 0 deletions
37
src/CEventQueue.h
Normal file
37
src/CEventQueue.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// CEventQueue.h
|
||||
// Fester Ring-Buffer FIFO für SEvent-Objekte.
|
||||
//
|
||||
// Bewusst ohne Heap (kein new/delete) und ohne STL (kein std::vector/queue)
|
||||
// um auf dem SAMD21 mit 16KB RAM deterministisches Verhalten zu garantieren.
|
||||
//
|
||||
// Kapazität: QUEUE_SIZE - 1 = 16 Events (ein Slot bleibt leer damit
|
||||
// is_full() und is_empty() ohne extra Zähler unterscheidbar sind).
|
||||
//
|
||||
// Thread-Sicherheit:
|
||||
// push() wird aus ISR-Kontext aufgerufen (encoder_cb).
|
||||
// pop() wird aus Loop-Kontext aufgerufen (processEvents).
|
||||
// Auf Cortex-M0+ sind 8-Bit-Lese/Schreibzugriffe atomar → kein Mutex nötig
|
||||
// solange nur ein Producer (ISR) und ein Consumer (Loop) existieren.
|
||||
|
||||
#pragma once
|
||||
#include "SEvent.h"
|
||||
#include <stdint.h>
|
||||
|
||||
class CEventQueue
|
||||
{
|
||||
public:
|
||||
// Event einreihen. Gibt false zurück wenn Queue voll (Event wird verworfen).
|
||||
bool push(SEvent ev);
|
||||
|
||||
// Ältestes Event abholen (FIFO). Gibt false zurück wenn Queue leer.
|
||||
bool pop(SEvent& out);
|
||||
|
||||
bool is_empty() const;
|
||||
bool is_full() const;
|
||||
|
||||
private:
|
||||
static const uint8_t QUEUE_SIZE = 17; // 16 nutzbare Slots
|
||||
SEvent m_buf[QUEUE_SIZE];
|
||||
uint8_t m_head = 0; // Nächster Lese-Index (Consumer: pop)
|
||||
uint8_t m_tail = 0; // Nächster Schreib-Index (Producer: push)
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue