TACOS/src/startup.cpp
2024-01-06 15:24:22 +01:00

136 lines
2.8 KiB
C++

/*
* 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 <sta/config.hpp>
#include <cmsis_os2.h>
#include <usart.h>
#include <sta/rtos/mutex.hpp>
// sta-core-specific imports.
#include <sta/devices/stm32/bus/uart.hpp>
#include <sta/debug/printing/printable_uart.hpp>
#include <sta/debug/debug.hpp>
#include <sta/lang.hpp>
// Tacos-specific includes.
#include <sta/tacos/manager.hpp>
#include <sta/tacos/statemachine.hpp>
// 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);
STA_DEBUG_PRINTLN("UART SUCCESSFULLY INITIALIZED");
}
}
#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();
}
} // 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();
}
} // namespace rtos
} // namespace sta