Skip to content

Commit

Permalink
Move tick blocking to project specific binding
Browse files Browse the repository at this point in the history
  • Loading branch information
samparent97 committed Apr 20, 2024
1 parent 55cbc74 commit cd62aeb
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 57 deletions.
15 changes: 0 additions & 15 deletions firmware/mcal/raspi/os/tick_blocking.cc

This file was deleted.

16 changes: 0 additions & 16 deletions firmware/mcal/stm32f767/os/tick_blocking.cc

This file was deleted.

15 changes: 0 additions & 15 deletions firmware/mcal/windows/os/tick_blocking.cc

This file was deleted.

8 changes: 3 additions & 5 deletions firmware/projects/DemoCanBar/main.cc
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
/// @author Samuel Parent
/// @date 2024-01-16

#include <sys/_stdint.h>
#include <cstdint>

#include "generated/can/can_messages.h"
#include "generated/can/msg_registry.h"
#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{};
Expand All @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions firmware/projects/DemoCanBar/platforms/raspi/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "mcal/raspi/periph/can.h"
#include "shared/periph/can.h"

#include <chrono>
#include <thread>

namespace mcal {
using namespace raspi::periph;

Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions firmware/projects/DemoCanBar/platforms/stm32f767/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions firmware/projects/DemoCanBar/platforms/windows/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "mcal/windows/periph/can.h"
#include "shared/periph/can.h"

#include <chrono>
#include <thread>

namespace mcal {
using namespace windows::periph;

Expand All @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions firmware/projects/DemoCanFoo/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand All @@ -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();

Expand Down
9 changes: 9 additions & 0 deletions firmware/projects/DemoCanFoo/platforms/raspi/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "mcal/raspi/periph/can.h"
#include "shared/periph/can.h"

#include <chrono>
#include <thread>

namespace mcal {
using namespace raspi::periph;

Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions firmware/projects/DemoCanFoo/platforms/stm32f767/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions firmware/projects/DemoCanFoo/platforms/windows/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "mcal/windows/periph/can.h"
#include "shared/periph/can.h"

#include <chrono>
#include <thread>

namespace mcal {
using namespace windows::periph;

Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion firmware/shared/os/tick.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cd62aeb

Please sign in to comment.