Initial commit

This commit is contained in:
Julian Appel 2026-03-29 14:47:13 +02:00
commit b49984b9c0
32 changed files with 2394 additions and 0 deletions

43
src/CEventQueue.cpp Normal file
View file

@ -0,0 +1,43 @@
// CEventQueue.cpp
// Ring-Buffer FIFO-Implementierung.
//
// Funktionsprinzip (klassischer Power-of-2-freier Ring-Buffer):
// m_head = Lese-Index (pop)
// m_tail = Schreib-Index (push)
// Leer: m_head == m_tail
// Voll: (m_tail + 1) % SIZE == m_head → ein Slot bleibt immer frei
//
// Interrupt-Sicherheit (Cortex-M0+):
// push() wird aus Encoder-ISR aufgerufen, pop() aus dem Loop.
// Auf M0+ sind uint8_t-Lese/Schreibzugriffe atomar (single-cycle LDR/STR)
// solange nur ein Producer (ISR) und ein Consumer (Loop) existieren, ist kein
// Mutex nötig. Bei mehreren Producern müsste noInterrupts() verwendet werden.
#include "CEventQueue.h"
bool CEventQueue::is_empty() const
{
return m_head == m_tail;
}
bool CEventQueue::is_full() const
{
// Voll wenn der nächste Schreib-Index auf den Lese-Index zeigen würde
return ((m_tail + 1) % QUEUE_SIZE) == m_head;
}
bool CEventQueue::push(SEvent ev)
{
if (is_full()) return false; // Event verwerfen sollte bei 16 Slots nie passieren
m_buf[m_tail] = ev;
m_tail = (m_tail + 1) % QUEUE_SIZE;
return true;
}
bool CEventQueue::pop(SEvent& out)
{
if (is_empty()) return false;
out = m_buf[m_head];
m_head = (m_head + 1) % QUEUE_SIZE;
return true;
}