Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
FreeRtos.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <utility>
11
12#if defined(FREERTOS) || defined(INC_FREERTOS_H) || defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_ESP32)
13#include <freertos/FreeRTOS.h>
14#include <freertos/task.h>
15#define CORIUM_HAS_FREERTOS_INCLUDES 1
16#else
17// Mock definitions for host build and desktop testing
18using BaseType_t = long;
19#define pdTRUE 1
20#define pdFALSE 0
21#define portYIELD_FROM_ISR(x) ((void)(x))
22#endif
23
24namespace corium::embedded {
25
29template <typename EventSinkType>
31public:
32 constexpr FreeRtosIsrSink() noexcept = default;
33
34 constexpr explicit FreeRtosIsrSink(EventSinkType sink) noexcept
35 : _sink(sink)
36 {}
37
43 template <typename Event>
44 void postFromIsr(Event&& event, BaseType_t* pxHigherPriorityTaskWoken = nullptr, EventPriority priority = EventPriority::Normal) noexcept
45 {
46 _sink.post(std::forward<Event>(event), priority);
47 if (pxHigherPriorityTaskWoken) {
48 *pxHigherPriorityTaskWoken = pdTRUE;
49 }
50 }
51
53 template <typename Event>
54 void postHighPriorityFromIsr(Event&& event, BaseType_t* pxHigherPriorityTaskWoken = nullptr) noexcept
55 {
56 _sink.postHighPriority(std::forward<Event>(event));
57 if (pxHigherPriorityTaskWoken) {
58 *pxHigherPriorityTaskWoken = pdTRUE;
59 }
60 }
61
63 static void yieldFromIsr(BaseType_t xHigherPriorityTaskWoken) noexcept
64 {
65 if (xHigherPriorityTaskWoken == pdTRUE) {
66 portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
67 }
68 }
69
71 [[nodiscard]] constexpr EventSinkType& sink() noexcept { return _sink; }
72 [[nodiscard]] constexpr const EventSinkType& sink() const noexcept { return _sink; }
73
74private:
75 EventSinkType _sink{};
76};
77
79template <typename EventSinkType>
80[[nodiscard]] constexpr auto makeFreeRtosIsrSink(EventSinkType sink) noexcept
81{
83}
84
85} // namespace corium::embedded
long BaseType_t
Definition FreeRtos.hpp:18
#define portYIELD_FROM_ISR(x)
Definition FreeRtos.hpp:21
#define pdTRUE
Definition FreeRtos.hpp:19
Bounded and multi-tier priority MPSC queueing policies.
FreeRTOS-specialized ISR sink managing RTOS task context switches.
Definition FreeRtos.hpp:30
constexpr FreeRtosIsrSink() noexcept=default
constexpr EventSinkType & sink() noexcept
Access underlying sink handle.
Definition FreeRtos.hpp:71
void postFromIsr(Event &&event, BaseType_t *pxHigherPriorityTaskWoken=nullptr, EventPriority priority=EventPriority::Normal) noexcept
Post event from FreeRTOS ISR and track if context switch is needed.
Definition FreeRtos.hpp:44
void postHighPriorityFromIsr(Event &&event, BaseType_t *pxHigherPriorityTaskWoken=nullptr) noexcept
Post high priority event from FreeRTOS ISR and track context switch.
Definition FreeRtos.hpp:54
constexpr const EventSinkType & sink() const noexcept
Definition FreeRtos.hpp:72
static void yieldFromIsr(BaseType_t xHigherPriorityTaskWoken) noexcept
Yield to higher priority unblocked task if flag was set.
Definition FreeRtos.hpp:63
Definition CanAdapter.hpp:16
constexpr auto makeFreeRtosIsrSink(EventSinkType sink) noexcept
Helper function to construct FreeRtosIsrSink from an event sink handle.
Definition FreeRtos.hpp:80
EventPriority
Event priority levels for multi-priority queue policies.
Definition QueuePolicies.hpp:32
DefaultEvents Event
Alias for DefaultEvents.
Definition Events.hpp:65