refactor: moved startup from rtos2-utils to TACOS

This commit is contained in:
CarlWachter 2024-11-03 12:43:46 +01:00 committed by carlwachter
parent fa3f420fa6
commit 4ac600d2b7
3 changed files with 58 additions and 10 deletions

View File

@ -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(;;)

View File

@ -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

View File

@ -21,11 +21,18 @@
// sta-core-specific imports.
#include <sta/devices/stm32/bus/uart.hpp>
#include <sta/devices/stm32/init.hpp>
#include <sta/debug/printing/printable_uart.hpp>
#include <sta/debug/debug.hpp>
#include <sta/debug/assert.hpp>
#include <sta/lang.hpp>
// rtos2-utils-specific includes.
#include <sta/rtos/system/startup.hpp>
#include <sta/rtos/system/events.hpp>
// Tacos-specific includes.
#include <sta/tacos/c_api/startup.h>
#include <sta/tacos/manager.hpp>
#include <sta/tacos/statemachine.hpp>
#include <sta/tacos/watchdog.hpp>
@ -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();
}
}