38#include <pico/stdlib.h>
60 subs.push_back({mask, target});
66 xSemaphoreTake(
lock, portMAX_DELAY);
74 xSemaphoreTake(
lock, portMAX_DELAY);
82 const uint8_t index = n.
code();
85 BaseType_t xHigherPriTaskWoken = pdFALSE;
88 for (
auto& sub : subs) {
89 if ((sub.eventMask & (1u << index)) &&
90 (target ==
nullptr || sub.controller == target)) {
91 sub.controller->notifyFromISR(index, 1, &xHigherPriTaskWoken);
96 portYIELD_FROM_ISR(xHigherPriTaskWoken);
99 for (
auto& sub : subs) {
100 if ((sub.eventMask & (1u << index)) &&
101 (target ==
nullptr || sub.controller == target)) {
102 sub.controller->notify(index, 1);
113 const uint8_t code =
event.notification.code();
116 BaseType_t xHigherPriTaskWoken = pdFALSE;
119 for (
auto& sub : subs) {
120 if ((sub.eventMask & (1u << code)) &&
121 (
event.target ==
nullptr || sub.controller ==
event.target))
123 QueueHandle_t q = sub.controller->getEventQueue();
125 BaseType_t result = xQueueSendToBackFromISR(q, &event, &xHigherPriTaskWoken);
126 if (result != pdPASS) {
127 debug_print(
"[EventManager] xQueueSendFromISR FAILED — queue full!\n");
134 portYIELD_FROM_ISR(xHigherPriTaskWoken);
137 for (
auto& sub : subs) {
138 if ((sub.eventMask & (1u << code)) &&
139 (
event.target ==
nullptr || sub.controller ==
event.target))
141 QueueHandle_t q = sub.controller->getEventQueue();
143 if (xQueueSendToBack(q, &event, 0) != pdPASS) {
144 debug_print(
"[EventManager] xQueueSend FAILED — queue full!\n");
Event pub/sub manager for embedded applications using FreeRTOS.
The FrameworkController class for event-driven control logic in embedded applications.
FreeRTOS-aware task abstraction with built-in notification and queue support.
void subscribe(uint32_t eventMask, FrameworkController *controller)
Subscribe a task to specific event types.
void postEvent(const Event &e)
Post a notification to the queue and notify matching subscribers.
void withSubscribersFromISR(const std::function< void(std::vector< Subscriber > &)> &fn)
Provides read-only access to subscribers from ISR context (no locking).
void enqueue(const Event &event)
Post an event to the queue and notify matching subscribers.
void postNotification(const Notification &n, FrameworkTask *target)
Post a notification to the queue and notify matching subscribers.
EventManager(size_t queueSize=0)
Constructor with optional queue size override.
std::vector< Subscriber > subscribers_
static StaticSemaphore_t lockBuffer_
void withSubscribers(const std::function< void(std::vector< Subscriber > &)> &fn)
Base class for event-driven control logic in embedded applications.
Base class for FreeRTOS-aware tasks in the framework.
Represents a framework event, optionally carrying payload data.
Notification notification
Notification identifier (system or user)
FrameworkTask * target
Optional specific target (for directed delivery)
A tagged union representing either a system or user-defined notification.
uint8_t code() const
Get the notification code.
int is_in_interrupt(void)
void debug_print(const char *msg)
System utilities for diagnostics, memory, stack usage, and tracing.