Can bus start without handle

This commit is contained in:
@CarlWachter 2024-02-16 17:43:28 +01:00
parent bfba17245f
commit 16b2ed5a20
5 changed files with 30 additions and 17 deletions

View File

@ -11,6 +11,7 @@
#include <sta/tacos/thread.hpp> #include <sta/tacos/thread.hpp>
#include <sta/tacos/manager.hpp> #include <sta/tacos/manager.hpp>
#include <sta/tacos/statemachine.hpp> #include <sta/tacos/statemachine.hpp>
#include <sta/tacos/can_bus.hpp>
#include <initializer_list> #include <initializer_list>
#include <type_traits> #include <type_traits>
@ -76,6 +77,8 @@ namespace sta
return thread_ptr; return thread_ptr;
} }
//bool queueCanBusMsg(const CanDataMsg & msg, uint32_t timeout);
} // namespace tacos } // namespace tacos
} }

View File

@ -32,19 +32,19 @@ namespace sta
{ {
public: public:
CanBus(CAN_HandleTypeDef * controller); CanBus();
/** /**
* @brief Getter function for the singleton instance. * @brief Getter function for the singleton instance.
*/ */
static CanBus* instance(CAN_HandleTypeDef * handle) static CanBus* instance()
{ {
static CGuard g; static CGuard g;
if (!_instance) if (!_instance)
{ {
// Create the can bus singleton instance. // Create the can bus singleton instance.
CanBus::_instance = new CanBus(handle); CanBus::_instance = new CanBus();
} }
return _instance; return _instance;
@ -115,7 +115,7 @@ namespace sta
AlpakaCanBus canBus_; AlpakaCanBus canBus_;
static RtosEvent messageEvent;
}; };

View File

@ -2,17 +2,16 @@
#ifdef STA_CAN_BUS_ENABLE #ifdef STA_CAN_BUS_ENABLE
#include <sta/tacos/can_bus.hpp> #include <sta/tacos/can_bus.hpp>
#include <sta/rtos/system/can_bus.hpp>
#include <sta/debug/debug.hpp>
#include <sta/debug/assert.hpp> #include <sta/debug/assert.hpp>
// TODO fix this shit
extern CAN_HandleTypeDef hcan1;
namespace sta namespace sta
{ {
namespace tacos namespace tacos
{ {
CanBus::CanBus(CAN_HandleTypeDef * controller) CanBus::CanBus()
: TacosThread{"Can Bus", STA_TACOS_CAN_BUS_PRIORITY}, : TacosThread{"Can Bus", STA_TACOS_CAN_BUS_PRIORITY},
canBusController_(new STM32CanController(controller)), canBusController_(new STM32CanController(&STA_STM32_CAN_HANDLE)),
canBusSysQueue_(STA_RTOS_CAN_BUS_QUEUE_LENGTH), canBusSysQueue_(STA_RTOS_CAN_BUS_QUEUE_LENGTH),
canBusDataQueue_(STA_RTOS_CAN_BUS_QUEUE_LENGTH), canBusDataQueue_(STA_RTOS_CAN_BUS_QUEUE_LENGTH),
canBus_{canBusController_, HAL_GetTick, sta::tacos::handleSysMessage, sta::tacos::handleDataMessage} canBus_{canBusController_, HAL_GetTick, sta::tacos::handleSysMessage, sta::tacos::handleDataMessage}
@ -26,8 +25,10 @@ namespace sta
void CanBus::func() void CanBus::func()
{ {
uint32_t flags = osThreadFlagsWait(STA_RTOS_THREAD_FLAGS_VALID_BITS, osFlagsWaitAny, 50); messageEvent.clear(STA_RTOS_CAN_ANY);
uint32_t flags = messageEvent.wait(STA_RTOS_CAN_ANY, osWaitForever);
STA_DEBUG_PRINTLN("CanBus received Flag");
if (flags != static_cast<uint32_t>(osErrorTimeout)) if (flags != static_cast<uint32_t>(osErrorTimeout))
{ {
STA_ASSERT_MSG((flags & osStatusReserved) == flags, "Unexpected error occurred in wait"); STA_ASSERT_MSG((flags & osStatusReserved) == flags, "Unexpected error occurred in wait");
@ -38,6 +39,7 @@ namespace sta
CanSysMsg msg; CanSysMsg msg;
while (CanBus::_instance->getCanBusMsg(&msg, 0)) while (CanBus::_instance->getCanBusMsg(&msg, 0))
{ {
STA_DEBUG_PRINTLN("CanBus about to send");
canBus_.send(msg); canBus_.send(msg);
} }
} }
@ -76,8 +78,9 @@ namespace sta
if (canBusDataQueue_.put(msg, timeout)) if (canBusDataQueue_.put(msg, timeout))
{ {
// Signal thread // Signal task
notify(STA_RTOS_CAN_FLAG_DATA_QUEUED); messageEvent.set(STA_RTOS_CAN_FLAG_DATA_QUEUED);
messageEvent.clear(STA_RTOS_CAN_ANY);
return true; return true;
} }
else else
@ -92,8 +95,9 @@ namespace sta
if (canBusSysQueue_.put(msg, timeout)) if (canBusSysQueue_.put(msg, timeout))
{ {
// Signal thread // Signal tasek
notify(STA_RTOS_CAN_FLAG_SYS_QUEUED); messageEvent.set(STA_RTOS_CAN_FLAG_SYS_QUEUED);
messageEvent.clear(STA_RTOS_CAN_ANY);
return true; return true;
} }
else else
@ -115,6 +119,8 @@ namespace sta
CanBus* CanBus::_instance = nullptr; CanBus* CanBus::_instance = nullptr;
RtosEvent CanBus::messageEvent;
} /* namespace tacos */ } /* namespace tacos */
} /* namespace sta */ } /* namespace sta */
@ -193,4 +199,4 @@ namespace sta {
} // namespace tacos } // namespace tacos
} // namespace sta } // namespace sta
#endif // STA_CAN_BUS_ENABLE #endif // STA_CAN_BUS_ENABLE

View File

@ -154,7 +154,7 @@ namespace sta
{ {
onCanBusInit(); onCanBusInit();
CanBus::instance(getCanController())->start(); CanBus::instance()->start();
} }
#endif //STA_CAN_BUS_ENABLE #endif //STA_CAN_BUS_ENABLE
} // namespace tacos } // namespace tacos

View File

@ -7,7 +7,6 @@
#include <sta/tacos.hpp> #include <sta/tacos.hpp>
namespace sta namespace sta
{ {
namespace tacos namespace tacos
@ -26,6 +25,11 @@ namespace sta
{ {
Statemachine::instance()->requestTimedStateTransition(from, to, millis, lockout); Statemachine::instance()->requestTimedStateTransition(from, to, millis, lockout);
} }
/*bool queueCanBusMsg(const CanDataMsg & msg, uint32_t timeout){
//extern CAN_HandleTypeDef hcan1;
//return CanBus::instance(STA_STM32_CAN_HANDLE)->queueCanBusMsg(msg, timeout);
return false;
}*/
} // namespace tacos } // namespace tacos
} // namespace sta } // namespace sta