From aeb472fd03451da304a019d200f1e2c1b23e72ca Mon Sep 17 00:00:00 2001 From: Henrik Stickann <4376396-Mithradir@users.noreply.gitlab.com> Date: Sat, 21 Jan 2023 22:34:26 +0100 Subject: [PATCH] Simplify startup API --- include/sta/rtos/system/startup.hpp | 39 ------------------- src/system/startup.cpp | 60 ++++++++++++++++++----------- 2 files changed, 38 insertions(+), 61 deletions(-) diff --git a/include/sta/rtos/system/startup.hpp b/include/sta/rtos/system/startup.hpp index d34d43a..f3a2e46 100644 --- a/include/sta/rtos/system/startup.hpp +++ b/include/sta/rtos/system/startup.hpp @@ -5,8 +5,6 @@ #ifndef STA_RTOS_SYSTEM_STARTUP_HPP #define STA_RTOS_SYSTEM_STARTUP_HPP -#include - /** * @defgroup STA_RTOS_Startup Startup task @@ -17,41 +15,6 @@ */ -#ifdef DOXYGEN -/** - * @brief Enable module. - * - * @ingroup STA_RTOS_BuildConfig - */ -# define STA_RTOS_STARTUP_ENABLE -#endif // DOXYGEN - - -/** - * @def STA_RTOS_STARTUP_TASK_NAME - * @brief Set name of startup task. - * - * @ingroup STA_RTOS_BuildConfig - */ -#ifndef STA_RTOS_STARTUP_TASK_NAME -# define STA_RTOS_STARTUP_TASK_NAME startup -#endif // !STA_RTOS_STARTUP_TASK_NAME - -/** - * @def STA_RTOS_STARTUP_ENTRY_FUNCTION - * @brief Set name of startup task entry function. - * - * @ingroup STA_RTOS_BuildConfig - */ -#ifndef STA_RTOS_STARTUP_ENTRY_FUNCTION -# define STA_RTOS_STARTUP_ENTRY_FUNCTION STA_RTOS_MAKE_ENTRY_NAME(STA_RTOS_STARTUP_TASK_NAME) -#endif // !STA_RTOS_STARTUP_ENTRY_FUNCTION - - -#include -#ifdef STA_RTOS_STARTUP_ENABLE - - namespace sta { namespace rtos @@ -68,6 +31,4 @@ namespace sta } // namespace sta -#endif // STA_RTOS_STARTUP_ENABLE - #endif // STA_RTOS_SYSTEM_STARTUP_HPP diff --git a/src/system/startup.cpp b/src/system/startup.cpp index 9e31530..4308fdb 100644 --- a/src/system/startup.cpp +++ b/src/system/startup.cpp @@ -1,7 +1,10 @@ #include -#ifdef STA_RTOS_STARTUP_ENABLE +#include + +#include #include +#include #include #include #include @@ -17,33 +20,46 @@ namespace sta STA_WEAK void startupExtras(void *) {} + + + void initSystem() + { +#ifdef STA_RTOS_SYSTEM_EVENTS_ENABLE + initSystemEvents(); +#endif // STA_RTOS_SYSTEM_EVENTS_ENABLE + +#ifdef STA_RTOS_WATCHDOG_ENABLE + initWatchdog(); +#endif // STA_RTOS_WATCHDOG_ENABLE + +#ifdef STA_RTOS_CAN_BUS_ENABLE + initCanBus(); +#endif // STA_RTOS_CAN_BUS_ENABLE + } } // namespace rtos } // namespace sta -// Declare with C linkage -extern "C" +void startALPAKA(void * arg) { - void STA_RTOS_STARTUP_ENTRY_FUNCTION(void * arg) + STA_ASSERT_MSG(osKernelGetState() != osKernelInactive, "Cannot call startALPAKA() before osKernelInitialize()"); + + // Call further initialization code + sta::rtos::startupExtras(arg); + + // Initialize HAL + sta::initHAL(); + + // Initialize RTOS system resources + sta::rtos::initSystem(); + + // Wake threads + sta::rtos::signalStartupEvent(); + + // Check if called from thread + if (osThreadGetId() != nullptr) { - // Call further initialization code - sta::rtos::startupExtras(arg); - - // Initialize HAL - sta::initHAL(); - -#ifdef STA_RTOS_WATCHDOG_ENABLE - // Start timers - sta::rtos::startWatchdogTimer(); -#endif // STA_RTOS_WATCHDOG_ENABLE - - // Wake threads - sta::rtos::signalStartupEvent(); - - // Terminate thread + // Terminate current thread osThreadExit(); } } - - -#endif // STA_RTOS_STARTUP_ENABLE