/* * startup.cpp * * Created on: 22 Sep 2023 * Author: Dario */ /** * @defgroup tacos TACOS Library * @brief TACOS library * * @details This library contains the internal functions of TACOS. It is not intended to be used by the user, but is documented rather for anyone wanting to contribute to the project. */ #include #include #include #include // sta-core-specific imports. #include #include #include #include // Tacos-specific includes. #include #include #include #include // The UART mutex defined in freertos.c extern osMutexId_t uartMutexHandle; /** * @defgroup tacos_startup Startup * @ingroup tacos * @brief Functions that are called during startup. */ namespace sta { #ifdef STA_DEBUGGING_ENABLED // Here the printable used for debugging is defined. Printable * Debug; namespace tacos { /** * @brief Function that returns the UART handle used for debugging. Override it in userspace to adjust. * * @ingroup tacos_startup */ STA_WEAK UART_HandleTypeDef * getUARThandle(){ return &STA_STM32_USART_HANDLE; } /** * @brief Function that initializes the printable object given by getUARThandle(). * * @ingroup tacos_startup */ void initPrintable() { // Initialize the mutex for UART communication. RtosMutex * mutex = new RtosMutex("uart"); // Initialize the UART interface and printable object. UARTSettings settings = { .mode = UARTMode::RX_TX }; STM32UART * intf_ptr = new STM32UART(getUARThandle(), settings, mutex); Debug = new PrintableUART(intf_ptr); } } #endif // STA_DEBUGGING_ENABLED namespace tacos { /** * @brief Function that is called before the statemachine task is started. Override it to * adjust the statemachine to your specifications. * * @ingroup tacos_startup */ STA_WEAK void onStatemachineInit() {} void initStatemachine() { onStatemachineInit(); Statemachine::instance()->start(); } /** * @brief Function that is called before the manager task is started. Override it to adjust * the manager to your specifications. * * @ingroup tacos_startup */ STA_WEAK void onManagerInit() {} void initManager() { onManagerInit(); Manager::instance()->start(); } #ifdef STA_TACOS_WATCHDOG_ENABLED STA_WEAK void onWatchdogInit() {} void initWatchdog() { onWatchdogInit(); Watchdog::instance()->start(); } #endif // STA_TACOS_WATCHDOG_ENABLED #ifdef STA_CAN_BUS_ENABLE /** * @brief Function that is called before the Can Bus task is started. Override it to adjust * the Can bus to your specifications. * * @ingroup tacos_startup */ STA_WEAK void onCanBusInit() {} void initCanBus() { onCanBusInit(); CanBus::instance()->start(); } #endif //STA_CAN_BUS_ENABLE } // namespace tacos namespace rtos { // Override the weak implementation of startupExtras provided in rtos2-utils. void startupExtras(void * argument) { #ifdef STA_DEBUGGING_ENABLED tacos::initPrintable(); #endif // STA_DEBUGGING_ENABLED tacos::initStatemachine(); tacos::initManager(); #ifdef STA_TACOS_WATCHDOG_ENABLED tacos::initWatchdog(); #endif // STA_TACOS_WATCHDOG_ENABLED #ifdef STA_CAN_BUS_ENABLE tacos::initCanBus(); #endif // STA_CAN_BUS_ENABLE } } // namespace rtos } // namespace sta