commit dde9b83a2914e14d751c036d974c57f622c72dc4 Author: Henrik Stickann <4376396-Mithradir@users.noreply.gitlab.com> Date: Thu Mar 31 13:49:03 2022 +0200 Add system events handling diff --git a/include/sta/system_event.hpp b/include/sta/system_event.hpp new file mode 100644 index 0000000..7e2ea1c --- /dev/null +++ b/include/sta/system_event.hpp @@ -0,0 +1,45 @@ +#ifndef STA_SYSTEM_EVENT_HPP +#define STA_SYSTEM_EVENT_HPP + +#include + + +// System event flags +// + +#define STA_SYSTEM_EVENT_STARTUP 0x00100000U + + +namespace sta +{ + /** + * @brief Signal system events + * + * @param flags System event flags + */ + void signalSystemEvents(uint32_t flags); + + /** + * @brief Wait for system event. + * + * @param flags System event flags + * @param options osFlagsWaitAll or osFlagsWaitAny (osFlagsNoClear always set) + * @param timeout Wait timeout (0 = instant, osWaitForever = infinite) + */ + void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout); + + /** + * @brief Signal startup system event + */ + void signalStartupCompleted(); + + /** + * @brief Wait for startup system event. + * + * Blocking while waiting + */ + void waitForStartup(); +} // namespace sta + + +#endif // STA_SYSTEM_EVENT_HPP \ No newline at end of file diff --git a/src/system_event.cpp b/src/system_event.cpp new file mode 100644 index 0000000..5eafbfe --- /dev/null +++ b/src/system_event.cpp @@ -0,0 +1,32 @@ +#include + +#include + + +extern osEventFlagsId_t systemEventHandle; + + +namespace sta +{ + void signalSystemEvents(uint32_t flags) + { + osEventFlagsSet(systemEventHandle, flags); + } + + + void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout) + { + osEventFlagsWait(systemEventHandle, flags, options | osFlagsNoClear, timeout); + } + + + void signalStartupCompleted() + { + signalSystemEvents(STA_SYSTEM_EVENT_STARTUP); + } + + void waitForStartup() + { + waitForSystemEvents(STA_SYSTEM_EVENT_STARTUP, osFlagsWaitAll, osWaitForever); + } +} // namespace sta