From 00cc305d02e6dae5abbfc9f2d8f334f6b12fe76b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 15 Mar 2023 18:07:31 -0700 Subject: [PATCH] GetCanConfig --- firmware/boards/f0_module/bootloader/bootloader.cpp | 2 +- firmware/boards/f0_module/port_shared.cpp | 6 +++++- firmware/boards/f1_dual/port_shared.cpp | 6 +++++- firmware/boards/f1_rev2/port_shared.cpp | 6 +++++- firmware/boards/f1_rev3/port_shared.cpp | 6 +++++- firmware/boards/port_shared.h | 2 +- firmware/can.cpp | 2 +- 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/firmware/boards/f0_module/bootloader/bootloader.cpp b/firmware/boards/f0_module/bootloader/bootloader.cpp index 47c933c..a507a42 100644 --- a/firmware/boards/f0_module/bootloader/bootloader.cpp +++ b/firmware/boards/f0_module/bootloader/bootloader.cpp @@ -222,7 +222,7 @@ THD_FUNCTION(BootloaderThread, arg) (void)arg; // turn on CAN - canStart(&CAND1, &canConfig500); + canStart(&CAND1, &GetCanConfig()); WaitForBootloaderCmd(); diff --git a/firmware/boards/f0_module/port_shared.cpp b/firmware/boards/f0_module/port_shared.cpp index 5fa0e8a..702da38 100644 --- a/firmware/boards/f0_module/port_shared.cpp +++ b/firmware/boards/f0_module/port_shared.cpp @@ -2,7 +2,7 @@ // board-specific stuff shared between bootloader and firmware -const CANConfig canConfig500 = +static const CANConfig canConfig500 = { CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, /* @@ -10,3 +10,7 @@ const CANConfig canConfig500 = */ CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1), }; + +const CANConfig& GetCanConfig() { + return canConfig500; +} diff --git a/firmware/boards/f1_dual/port_shared.cpp b/firmware/boards/f1_dual/port_shared.cpp index ad7927d..8647809 100644 --- a/firmware/boards/f1_dual/port_shared.cpp +++ b/firmware/boards/f1_dual/port_shared.cpp @@ -2,7 +2,7 @@ // board-specific stuff shared between bootloader and firmware -const CANConfig canConfig500 = +static const CANConfig canConfig500 = { CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, /* @@ -10,3 +10,7 @@ const CANConfig canConfig500 = */ CAN_BTR_SJW(0) | CAN_BTR_BRP(2) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1), }; + +const CANConfig& GetCanConfig() { + return canConfig500; +} diff --git a/firmware/boards/f1_rev2/port_shared.cpp b/firmware/boards/f1_rev2/port_shared.cpp index 3e2cbff..e8b98d1 100644 --- a/firmware/boards/f1_rev2/port_shared.cpp +++ b/firmware/boards/f1_rev2/port_shared.cpp @@ -2,7 +2,7 @@ // board-specific stuff shared between bootloader and firmware -const CANConfig canConfig500 = +static const CANConfig canConfig500 = { CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, /* @@ -10,3 +10,7 @@ const CANConfig canConfig500 = */ CAN_BTR_SJW(0) | CAN_BTR_BRP(4 - 1) | CAN_BTR_TS1(13 - 1) | CAN_BTR_TS2(2 - 1), }; + +const CANConfig& GetCanConfig() { + return canConfig500; +} diff --git a/firmware/boards/f1_rev3/port_shared.cpp b/firmware/boards/f1_rev3/port_shared.cpp index ad7927d..8647809 100644 --- a/firmware/boards/f1_rev3/port_shared.cpp +++ b/firmware/boards/f1_rev3/port_shared.cpp @@ -2,7 +2,7 @@ // board-specific stuff shared between bootloader and firmware -const CANConfig canConfig500 = +static const CANConfig canConfig500 = { CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, /* @@ -10,3 +10,7 @@ const CANConfig canConfig500 = */ CAN_BTR_SJW(0) | CAN_BTR_BRP(2) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1), }; + +const CANConfig& GetCanConfig() { + return canConfig500; +} diff --git a/firmware/boards/port_shared.h b/firmware/boards/port_shared.h index e04aa74..19c16f0 100644 --- a/firmware/boards/port_shared.h +++ b/firmware/boards/port_shared.h @@ -1,4 +1,4 @@ #include "ch.h" #include "hal.h" -extern const CANConfig canConfig500; \ No newline at end of file +const CANConfig& GetCanConfig(); diff --git a/firmware/can.cpp b/firmware/can.cpp index 815addc..184ff33 100644 --- a/firmware/can.cpp +++ b/firmware/can.cpp @@ -128,7 +128,7 @@ void InitCan() { configuration = GetConfiguration(); - canStart(&CAND1, &canConfig500); + canStart(&CAND1, &GetCanConfig()); chThdCreateStatic(waCanTxThread, sizeof(waCanTxThread), NORMALPRIO, CanTxThread, nullptr); chThdCreateStatic(waCanRxThread, sizeof(waCanRxThread), NORMALPRIO - 4, CanRxThread, nullptr); }