mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-08-06 19:17:34 +00:00
Add startup and watchdog modules
This commit is contained in:
44
src/startup.cpp
Normal file
44
src/startup.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <sta/config.hpp>
|
||||
|
||||
#ifdef STA_STARTUP_TASK_ENABLE
|
||||
|
||||
#include <sta/lang.hpp>
|
||||
#include <sta/system_event.hpp>
|
||||
#include <sta/watchdog.hpp>
|
||||
|
||||
#include <main.h>
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
// Weak noop to be overridden by application if required
|
||||
STA_WEAK void startupTaskExtras(void *) {}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
// Declare with C linkage
|
||||
extern "C"
|
||||
{
|
||||
void startupTask(void * arg)
|
||||
{
|
||||
// Call further initialization code
|
||||
sta::startupTaskExtras(arg);
|
||||
|
||||
|
||||
#ifdef STA_WATCHDOG_ENABLE
|
||||
// Start timers
|
||||
sta::startWatchdogTimer();
|
||||
#endif
|
||||
|
||||
// Wake tasks
|
||||
sta::signalStartupEvent();
|
||||
|
||||
// Terminate task
|
||||
osThreadExit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // STA_STARTUP_TASK_ENABLE
|
@@ -5,6 +5,7 @@
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
|
||||
// Access handles from freertos.c
|
||||
extern osEventFlagsId_t systemEventHandle;
|
||||
|
||||
|
||||
@@ -34,4 +35,4 @@ namespace sta
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_SYSTEM_EVENT_ENABLE
|
||||
#endif // STA_SYSTEM_EVENT_ENABLE
|
||||
|
38
src/watchdog/heartbeat.cpp
Normal file
38
src/watchdog/heartbeat.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <sta/watchdog.hpp>
|
||||
|
||||
#ifdef STA_WATCHDOG_ENABLE
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
|
||||
#ifndef STA_WATCHDOG_TIMER_PERIOD
|
||||
# define STA_WATCHDOG_TIMER_PERIOD 1000
|
||||
#endif // STA_WATCHDOG_TIMER_PERIOD
|
||||
|
||||
|
||||
// Access handles from freertos.c
|
||||
extern osTimerId_t heartbeatHandle;
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
void startWatchdogTimer()
|
||||
{
|
||||
osTimerStart(heartbeatHandle, STA_WATCHDOG_TIMER_PERIOD);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
// Declare with C linkage
|
||||
extern "C"
|
||||
{
|
||||
void heartbeatCallback(void *)
|
||||
{
|
||||
// Notify watchdog task to send heartbeat message
|
||||
// Required because blocking in a timer callback is not allowed
|
||||
sta::notifyWatchdog(STA_WATCHDOG_FLAG_HEARTBEAT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // STA_WATCHDOG_ENABLE
|
50
src/watchdog/watchdog.cpp
Normal file
50
src/watchdog/watchdog.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <sta/watchdog.hpp>
|
||||
|
||||
#ifdef STA_WATCHDOG_ENABLE
|
||||
|
||||
#include <sta/lang.hpp>
|
||||
#include <sta/os2.hpp>
|
||||
#include <sta/system_event.hpp>
|
||||
|
||||
#include <main.h>
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
|
||||
// Access handles from freertos.c
|
||||
extern osThreadId_t watchdogHandle;
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
void notifyWatchdog(uint32_t flags)
|
||||
{
|
||||
osThreadFlagsSet(watchdogHandle, flags);
|
||||
}
|
||||
|
||||
|
||||
// Handler for watchdog events
|
||||
extern void watchdogEventHandler(void * arg, uint32_t flags);
|
||||
} // namespace sta
|
||||
|
||||
|
||||
// Declare with C linkage
|
||||
extern "C"
|
||||
{
|
||||
STA_WEAK void watchdogTask(void * arg)
|
||||
{
|
||||
sta::waitForStartupEvent();
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Wait for any flag to be set
|
||||
uint32_t flags = osThreadFlagsWait(STA_OS2_THREAD_FLAGS_VALID_BITS, osFlagsWaitAny, osWaitForever);
|
||||
|
||||
// Call event handler
|
||||
sta::watchdogEventHandler(arg, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // STA_WATCHDOG_ENABLE
|
Reference in New Issue
Block a user