mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-06-12 01:25:59 +00:00
Working global events implementation
This commit is contained in:
parent
1669b0c590
commit
4faeb1e6b0
@ -16,31 +16,33 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cmsis_os2.h>
|
||||||
|
|
||||||
|
// Custom event flags for the user (bits 0-13).
|
||||||
|
//
|
||||||
|
#define STA_TACOS_CUSTOM_EVENT(k) (0x1U << k)
|
||||||
|
|
||||||
|
// A mask representing all custom flags available for the user.
|
||||||
|
#define STA_TACOS_CUSTOM_EVENT_MASK (0x7FFFU)
|
||||||
|
|
||||||
// System event flags
|
// System event flags
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Startup system event flag.
|
* @brief Startup system event flag (bits 14-23).
|
||||||
*
|
*
|
||||||
* @ingroup STA_RTOS_SysEvent
|
* @ingroup STA_RTOS_SysEvent
|
||||||
*/
|
*/
|
||||||
|
#define STA_TACOS_SYSTEM_EVENTS_STARTUP (0x01U << 23)
|
||||||
|
|
||||||
#define STA_TACOS_EVENT_SYSTEM_MASK (0xFFFE0000U >> 1)
|
#define STA_TACOS_TICK_100_Hz (0x01U << 22)
|
||||||
#define STA_TACOS_EVENT_TIMER_MASK (0x7FC00000U >> 1)
|
#define STA_TACOS_TICK_50_Hz (0x01U << 21)
|
||||||
|
#define STA_TACOS_TOCK_50_Hz (0x01U << 20)
|
||||||
#define STA_TACOS_SYSTEM_EVENTS_STARTUP (0x01U << 30)
|
#define STA_TACOS_TICK_20_Hz (0x01U << 19)
|
||||||
|
#define STA_TACOS_TICK_10_Hz (0x01U << 18)
|
||||||
#define STA_TACOS_TICK_100_Hz (0x01U << 29)
|
#define STA_TACOS_TOCK_10_Hz (0x01U << 17)
|
||||||
#define STA_TACOS_TICK_50_Hz (0x01U << 28)
|
#define STA_TACOS_TICK_1_Hz (0x01U << 16)
|
||||||
#define STA_TACOS_TOCK_50_Hz (0x01U << 27)
|
#define STA_TACOS_TOCK_1_Hz (0x01U << 15)
|
||||||
#define STA_TACOS_TICK_20_Hz (0x01U << 26)
|
|
||||||
#define STA_TACOS_TOCK_20_Hz (0x01U << 25)
|
|
||||||
#define STA_TACOS_TICK_10_Hz (0x01U << 24)
|
|
||||||
#define STA_TACOS_TOCK_10_Hz (0x01U << 23)
|
|
||||||
#define STA_TACOS_TICK_1_Hz (0x01U << 22)
|
|
||||||
#define STA_TACOS_TOCK_1_Hz (0x01U << 21)
|
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
@ -72,7 +74,7 @@ namespace sta
|
|||||||
*
|
*
|
||||||
* @ingroup STA_RTOS_SysEvent
|
* @ingroup STA_RTOS_SysEvent
|
||||||
*/
|
*/
|
||||||
void wait(uint32_t flags, uint32_t options, uint32_t timeout);
|
void wait(uint32_t flags, uint32_t timeout = osWaitForever);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Signal startup system event.
|
* @brief Signal startup system event.
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// Event handle
|
// Event handle for system events.
|
||||||
sta::RtosEvent * systemEvents = nullptr;
|
sta::RtosEvent * systemEvents = nullptr;
|
||||||
|
|
||||||
// Tick timer handle
|
// Tick timer handle
|
||||||
@ -35,10 +35,11 @@ namespace sta
|
|||||||
|
|
||||||
if (tickTimer == nullptr)
|
if (tickTimer == nullptr)
|
||||||
{
|
{
|
||||||
|
// Initialize the a timer that sets tick event flags.
|
||||||
tickTimer = new sta::RtosTimer([](void * args) {
|
tickTimer = new sta::RtosTimer([](void * args) {
|
||||||
uint32_t flags = 0x00;
|
uint32_t flags = 0x00;
|
||||||
|
|
||||||
flags |= STA_TACOS_TOCK_50_Hz;
|
flags |= STA_TACOS_TICK_100_Hz;
|
||||||
|
|
||||||
if (tickCounter % 20 == 0) {
|
if (tickCounter % 20 == 0) {
|
||||||
flags |= STA_TACOS_TICK_50_Hz;
|
flags |= STA_TACOS_TICK_50_Hz;
|
||||||
@ -48,17 +49,15 @@ namespace sta
|
|||||||
|
|
||||||
if (tickCounter % 50 == 0) {
|
if (tickCounter % 50 == 0) {
|
||||||
flags |= STA_TACOS_TICK_20_Hz;
|
flags |= STA_TACOS_TICK_20_Hz;
|
||||||
} else if (tickCounter % 25 == 0) {
|
|
||||||
flags |= STA_TACOS_TOCK_20_Hz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tickCounter % 100) {
|
if (tickCounter % 100 == 0) {
|
||||||
flags |= STA_TACOS_TICK_10_Hz;
|
flags |= STA_TACOS_TICK_10_Hz;
|
||||||
} else if (tickCounter % 50 == 0) {
|
} else if (tickCounter % 50 == 0) {
|
||||||
flags |= STA_TACOS_TOCK_10_Hz;
|
flags |= STA_TACOS_TOCK_10_Hz;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tickCounter % 1000) {
|
if (tickCounter % 1000 == 0) {
|
||||||
flags |= STA_TACOS_TICK_1_Hz;
|
flags |= STA_TACOS_TICK_1_Hz;
|
||||||
} else if (tickCounter % 500 == 0) {
|
} else if (tickCounter % 500 == 0) {
|
||||||
flags |= STA_TACOS_TOCK_1_Hz;
|
flags |= STA_TACOS_TOCK_1_Hz;
|
||||||
@ -66,8 +65,8 @@ namespace sta
|
|||||||
|
|
||||||
tickCounter = (tickCounter + 10) % 1000;
|
tickCounter = (tickCounter + 10) % 1000;
|
||||||
|
|
||||||
signal(flags);
|
systemEvents->set(flags);
|
||||||
systemEvents->clear(STA_TACOS_EVENT_TIMER_MASK);
|
systemEvents->clear(flags);
|
||||||
}, nullptr, true);
|
}, nullptr, true);
|
||||||
|
|
||||||
tickTimer->start(10);
|
tickTimer->start(10);
|
||||||
@ -77,10 +76,13 @@ namespace sta
|
|||||||
void signal(uint32_t flags)
|
void signal(uint32_t flags)
|
||||||
{
|
{
|
||||||
STA_ASSERT_MSG(systemEvents != nullptr, "System events not initialized");
|
STA_ASSERT_MSG(systemEvents != nullptr, "System events not initialized");
|
||||||
|
STA_ASSERT_MSG((flags & ~STA_TACOS_CUSTOM_EVENT_MASK) == 0, "Invalid custom flags (available: bits 0 to 14)");
|
||||||
|
|
||||||
systemEvents->set(flags);
|
systemEvents->set(flags);
|
||||||
|
systemEvents->clear(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wait(uint32_t flags, uint32_t options, uint32_t timeout)
|
void wait(uint32_t flags, uint32_t timeout /* = osWaitForever */)
|
||||||
{
|
{
|
||||||
STA_ASSERT_MSG(systemEvents != nullptr, "System events not initialized");
|
STA_ASSERT_MSG(systemEvents != nullptr, "System events not initialized");
|
||||||
systemEvents->peek(flags, timeout);
|
systemEvents->peek(flags, timeout);
|
||||||
@ -88,12 +90,12 @@ namespace sta
|
|||||||
|
|
||||||
void signalStartup()
|
void signalStartup()
|
||||||
{
|
{
|
||||||
signal(STA_TACOS_SYSTEM_EVENTS_STARTUP);
|
systemEvents->set(STA_TACOS_SYSTEM_EVENTS_STARTUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitForStartup()
|
void waitForStartup()
|
||||||
{
|
{
|
||||||
wait(STA_TACOS_SYSTEM_EVENTS_STARTUP, osFlagsWaitAll, osWaitForever);
|
wait(STA_TACOS_SYSTEM_EVENTS_STARTUP);
|
||||||
}
|
}
|
||||||
} // namespace events
|
} // namespace events
|
||||||
} // namespace tacos
|
} // namespace tacos
|
||||||
|
Loading…
x
Reference in New Issue
Block a user