From f0c5faf29ecc685749b48a161f8d2f7e16980ddd Mon Sep 17 00:00:00 2001 From: CarlWachter Date: Sun, 3 Nov 2024 12:43:46 +0100 Subject: [PATCH] refactor: moved startup from rtos2-utils to TACOS --- README.md | 6 ++--- include/sta/tacos/c_api/startup.h | 22 +++++++++++++++++ src/startup.cpp | 40 +++++++++++++++++++++++++------ 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 include/sta/tacos/c_api/startup.h diff --git a/README.md b/README.md index 5fec4c4..0a16532 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ Properties -> C/C++ General -> Paths and Symbols -> Includes -> GNU C++ -> Add.. Properties -> C/C++ General -> Paths and Symbols -> Source Location -> Add Folder... ``` -Create a new thread via the project's IOC and call `startALPAKA()` from this thread. If your thread is called `defaultTask`, the corresponding function `StartDefaultTask` generated in `Core/Src/freertos.c` should look like this: +Create a new thread via the project's IOC and call `startTACOS()` from this thread. If your thread is called `defaultTask`, the corresponding function `StartDefaultTask` generated in `Core/Src/freertos.c` should look like this: ``` void StartDefaultTask(void *argument) { /* USER CODE BEGIN StartDefaultTask */ - extern void startALPAKA(void *); - startALPAKA(argument); + extern void startTACOS(void *); + startTACOS(argument); /* Infinite loop */ for(;;) diff --git a/include/sta/tacos/c_api/startup.h b/include/sta/tacos/c_api/startup.h new file mode 100644 index 0000000..3876718 --- /dev/null +++ b/include/sta/tacos/c_api/startup.h @@ -0,0 +1,22 @@ +#ifndef STA_TACOS_C_API_STARTUP_H +#define STA_TACOS_C_API_STARTUP_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @brief + * + * @param arg Default task argument + */ +void startTACOS(void * arg); + + +#ifdef __cplusplus +} +#endif + + +#endif // STA_TACOS_C_API_STARTUP_H diff --git a/src/startup.cpp b/src/startup.cpp index 6934df5..0f450f5 100644 --- a/src/startup.cpp +++ b/src/startup.cpp @@ -21,11 +21,18 @@ // sta-core-specific imports. #include +#include #include #include +#include #include +// rtos2-utils-specific includes. +#include +#include + // Tacos-specific includes. +#include #include #include #include @@ -72,7 +79,7 @@ namespace sta STM32UART * intf_ptr = new STM32UART(getUARThandle(), settings, mutex); Debug = new PrintableUART(intf_ptr); } - } + } // namespace tacos #endif // STA_DEBUGGING_ENABLED namespace tacos @@ -142,12 +149,7 @@ namespace sta CanBus::instance()->start(); } #endif //STA_TACOS_CAN_BUS_ENABLED - } // namespace tacos - - namespace rtos - { - // Override the weak implementation of startupExtras provided in rtos2-utils. void startupExtras(void * argument) { #ifdef STA_DEBUGGING_ENABLED @@ -166,7 +168,31 @@ namespace sta tacos::initCanBus(); #endif // STA_TACOS_CAN_BUS_ENABLED } - } // namespace rtos + } // namespace tacos } // namespace sta +void startTACOS(void * arg) +{ + STA_ASSERT_MSG(osKernelGetState() != osKernelInactive, "Cannot call startTACOS() before osKernelInitialize()"); + // Initialize HAL + sta::initHAL(); + + // Initialize RTOS system resources + sta::rtos::initSystem(); + + // Call further initialization code + sta::tacos::startupExtras(arg); + + // Wake threads +#ifdef STA_RTOS_SYSTEM_EVENTS_ENABLE + sta::rtos::signalStartupEvent(); +#endif // STA_RTOS_SYSTEM_EVENTS_ENABLE + + // Check if called from thread + if (osThreadGetId() != nullptr) + { + // Terminate current thread + osThreadExit(); + } +}