Skip to content

Commit b6fea28

Browse files
committed
Implement more CAN protocols
1 parent 7ccfdd8 commit b6fea28

26 files changed

Lines changed: 1184 additions & 330 deletions

firmware/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,13 @@ CPPSRC = $(ALLCPPSRC) \
150150
shared/flash.cpp \
151151
can.cpp \
152152
can_helper.cpp \
153-
can_aemnet.cpp \
154-
fault.cpp \
153+
can/can_aemnet.cpp \
154+
can/can_rusefi.cpp \
155+
can/can_ecumaster.cpp \
156+
can/can_haltech.cpp \
157+
can/can_motec.cpp \
158+
can/can_link.cpp \
159+
status.cpp \
155160
lambda_conversion.cpp \
156161
pwm.cpp \
157162
dac.cpp \

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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ static const CANConfig canConfig1000 =
3939
};
4040

4141

42-
const CANConfig& GetCanConfig() {
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+
}
50+
// default to 500kbps
4351
return canConfig500;
4452
}

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: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ enum class SensorType : uint8_t {
4141
LSUADV = 2,
4242
};
4343

44+
struct CanStatusData{
45+
HeaterAllow heaterAllow;
46+
float remoteBatteryVoltage;
47+
};
48+
4449
#ifndef BOARD_DEFAULT_SENSOR_TYPE
4550
#define BOARD_DEFAULT_SENSOR_TYPE SensorType::LSU49
4651
#endif
@@ -54,11 +59,22 @@ enum class AuxOutputMode : uint8_t {
5459
Egt1 = 5,
5560
};
5661

62+
enum class CanProtocol : uint8_t {
63+
None = 0,
64+
AemNet = 1, // for backward compatibility
65+
LinkEcu = 2,
66+
Haltech = 3,
67+
EcuMasterClassic = 4,
68+
EcuMasterBlack = 5,
69+
Motec = 6,
70+
Emtron = 7,
71+
};
72+
5773
class Configuration {
5874
private:
5975
// Increment this any time the configuration format changes
6076
// It is stored along with the data to ensure that it has been written before
61-
static constexpr uint32_t ExpectedTag = 0xDEADBE03;
77+
static constexpr uint32_t ExpectedTag = 0xDEADBE04;
6278
uint32_t Tag = ExpectedTag;
6379

6480
public:
@@ -75,6 +91,7 @@ class Configuration {
7591
*this = {};
7692

7793
NoLongerUsed0 = 0;
94+
CanMode = 0;
7895
sensorType = BOARD_DEFAULT_SENSOR_TYPE;
7996

8097
/* default auxout curve is 0..5V for AFR 8.5 to 18.0
@@ -92,9 +109,9 @@ class Configuration {
92109
afr[i].RusEfiTxDiag = true;
93110
afr[i].RusEfiIdx = i;
94111

95-
// Disable AemNet
96-
afr[i].AemNetTx = false;
97-
afr[i].AemNetIdOffset = i;
112+
// No extra protocol by default
113+
afr[i].ExtraCanProtocol = CanProtocol::None;
114+
afr[i].ExtraCanIdOffset = i;
98115
}
99116

100117
for (i = 0; i < EGT_CHANNELS; i++) {
@@ -103,9 +120,9 @@ class Configuration {
103120
egt[i].RusEfiTxDiag = false;
104121
egt[i].RusEfiIdx = i;
105122

106-
// Enable AemNet
107-
egt[i].AemNetTx = true;
108-
egt[i].AemNetIdOffset = i;
123+
// AemNet protocol by default
124+
egt[i].ExtraCanProtocol = CanProtocol::AemNet;
125+
egt[i].ExtraCanIdOffset = i;
109126
}
110127

111128
heaterConfig.HeaterSupplyOffVoltage = HEATER_SUPPLY_OFF_VOLTAGE;
@@ -119,7 +136,8 @@ class Configuration {
119136
// Actual configuration data
120137
union {
121138
struct {
122-
uint8_t NoLongerUsed0 = 0;
139+
uint8_t NoLongerUsed0 : 6 = 0;
140+
uint8_t CanMode : 2;
123141
// AUX0 and AUX1 curves
124142
float auxOutBins[2][8];
125143
float auxOutValues[2][8];
@@ -131,22 +149,24 @@ class Configuration {
131149
struct {
132150
bool RusEfiTx:1;
133151
bool RusEfiTxDiag:1;
134-
bool AemNetTx:1;
152+
CanProtocol ExtraCanProtocol:4;
153+
135154

136155
uint8_t RusEfiIdx;
137-
uint8_t AemNetIdOffset;
138-
uint8_t pad[5];
156+
uint8_t ExtraCanIdOffset;
157+
uint8_t Reserved[5];
139158
} afr[2];
140159

141160
// per EGT channel settings
142161
struct {
143162
bool RusEfiTx:1;
144163
bool RusEfiTxDiag:1;
145-
bool AemNetTx:1;
164+
CanProtocol ExtraCanProtocol:4;
165+
146166

147167
uint8_t RusEfiIdx;
148-
uint8_t AemNetIdOffset;
149-
uint8_t pad[5];
168+
uint8_t ExtraCanIdOffset;
169+
uint8_t Reserved[5];
150170
} egt[2];
151171

152172
struct HeaterConfig heaterConfig;

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

0 commit comments

Comments
 (0)