CAN Bus shifted to TACOS from rtos

This commit is contained in:
@CarlWachter 2024-02-16 14:44:29 +01:00
parent db43a3c7df
commit 7da60dc85e
4 changed files with 40 additions and 31 deletions

View File

@ -50,7 +50,7 @@ In order to use TACOS, you need to provide a configuration file in the path `sta
#define STA_RTOS_SYSTEM_EVENTS_ENABLE
// #define STA_RTOS_SYSTEM_WATCHDOG_ENABLE
// #define STA_RTOS_WATCHDOG_ENABLE
#define STA_RTOS_CAN_BUS_ENABLE
#define STA_CAN_BUS_ENABLE
// Statemachine settings.
#define STA_TACOS_NUM_STATES 3

View File

@ -3,7 +3,7 @@
#include <sta/config.hpp>
#ifdef STA_RTOS_CAN_BUS_ENABLE
#ifdef STA_CAN_BUS_ENABLE
#include <sta/tacos/thread.hpp>
#include <sta/rtos/queue.hpp>
@ -127,5 +127,5 @@ namespace sta
} /* namespace sta */
#endif /* STA_RTOS_CAN_BUS_ENABLE */
#endif /* STA_CAN_BUS_ENABLE */
#endif /* INCLUDE_TACOS_CAN_BUS_HPP_ */

View File

@ -1,24 +1,11 @@
#include <sta/config.hpp>
#ifdef STA_RTOS_CAN_BUS_ENABLE
#ifdef STA_CAN_BUS_ENABLE
#include <sta/tacos/can_bus.hpp>
#include <sta/rtos/system/can_bus.hpp>
#include <sta/debug/debug.hpp>
#include <sta/debug/assert.hpp>
namespace sta
{
namespace rtos
{
void initCanBus()
{
sta::tacos::CanBus::instance(getCanController())->start();
}
} // namespace rtos
} // namespace sta
namespace sta
{
namespace tacos
@ -206,4 +193,4 @@ namespace sta {
} // namespace tacos
} // namespace sta
#endif // STA_RTOS_CAN_BUS_ENABLE
#endif // STA_CAN_BUS_ENABLE

View File

@ -29,7 +29,10 @@
#include <sta/tacos/manager.hpp>
#include <sta/tacos/statemachine.hpp>
#include <sta/tacos/watchdog.hpp>
#include <sta/tacos/can_bus.hpp>
// TODO: WHY DO I HAVE TO PUT THIS HERE???? DO YOU THINK YOU ARE SPECIAL, HUH MR. HCAN1? WHY CAN'T YOU BE NORMAL LIKE HUART
extern CAN_HandleTypeDef hcan1;
// The UART mutex defined in freertos.c
extern osMutexId_t uartMutexHandle;
@ -39,12 +42,6 @@ extern osMutexId_t uartMutexHandle;
* @ingroup tacos
* @brief Functions that are called during startup.
*/
// CAN Handle
#ifdef STA_RTOS_CAN_BUS_ENABLE
extern CAN_HandleTypeDef hcan1;
#endif /* STA_RTOS_CAN_BUS_ENABLE */
namespace sta
{
#ifdef STA_DEBUGGING_ENABLED
@ -63,6 +60,18 @@ namespace sta
return &STA_STM32_USART_HANDLE;
}
#if defined(STA_CAN_BUS_ENABLE) || defined(DOXYGEN)
/**
* @brief Function that returns the CAN handle used for the CAN bus. Override it in userspace to adjust.
*
* @ingroup tacos_startup
*/
STA_WEAK
CAN_HandleTypeDef * getCanController(){
return &STA_STM32_CAN_HANDLE;
}
#endif /* STA_CAN_BUS_ENABLE */
/**
* @brief Function that initializes the printable object given by getUARThandle().
*
@ -134,6 +143,23 @@ namespace sta
extern CAN_HandleTypeDef hcan1;
return new STM32CanController(&hcan1);
}
/**
* @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(getCanController())->start();
}
} // namespace tacos
@ -153,15 +179,11 @@ namespace sta
#ifdef STA_TACOS_WATCHDOG_ENABLED
tacos::initWatchdog();
#endif // STA_TACOS_WATCHDOG_ENABLED
}
#ifdef STA_RTOS_CAN_BUS_ENABLE
STA_WEAK
CAN_HandleTypeDef * getCanController(){
return &hcan1;
#ifdef STA_CAN_BUS_ENABLE
tacos::initCanBus();
#endif // STA_CAN_BUS_ENABLE
}
#endif /* STA_RTOS_CAN_BUS_ENABLE */
} // namespace rtos
} // namespace sta