From 7da60dc85ed63d4ae934ca9e3575ea125ad30142 Mon Sep 17 00:00:00 2001 From: "@CarlWachter" Date: Fri, 16 Feb 2024 14:44:29 +0100 Subject: [PATCH] CAN Bus shifted to TACOS from rtos --- README.md | 2 +- include/sta/tacos/can_bus.hpp | 4 +-- src/can_bus.cpp | 17 ++----------- src/startup.cpp | 48 +++++++++++++++++++++++++---------- 4 files changed, 40 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index a765ae6..c99602f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/include/sta/tacos/can_bus.hpp b/include/sta/tacos/can_bus.hpp index aac82fd..82a9cd8 100644 --- a/include/sta/tacos/can_bus.hpp +++ b/include/sta/tacos/can_bus.hpp @@ -3,7 +3,7 @@ #include -#ifdef STA_RTOS_CAN_BUS_ENABLE +#ifdef STA_CAN_BUS_ENABLE #include #include @@ -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_ */ diff --git a/src/can_bus.cpp b/src/can_bus.cpp index 48ecfa2..c06a947 100644 --- a/src/can_bus.cpp +++ b/src/can_bus.cpp @@ -1,24 +1,11 @@ #include -#ifdef STA_RTOS_CAN_BUS_ENABLE +#ifdef STA_CAN_BUS_ENABLE #include #include #include #include -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 \ No newline at end of file +#endif // STA_CAN_BUS_ENABLE \ No newline at end of file diff --git a/src/startup.cpp b/src/startup.cpp index 0fda9b3..46f8490 100644 --- a/src/startup.cpp +++ b/src/startup.cpp @@ -29,7 +29,10 @@ #include #include #include +#include +// 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