mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-08-06 19:17:34 +00:00
Rework structure and configuration
This commit is contained in:
50
src/os2/startup.cpp
Normal file
50
src/os2/startup.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <sta/os2/startup.hpp>
|
||||
#ifdef STA_OS2_STARTUP_ENABLE
|
||||
|
||||
#include <sta/lang.hpp>
|
||||
#include <sta/os2/system_event.hpp>
|
||||
#include <sta/os2/watchdog.hpp>
|
||||
|
||||
#include <main.h>
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
|
||||
#ifndef STA_OS2_STARTUP_ENTRY_FUNCTION
|
||||
# define STA_OS2_STARTUP_ENTRY_FUNCTION startupTask
|
||||
#endif // !STA_OS2_STARTUP_ENTRY_FUNCTION
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
// Provide weak implementation to allow overriding
|
||||
STA_WEAK
|
||||
void startupExtras(void *)
|
||||
{}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
// Declare with C linkage
|
||||
extern "C"
|
||||
{
|
||||
void STA_OS2_STARTUP_ENTRY_FUNCTION(void * arg)
|
||||
{
|
||||
// Call further initialization code
|
||||
sta::startupExtras(arg);
|
||||
|
||||
|
||||
#ifdef STA_WATCHDOG_ENABLE
|
||||
// Start timers
|
||||
sta::startWatchdogTimer();
|
||||
#endif
|
||||
|
||||
// Wake tasks
|
||||
sta::signalStartupEvent();
|
||||
|
||||
// Terminate task
|
||||
osThreadExit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // STA_OS2_STARTUP_ENABLE
|
41
src/os2/system_event.cpp
Normal file
41
src/os2/system_event.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <sta/os2/system_event.hpp>
|
||||
|
||||
#ifdef STA_OS2_SYSTEM_EVENT_ENABLE
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
|
||||
#ifndef STA_OS2_SYSTEM_EVENT_HANDLE
|
||||
# define STA_OS2_SYSTEM_EVENT_HANDLE systemEventHandle
|
||||
#endif // !STA_OS2_SYSTEM_EVENT_HANDLE
|
||||
|
||||
// Access handle from freertos.c
|
||||
extern osEventFlagsId_t STA_OS2_SYSTEM_EVENT_HANDLE;
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
void signalSystemEvents(uint32_t flags)
|
||||
{
|
||||
osEventFlagsSet(STA_OS2_SYSTEM_EVENT_HANDLE, flags);
|
||||
}
|
||||
|
||||
void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout)
|
||||
{
|
||||
osEventFlagsWait(STA_OS2_SYSTEM_EVENT_HANDLE, flags, options | osFlagsNoClear, timeout);
|
||||
}
|
||||
|
||||
|
||||
void signalStartupEvent()
|
||||
{
|
||||
signalSystemEvents(STA_SYSTEM_EVENT_STARTUP);
|
||||
}
|
||||
|
||||
void waitForStartupEvent()
|
||||
{
|
||||
waitForSystemEvents(STA_SYSTEM_EVENT_STARTUP, osFlagsWaitAll, osWaitForever);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_SYSTEM_EVENT_ENABLE
|
46
src/os2/watchdog/heartbeat.cpp
Normal file
46
src/os2/watchdog/heartbeat.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <sta/os2/watchdog.hpp>
|
||||
|
||||
#ifdef STA_OS2_WATCHDOG_ENABLE
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
|
||||
#ifndef STA_OS2_WATCHDOG_TIMER_PERIOD
|
||||
# define STA_OS2_WATCHDOG_TIMER_PERIOD 1000
|
||||
#endif // !STA_OS2_WATCHDOG_TIMER_PERIOD
|
||||
|
||||
#ifndef STA_OS2_WATCHDOG_TIMER_HANDLE
|
||||
# define STA_OS2_WATCHDOG_TIMER_HANDLE heartbeatHandle
|
||||
#endif // !STA_OS2_WATCHDOG_TIMER_HANDLE
|
||||
|
||||
#ifndef STA_OS2_WATCHDOG_TIMER_CALLBACK
|
||||
# define STA_OS2_WATCHDOG_TIMER_CALLBACK heartbeatCallback
|
||||
#endif // !STA_OS2_WATCHDOG_TIMER_CALLBACK
|
||||
|
||||
|
||||
// Access handles from freertos.c
|
||||
extern osTimerId_t STA_OS2_WATCHDOG_TIMER_HANDLE;
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
void startWatchdogTimer()
|
||||
{
|
||||
osTimerStart(STA_OS2_WATCHDOG_TIMER_HANDLE, STA_OS2_WATCHDOG_TIMER_PERIOD);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
// Declare with C linkage
|
||||
extern "C"
|
||||
{
|
||||
void STA_OS2_WATCHDOG_TIMER_CALLBACK(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_OS2_WATCHDOG_ENABLE
|
@@ -1,18 +1,26 @@
|
||||
#include <sta/watchdog.hpp>
|
||||
#include <sta/os2/watchdog.hpp>
|
||||
|
||||
#ifdef STA_WATCHDOG_ENABLE
|
||||
#ifdef STA_OS2_WATCHDOG_ENABLE
|
||||
|
||||
#include <sta/lang.hpp>
|
||||
#include <sta/os2.hpp>
|
||||
#include <sta/system_event.hpp>
|
||||
#include <sta/os2/defs.hpp>
|
||||
#include <sta/os2/system_event.hpp>
|
||||
|
||||
#include <main.h>
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
|
||||
// Access handles from freertos.c
|
||||
extern osThreadId_t watchdogHandle;
|
||||
#ifndef STA_OS2_WATCHDOG_HANDLE
|
||||
# define STA_OS2_WATCHDOG_HANDLE watchdogHandle
|
||||
#endif // !STA_OS2_WATCHDOG_HANDLE
|
||||
|
||||
#ifndef STA_OS2_WATCHDOG_ENTRY_FUNCTION
|
||||
# define STA_OS2_WATCHDOG_ENTRY_FUNCTION watchdogTask
|
||||
#endif // !STA_OS2_WATCHDOG_ENTRY_FUNCTION
|
||||
|
||||
|
||||
// Access handle from freertos.c
|
||||
extern osThreadId_t STA_OS2_WATCHDOG_HANDLE;
|
||||
|
||||
|
||||
namespace sta
|
||||
@@ -31,7 +39,7 @@ namespace sta
|
||||
// Declare with C linkage
|
||||
extern "C"
|
||||
{
|
||||
STA_WEAK void watchdogTask(void * arg)
|
||||
void STA_OS2_WATCHDOG_ENTRY_FUNCTION(void * arg)
|
||||
{
|
||||
sta::waitForStartupEvent();
|
||||
|
||||
@@ -47,4 +55,4 @@ extern "C"
|
||||
}
|
||||
|
||||
|
||||
#endif // STA_WATCHDOG_ENABLE
|
||||
#endif // STA_OS2_WATCHDOG_ENABLE
|
@@ -1,44 +0,0 @@
|
||||
#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
|
@@ -1,38 +0,0 @@
|
||||
#include <sta/system_event.hpp>
|
||||
|
||||
#ifdef STA_SYSTEM_EVENT_ENABLE
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
|
||||
// Access handles from freertos.c
|
||||
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 signalStartupEvent()
|
||||
{
|
||||
signalSystemEvents(STA_SYSTEM_EVENT_STARTUP);
|
||||
}
|
||||
|
||||
void waitForStartupEvent()
|
||||
{
|
||||
waitForSystemEvents(STA_SYSTEM_EVENT_STARTUP, osFlagsWaitAll, osWaitForever);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_SYSTEM_EVENT_ENABLE
|
@@ -1,38 +0,0 @@
|
||||
#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
|
Reference in New Issue
Block a user