diff --git a/include/sta/rtos/event.hpp b/include/sta/rtos/event.hpp index b058e0c..85b5bbd 100644 --- a/include/sta/rtos/event.hpp +++ b/include/sta/rtos/event.hpp @@ -40,7 +40,7 @@ namespace sta uint32_t get() override; /** - * @brief Wait for any of the given flags to be set. + * @brief Wait for any of the given flags to be set. Clears the flags afterwards * * @param flags Flags to wait for. * @param timeout Timeout in milliseconds. @@ -48,9 +48,17 @@ namespace sta */ uint32_t wait(uint32_t flags, uint32_t timeout = osWaitForever) override; + /** + * @brief Wait for any of the given flags to be set without clearing the flags afterwards. + * + * @param flags Flags to wait for. + * @param timeout Timeout in milliseconds. + * @return Event flags before clearing or error code if highest bit set. + */ + uint32_t peek(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 +#endif // STA_RTOS_EVENT_HPP diff --git a/include/sta/rtos/system/events.hpp b/include/sta/rtos/system/events.hpp deleted file mode 100644 index 603beb6..0000000 --- a/include/sta/rtos/system/events.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @file - * @brief Implementation of system events. - */ -#ifndef STA_RTOS_SYSTEM_EVENTS_HPP -#define STA_RTOS_SYSTEM_EVENTS_HPP - - -/** - * @defgroup STA_RTOS_SysEvent System Events - * @ingroup STA_RTOS_API - * @brief System events. - * - * Check @ref STA_RTOS_BuildConfig for configuration options. - */ - - -#include - - -// System event flags -// - -/** - * @brief Startup system event flag. - * - * @ingroup STA_RTOS_SysEvent - */ -#define STA_RTOS_SYSTEM_EVENTS_STARTUP 0x100000U - - -namespace sta -{ - namespace rtos - { - /** - * @brief Initialize system events. - */ - void initSystemEvents(); - - - /** - * @brief Signal system events. - * - * @param flags System event flags - * - * @ingroup STA_RTOS_SysEvent - */ - void signalSystemEvents(uint32_t flags); - - /** - * @brief Wait for system events. - * - * @param flags System event flags - * @param options osFlagsWaitAll or osFlagsWaitAny (osFlagsNoClear always set) - * @param timeout Wait timeout (0 = instant, osWaitForever = infinite) - * - * @ingroup STA_RTOS_SysEvent - */ - void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout); - - - /** - * @brief Signal startup system event. - * - * @ingroup STA_RTOS_SysEvent - */ - void signalStartupEvent(); - - /** - * @brief Wait for startup system event. - * - * Blocking while waiting - * - * @ingroup STA_RTOS_SysEvent - */ - void waitForStartupEvent(); - } // namespace rtos -} // namespace sta - - -#endif // STA_RTOS_SYSTEM_EVENTS_HPP diff --git a/include/sta/rtos/system/startup.hpp b/include/sta/rtos/system/startup.hpp deleted file mode 100644 index f3e957a..0000000 --- a/include/sta/rtos/system/startup.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @file - * @brief Implementation of startup system task. - */ -#ifndef STA_RTOS_SYSTEM_STARTUP_HPP -#define STA_RTOS_SYSTEM_STARTUP_HPP - -/** - * @defgroup STA_RTOS_Startup RTOS Startup - * @ingroup STA_RTOS_API - * @brief Initializes rtos functions. - */ - -namespace sta -{ - namespace rtos - { - /** - * @brief Initializes rtos functions. - * - * @ingroup STA_RTOS_Startup - */ - void initSystem(); - } // namespace rtos -} // namespace sta - - -#endif // STA_RTOS_SYSTEM_STARTUP_HPP diff --git a/src/event.cpp b/src/event.cpp index c6795cd..50999e2 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -22,8 +22,13 @@ namespace sta { return osEventFlagsGet(event_id); } - uint32_t RtosEvent::wait(uint32_t flags, uint32_t timeout) { + uint32_t RtosEvent::wait(uint32_t flags, uint32_t timeout /* = osWaitForever */) { return osEventFlagsWait(event_id, flags, osFlagsWaitAny, timeout); } -} // namespace sta \ No newline at end of file + uint32_t RtosEvent::peek(uint32_t flags, uint32_t timeout /* = osWaitForever */) + { + return osEventFlagsWait(event_id, flags, osFlagsWaitAny | osFlagsNoClear, timeout); + } + +} // namespace sta diff --git a/src/system/events.cpp b/src/system/events.cpp deleted file mode 100644 index 6383047..0000000 --- a/src/system/events.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include - -#include - -#include -#include - - -namespace -{ - // Static memory for system events - StaticEventGroup_t systemEventControlBlock; - // Event handle - osEventFlagsId_t systemEventsHandle = nullptr; -} - - -namespace sta -{ - namespace rtos - { - void initSystemEvents() - { - // Create event using static allocation - const osEventFlagsAttr_t attributes = { - .name = "systemEvent", - .cb_mem = &systemEventControlBlock, - .cb_size = sizeof(systemEventControlBlock), - }; - - if (systemEventsHandle == nullptr) - { - systemEventsHandle = osEventFlagsNew(&attributes); - } - } - - - void signalSystemEvents(uint32_t flags) - { - STA_ASSERT_MSG(systemEventsHandle != nullptr, "System events not initialized"); - osEventFlagsSet(systemEventsHandle, flags); - } - - void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout) - { - STA_ASSERT_MSG(systemEventsHandle != nullptr, "System events not initialized"); - osEventFlagsWait(systemEventsHandle, flags, options | osFlagsNoClear, timeout); - } - - - void signalStartupEvent() - { - signalSystemEvents(STA_RTOS_SYSTEM_EVENTS_STARTUP); - } - - void waitForStartupEvent() - { - waitForSystemEvents(STA_RTOS_SYSTEM_EVENTS_STARTUP, osFlagsWaitAll, osWaitForever); - } - } // namespace rtos -} // namespace sta diff --git a/src/system/startup.cpp b/src/system/startup.cpp deleted file mode 100644 index e03a80e..0000000 --- a/src/system/startup.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -namespace sta -{ - namespace rtos - { - void initSystem() - { - -#ifdef STA_RTOS_SYSTEM_EVENTS_ENABLE - initSystemEvents(); -#endif // STA_RTOS_SYSTEM_EVENTS_ENABLE - - } - } // namespace rtos -} // namespace sta