Skip to content

Commit 71e3876

Browse files
committed
Added can mode selection
1 parent 2040d11 commit 71e3876

10 files changed

Lines changed: 27 additions & 15 deletions

File tree

firmware/boards/f0_module/bootloader/bootloader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ THD_FUNCTION(BootloaderThread, arg)
225225
(void)arg;
226226

227227
// turn on CAN
228-
canStart(&CAND1, &GetCanConfig());
228+
canStart(&CAND1, &GetCanConfig(0));
229229

230230
WaitForBootloaderCmd();
231231

firmware/boards/f0_module/port_shared.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ static const CANConfig canConfig500 =
1111
CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1),
1212
};
1313

14-
const CANConfig& GetCanConfig() {
14+
const CANConfig& GetCanConfig(uint8_t mode) {
1515
return canConfig500;
1616
}

firmware/boards/f1_dual/port_shared.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ static const CANConfig canConfig500 =
1111
CAN_BTR_SJW(0) | CAN_BTR_BRP(2) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1),
1212
};
1313

14-
const CANConfig& GetCanConfig() {
14+
const CANConfig& GetCanConfig(uint8_t mode) {
1515
return canConfig500;
1616
}

firmware/boards/f1_dual_rev1/port_shared.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ static const CANConfig canConfig1000 =
3939
};
4040

4141

42-
const CANConfig& GetCanConfig() {
43-
return canConfig500;
42+
const CANConfig& GetCanConfig(uint8_t mode) {
43+
mode &= 0x03;
44+
switch (mode) {
45+
case 0:
46+
return canConfig500;
47+
case 1:
48+
return canConfig1000;
49+
}
4450
}

firmware/boards/f1_rev2/port_shared.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ static const CANConfig canConfig500 =
1111
CAN_BTR_SJW(0) | CAN_BTR_BRP(4 - 1) | CAN_BTR_TS1(13 - 1) | CAN_BTR_TS2(2 - 1),
1212
};
1313

14-
const CANConfig& GetCanConfig() {
14+
const CANConfig& GetCanConfig(uint8_t mode) {
1515
return canConfig500;
1616
}

firmware/boards/f1_rev3/port_shared.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ static const CANConfig canConfig500 =
1111
CAN_BTR_SJW(0) | CAN_BTR_BRP(2) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1),
1212
};
1313

14-
const CANConfig& GetCanConfig() {
14+
const CANConfig& GetCanConfig(uint8_t mode) {
1515
return canConfig500;
1616
}

firmware/boards/port.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Configuration {
5858
private:
5959
// Increment this any time the configuration format changes
6060
// It is stored along with the data to ensure that it has been written before
61-
static constexpr uint32_t ExpectedTag = 0xDEADBE03;
61+
static constexpr uint32_t ExpectedTag = 0xDEADBE04;
6262
uint32_t Tag = ExpectedTag;
6363

6464
public:
@@ -75,6 +75,7 @@ class Configuration {
7575
*this = {};
7676

7777
NoLongerUsed0 = 0;
78+
CanMode = 0;
7879
sensorType = BOARD_DEFAULT_SENSOR_TYPE;
7980

8081
/* default auxout curve is 0..5V for AFR 8.5 to 18.0
@@ -119,7 +120,8 @@ class Configuration {
119120
// Actual configuration data
120121
union {
121122
struct {
122-
uint8_t NoLongerUsed0 = 0;
123+
uint8_t NoLongerUsed0 : 6 = 0;
124+
uint8_t CanMode : 2;
123125
// AUX0 and AUX1 curves
124126
float auxOutBins[2][8];
125127
float auxOutValues[2][8];

firmware/boards/port_shared.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
#include "hal.h"
66

7-
const CANConfig& GetCanConfig();
7+
const CANConfig& GetCanConfig(uint8_t mode);
88

99
#endif // WB_PROD

firmware/can.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void InitCan()
179179
{
180180
configuration = GetConfiguration();
181181

182-
canStart(&CAND1, &GetCanConfig());
182+
canStart(&CAND1, &GetCanConfig(configuration->CanMode));
183183
chThdCreateStatic(waCanTxThread, sizeof(waCanTxThread), NORMALPRIO, CanTxThread, nullptr);
184184
chThdCreateStatic(waCanRxThread, sizeof(waCanRxThread), NORMALPRIO - 4, CanRxThread, nullptr);
185185
}

firmware/ini/wideband_dual.ini

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ page = 1
6060

6161
; name = class, type, offset, [shape], units, scale, translate, min, max, digits
6262
; First four bytes are used for internal tag. Should not be accessable from TS
63-
CanIndexOffset = scalar, U08, 4, "", 1, 0, 0, 255, 0
63+
CanMode = bits, U08, 4, [7:8], "500kbps", "1000kbps", "INVALID", "INVALID"
6464
Aux0OutBins = array, F32, 5, [8], "", 1, 0, 0, 1500, 2
6565
Aux1OutBins = array, F32, 37, [8], "", 1, 0, 0, 1500, 2
6666
Aux0Out = array, F32, 69, [8], "V", 1, 0, 0, 5.0, 2
@@ -338,7 +338,8 @@ menuDialog = main
338338
menu = "&Settings"
339339
subMenu = sensor_settings, "Sensor settings"
340340
subMenu = heater_settings, "Heater settings"
341-
subMenu = can_settings, "CAN AFR settings"
341+
subMenu = can_speed_settings, "CAN Speed settings"
342+
subMenu = can_afr_settings, "CAN AFR settings"
342343
subMenu = can_egt_settings, "CAN EGT settings"
343344

344345
menu = "Outputs"
@@ -367,6 +368,9 @@ cmd_openblt = "Z\x00\xbc\x00\x00"
367368

368369
[UserDefined]
369370

371+
dialog = can_speed_settings, "Can Settings"
372+
field = "Speed", CanMode
373+
370374
dialog = sensor_settings, "Sensor Settings"
371375
field = "Sensor Type", LsuSensorType
372376

@@ -407,11 +411,11 @@ dialog = egt1_can_settings, "EGT 1 (right) channel CAN Settings"
407411
field = "Output EGT", AemNetEgtTx1
408412
field = "Device index (CAN ID is 0xA0305 + IDX)", AemNetEgtIdx1, { (AemNetEgtTx1 == 1) }, { 1 }, displayInHex
409413

410-
dialog = can_settings, "CAN AFR Settings", border
414+
dialog = can_afr_settings, "CAN AFR Settings", border
411415
panel = afr0_can_settings, West
412416
panel = afr1_can_settings, East
413417

414-
dialog = can_egt_settings, "CAN AFR Settings", border
418+
dialog = can_egt_settings, "CAN EGT Settings", border
415419
panel = egt0_can_settings, West
416420
panel = egt1_can_settings, East
417421

0 commit comments

Comments
 (0)