From 96e9213b1a3bb0b0aa5cd63cc67a823d6abc2529 Mon Sep 17 00:00:00 2001 From: dario Date: Fri, 1 Sep 2023 22:39:14 +0200 Subject: [PATCH] Added basic task creating in manager task --- App/Inc/sta/config.hpp | 1 + App/Src/tasks/manager.cpp | 19 ++++++++++++++++++- App/Src/tasks/output.cpp | 10 ++++++---- App/Src/tasks/watchdog.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 App/Src/tasks/watchdog.cpp diff --git a/App/Inc/sta/config.hpp b/App/Inc/sta/config.hpp index 7bc5507..9db0927 100644 --- a/App/Inc/sta/config.hpp +++ b/App/Inc/sta/config.hpp @@ -25,5 +25,6 @@ // Settings for the rtos-utils #define STA_RTOS_SYSTEM_EVENTS_ENABLE #define STA_RTOS_SYSTEM_WATCHDOG_ENABLE +#define STA_RTOS_WATCHDOG_ENABLE #endif /* INC_STA_CONFIG_HPP_ */ diff --git a/App/Src/tasks/manager.cpp b/App/Src/tasks/manager.cpp index cd18f39..6a76842 100644 --- a/App/Src/tasks/manager.cpp +++ b/App/Src/tasks/manager.cpp @@ -16,8 +16,17 @@ typedef StaticTask_t osStaticThreadDef_t; + extern "C" void outputTask(void *); + +void startWorker(void *arg) +{ + STA_DEBUG_PRINTLN("STARTED WORKER!"); + + osThreadExit(); +} + extern "C" void startManagerTask(void *) { STA_DEBUG_PRINTLN("INITIALIZED MANAGER TASK"); @@ -40,9 +49,17 @@ extern "C" void startManagerTask(void *) STA_ASSERT_MSG(outputTaskHandle != nullptr, "outputTask initialization failed"); */ + // Create thread using static allocation + const osThreadAttr_t workerAttributes = {}; + + for (uint8_t i = 0; i < 5; i++) + { + osThreadNew(startWorker, NULL, &workerAttributes); + } + while (true) { - STA_DEBUG_PRINTLN("PING!"); + // STA_DEBUG_PRINTLN("MANAGING!"); } osThreadExit(); diff --git a/App/Src/tasks/output.cpp b/App/Src/tasks/output.cpp index a8a2ec2..8c9854b 100644 --- a/App/Src/tasks/output.cpp +++ b/App/Src/tasks/output.cpp @@ -9,14 +9,16 @@ #include #include +#include + extern "C" void outputTask(void *) { - std::string str("Hello World!"); - - for (char c : str) + while (true) { - HAL_UART_Transmit(&huart2, (uint8_t*)&c, 1, HAL_MAX_DELAY); + STA_DEBUG_PRINTLN("OUTPUT TASK RUNNING"); + + osThreadYield(); } osThreadExit(); diff --git a/App/Src/tasks/watchdog.cpp b/App/Src/tasks/watchdog.cpp new file mode 100644 index 0000000..e785bce --- /dev/null +++ b/App/Src/tasks/watchdog.cpp @@ -0,0 +1,24 @@ +/* + * watchdog.cpp + * + * Created on: Sep 1, 2023 + * Author: Dario + */ + +#include +#include + +namespace sta +{ + namespace rtos + { + // Implementation of the watchdog event handler. + void watchdogEventHandler(void *, uint32_t flags) + { + if (flags & STA_WATCHDOG_FLAG_HEARTBEAT) + { + STA_DEBUG_PRINTLN("PING!"); + } + } + } +} // namespace sta