mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-14 19:25:59 +00:00
62 lines
1.3 KiB
C++
62 lines
1.3 KiB
C++
#include <sta/rtos/system/events.hpp>
|
|
|
|
#include <sta/debug/assert.hpp>
|
|
|
|
#include <cmsis_os2.h>
|
|
#include <FreeRTOS.h>
|
|
|
|
|
|
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
|