From 7ea8bb839e5a72e48b80ba9d646bbf6db3e50bd5 Mon Sep 17 00:00:00 2001 From: "@CarlWachter" Date: Tue, 12 Sep 2023 13:38:42 +0200 Subject: [PATCH] Added Events wrapper --- include/sta/rtos/event.hpp | 35 +++++++++++++++++++++++++++++++++++ src/event.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 include/sta/rtos/event.hpp create mode 100644 src/event.cpp diff --git a/include/sta/rtos/event.hpp b/include/sta/rtos/event.hpp new file mode 100644 index 0000000..95d1c89 --- /dev/null +++ b/include/sta/rtos/event.hpp @@ -0,0 +1,35 @@ +/** + * @file + * @brief RTOS event implementation. + */ + +#ifndef STA_RTOS_EVENT_HPP +#define STA_RTOS_EVENT_HPP + +#include +#include + +namespace sta +{ + /** + * @brief Implementation of Event using CMSIS RTOS2. + * + * @ingroup STA_RTOS_API + */ + class RtosEvent : public Event + { + public: + RtosEvent(); + ~RtosEvent(); + + void set(uint32_t flags) override; + void clear(uint32_t flags) override; + uint32_t get() override; + uint32_t wait(uint32_t flags, uint32_t timeout = osWaitForever) override; + + private: + osEventFlagsId_t event_id; /**< CMSIS RTOS2 Event Flag */ + }; +} // namespace sta + +#endif // STA_RTOS_EVENT_HPP \ No newline at end of file diff --git a/src/event.cpp b/src/event.cpp new file mode 100644 index 0000000..c6795cd --- /dev/null +++ b/src/event.cpp @@ -0,0 +1,29 @@ +#include + +namespace sta { + RtosEvent::RtosEvent() { + osEventFlagsAttr_t attr = { 0 }; + event_id = osEventFlagsNew(&attr); + } + + RtosEvent::~RtosEvent() { + osEventFlagsDelete(event_id); + } + + void RtosEvent::set(uint32_t flags) { + osEventFlagsSet(event_id, flags); + } + + void RtosEvent::clear(uint32_t flags) { + osEventFlagsClear(event_id, flags); + } + + uint32_t RtosEvent::get() { + return osEventFlagsGet(event_id); + } + + uint32_t RtosEvent::wait(uint32_t flags, uint32_t timeout) { + return osEventFlagsWait(event_id, flags, osFlagsWaitAny, timeout); + } + +} // namespace sta \ No newline at end of file