From cd62aeb951136151963c3c06e492b73067a7d809 Mon Sep 17 00:00:00 2001 From: samparent97 Date: Sat, 20 Apr 2024 18:32:34 -0400 Subject: [PATCH] Move tick blocking to project specific binding --- firmware/mcal/raspi/os/tick_blocking.cc | 15 --------------- firmware/mcal/stm32f767/os/tick_blocking.cc | 16 ---------------- firmware/mcal/windows/os/tick_blocking.cc | 15 --------------- firmware/projects/DemoCanBar/main.cc | 8 +++----- .../DemoCanBar/platforms/raspi/bindings.cc | 9 +++++++++ .../DemoCanBar/platforms/stm32f767/bindings.cc | 4 ++++ .../DemoCanBar/platforms/windows/bindings.cc | 10 ++++++++++ firmware/projects/DemoCanFoo/main.cc | 7 ++----- .../DemoCanFoo/platforms/raspi/bindings.cc | 9 +++++++++ .../DemoCanFoo/platforms/stm32f767/bindings.cc | 5 +++++ .../DemoCanFoo/platforms/windows/bindings.cc | 10 ++++++++++ firmware/shared/os/tick.h | 1 - 12 files changed, 52 insertions(+), 57 deletions(-) delete mode 100644 firmware/mcal/raspi/os/tick_blocking.cc delete mode 100644 firmware/mcal/stm32f767/os/tick_blocking.cc delete mode 100644 firmware/mcal/windows/os/tick_blocking.cc diff --git a/firmware/mcal/raspi/os/tick_blocking.cc b/firmware/mcal/raspi/os/tick_blocking.cc deleted file mode 100644 index e81eebd56..000000000 --- a/firmware/mcal/raspi/os/tick_blocking.cc +++ /dev/null @@ -1,15 +0,0 @@ -/// @author Samuel Parent -/// @date 2024-04-15 - -#include -#include -#include -#include - -namespace os { -void TickBlocking(uint32_t ticks) { - std::chrono::milliseconds duration(ticks); - - std::this_thread::sleep_for(duration); -} -} // namespace os diff --git a/firmware/mcal/stm32f767/os/tick_blocking.cc b/firmware/mcal/stm32f767/os/tick_blocking.cc deleted file mode 100644 index 5b4e4e437..000000000 --- a/firmware/mcal/stm32f767/os/tick_blocking.cc +++ /dev/null @@ -1,16 +0,0 @@ -/// @author Samuel Parent -/// @date 2024-04-15 - -#include - -#include "stm32f7xx_hal.h" - -/// @note This file should be left seperate from tick.h -/// as it allows for timing control in projects that -/// do not make use of an RTOS. - -namespace os { -void TickBlocking(uint32_t ticks) { - HAL_Delay(ticks); -} -} // namespace os diff --git a/firmware/mcal/windows/os/tick_blocking.cc b/firmware/mcal/windows/os/tick_blocking.cc deleted file mode 100644 index e81eebd56..000000000 --- a/firmware/mcal/windows/os/tick_blocking.cc +++ /dev/null @@ -1,15 +0,0 @@ -/// @author Samuel Parent -/// @date 2024-04-15 - -#include -#include -#include -#include - -namespace os { -void TickBlocking(uint32_t ticks) { - std::chrono::milliseconds duration(ticks); - - std::this_thread::sleep_for(duration); -} -} // namespace os diff --git a/firmware/projects/DemoCanBar/main.cc b/firmware/projects/DemoCanBar/main.cc index 5e6dcf8ff..ccce5263c 100644 --- a/firmware/projects/DemoCanBar/main.cc +++ b/firmware/projects/DemoCanBar/main.cc @@ -1,6 +1,7 @@ /// @author Samuel Parent /// @date 2024-01-16 +#include #include #include "generated/can/can_messages.h" @@ -8,13 +9,10 @@ #include "shared/comms/can/can_bus.h" #include "shared/os/tick.h" -namespace os { -extern void TickBlocking(uint32_t ticks); -} - namespace bindings { extern shared::periph::CanBase& veh_can_base; extern void Initialize(); +extern void TickBlocking(uint32_t); } // namespace bindings generated::can::VehMsgRegistry veh_can_registry{}; @@ -32,7 +30,7 @@ int main(void) { generated::can::TempSensorsReply temp_sens_msg_reply{}; while (true) { - os::TickBlocking(tick_duration); + bindings::TickBlocking(tick_duration); veh_can_bus.Update(); veh_can_bus.Read(temp_sens_msg); diff --git a/firmware/projects/DemoCanBar/platforms/raspi/bindings.cc b/firmware/projects/DemoCanBar/platforms/raspi/bindings.cc index 04237ede5..cbd799c58 100644 --- a/firmware/projects/DemoCanBar/platforms/raspi/bindings.cc +++ b/firmware/projects/DemoCanBar/platforms/raspi/bindings.cc @@ -4,6 +4,9 @@ #include "mcal/raspi/periph/can.h" #include "shared/periph/can.h" +#include +#include + namespace mcal { using namespace raspi::periph; @@ -13,6 +16,12 @@ CanBase veh_can_base{"vcan0"}; namespace bindings { shared::periph::CanBase& veh_can_base = mcal::veh_can_base; +void TickBlocking(uint32_t ticks) { + std::chrono::milliseconds duration(ticks); + + std::this_thread::sleep_for(duration); +} + void Initialize() { mcal::veh_can_base.Setup(); std::cout << "Initializing raspi..." << std::endl; diff --git a/firmware/projects/DemoCanBar/platforms/stm32f767/bindings.cc b/firmware/projects/DemoCanBar/platforms/stm32f767/bindings.cc index 539859d96..34736d32f 100644 --- a/firmware/projects/DemoCanBar/platforms/stm32f767/bindings.cc +++ b/firmware/projects/DemoCanBar/platforms/stm32f767/bindings.cc @@ -35,6 +35,10 @@ void Initialize() { mcal::veh_can_base.Setup(); } +void TickBlocking(uint32_t ticks) { + HAL_Delay(ticks); +} + extern "C" { void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* hcan) { if (hcan == &hcan3) { diff --git a/firmware/projects/DemoCanBar/platforms/windows/bindings.cc b/firmware/projects/DemoCanBar/platforms/windows/bindings.cc index 56749015d..5fa2d8af0 100644 --- a/firmware/projects/DemoCanBar/platforms/windows/bindings.cc +++ b/firmware/projects/DemoCanBar/platforms/windows/bindings.cc @@ -4,6 +4,9 @@ #include "mcal/windows/periph/can.h" #include "shared/periph/can.h" +#include +#include + namespace mcal { using namespace windows::periph; @@ -13,6 +16,13 @@ CanBase veh_can_base{"vcan0"}; namespace bindings { shared::periph::CanBase& veh_can_base = mcal::veh_can_base; + +void TickBlocking(uint32_t ticks) { + std::chrono::milliseconds duration(ticks); + + std::this_thread::sleep_for(duration); +} + void Initialize() { mcal::veh_can_base.Setup(); std::cout << "Initializing windows..." << std::endl; diff --git a/firmware/projects/DemoCanFoo/main.cc b/firmware/projects/DemoCanFoo/main.cc index 3028feeb8..7ab7376e5 100644 --- a/firmware/projects/DemoCanFoo/main.cc +++ b/firmware/projects/DemoCanFoo/main.cc @@ -8,13 +8,10 @@ #include "shared/comms/can/can_bus.h" #include "shared/os/tick.h" -namespace os { -extern void TickBlocking(uint32_t ticks); -} - namespace bindings { extern shared::periph::CanBase& veh_can_base; extern void Initialize(); +extern void TickBlocking(uint32_t); } // namespace bindings generated::can::VehMsgRegistry veh_can_registry{}; @@ -31,7 +28,7 @@ int main(void) { generated::can::TempSensors temp_sens_msg{}; while (true) { - os::TickBlocking(tick_duration); + bindings::TickBlocking(tick_duration); veh_can_bus.Update(); diff --git a/firmware/projects/DemoCanFoo/platforms/raspi/bindings.cc b/firmware/projects/DemoCanFoo/platforms/raspi/bindings.cc index 04237ede5..cbd799c58 100644 --- a/firmware/projects/DemoCanFoo/platforms/raspi/bindings.cc +++ b/firmware/projects/DemoCanFoo/platforms/raspi/bindings.cc @@ -4,6 +4,9 @@ #include "mcal/raspi/periph/can.h" #include "shared/periph/can.h" +#include +#include + namespace mcal { using namespace raspi::periph; @@ -13,6 +16,12 @@ CanBase veh_can_base{"vcan0"}; namespace bindings { shared::periph::CanBase& veh_can_base = mcal::veh_can_base; +void TickBlocking(uint32_t ticks) { + std::chrono::milliseconds duration(ticks); + + std::this_thread::sleep_for(duration); +} + void Initialize() { mcal::veh_can_base.Setup(); std::cout << "Initializing raspi..." << std::endl; diff --git a/firmware/projects/DemoCanFoo/platforms/stm32f767/bindings.cc b/firmware/projects/DemoCanFoo/platforms/stm32f767/bindings.cc index 539859d96..0dda3f269 100644 --- a/firmware/projects/DemoCanFoo/platforms/stm32f767/bindings.cc +++ b/firmware/projects/DemoCanFoo/platforms/stm32f767/bindings.cc @@ -35,6 +35,11 @@ void Initialize() { mcal::veh_can_base.Setup(); } +void TickBlocking(uint32_t ticks) { + HAL_Delay(ticks); +} + + extern "C" { void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* hcan) { if (hcan == &hcan3) { diff --git a/firmware/projects/DemoCanFoo/platforms/windows/bindings.cc b/firmware/projects/DemoCanFoo/platforms/windows/bindings.cc index 56749015d..5fa2d8af0 100644 --- a/firmware/projects/DemoCanFoo/platforms/windows/bindings.cc +++ b/firmware/projects/DemoCanFoo/platforms/windows/bindings.cc @@ -4,6 +4,9 @@ #include "mcal/windows/periph/can.h" #include "shared/periph/can.h" +#include +#include + namespace mcal { using namespace windows::periph; @@ -13,6 +16,13 @@ CanBase veh_can_base{"vcan0"}; namespace bindings { shared::periph::CanBase& veh_can_base = mcal::veh_can_base; + +void TickBlocking(uint32_t ticks) { + std::chrono::milliseconds duration(ticks); + + std::this_thread::sleep_for(duration); +} + void Initialize() { mcal::veh_can_base.Setup(); std::cout << "Initializing windows..." << std::endl; diff --git a/firmware/shared/os/tick.h b/firmware/shared/os/tick.h index 058559a50..24fb85c21 100644 --- a/firmware/shared/os/tick.h +++ b/firmware/shared/os/tick.h @@ -6,7 +6,6 @@ namespace os { void Tick(uint32_t ticks); void TickUntil(uint32_t ticks); -void TickBlocking(uint32_t ticks); uint32_t GetTickCount(); } // namespace os