Skip to content

Commit 500370a

Browse files
authoredApr 9, 2020
Make sure relay faults make it to the health packet (#492)
* Added relay malfunction handling * Bump version * Fixed safety test * set/reset * fixed test again
1 parent bc90b60 commit 500370a

15 files changed

+40
-22
lines changed
 

‎VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.7.4
1+
v1.7.5

‎board/safety.h

+9
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ bool addr_safety_check(CAN_FIFOMailBox_TypeDef *to_push,
184184
return is_msg_valid(rx_checks, index);
185185
}
186186

187+
void relay_malfunction_set(void) {
188+
relay_malfunction = true;
189+
fault_occurred(FAULT_RELAY_MALFUNCTION);
190+
}
191+
192+
void relay_malfunction_reset(void) {
193+
relay_malfunction = false;
194+
fault_recovered(FAULT_RELAY_MALFUNCTION);
195+
}
187196

188197
typedef struct {
189198
uint16_t id;

‎board/safety/safety_chrysler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
126126

127127
// check if stock camera ECU is on bus 0
128128
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (addr == 0x292)) {
129-
relay_malfunction = true;
129+
relay_malfunction_set();
130130
}
131131
}
132132
return valid;

‎board/safety/safety_defaults.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ int default_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
88
static void nooutput_init(int16_t param) {
99
UNUSED(param);
1010
controls_allowed = false;
11-
relay_malfunction = false;
11+
relay_malfunction_reset();
1212
}
1313

1414
static int nooutput_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
@@ -42,7 +42,7 @@ const safety_hooks nooutput_hooks = {
4242
static void alloutput_init(int16_t param) {
4343
UNUSED(param);
4444
controls_allowed = true;
45-
relay_malfunction = false;
45+
relay_malfunction_reset();
4646
}
4747

4848
static int alloutput_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {

‎board/safety/safety_ford.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
5555
}
5656

5757
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && (addr == 0x3CA)) {
58-
relay_malfunction = true;
58+
relay_malfunction_set();
5959
}
6060
return 1;
6161
}

‎board/safety/safety_gm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
112112
// 384 = ASCMLKASteeringCmd
113113
// 715 = ASCMGasRegenCmd
114114
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && ((addr == 384) || (addr == 715))) {
115-
relay_malfunction = true;
115+
relay_malfunction_set();
116116
}
117117
}
118118
return valid;

‎board/safety/safety_honda.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static int honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
165165
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && ((addr == 0xE4) || (addr == 0x194))) {
166166
if (((honda_hw != HONDA_N_HW) && (bus == bus_rdr_car)) ||
167167
((honda_hw == HONDA_N_HW) && (bus == 0))) {
168-
relay_malfunction = true;
168+
relay_malfunction_set();
169169
}
170170
}
171171
}
@@ -257,22 +257,22 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
257257
static void honda_nidec_init(int16_t param) {
258258
UNUSED(param);
259259
controls_allowed = false;
260-
relay_malfunction = false;
260+
relay_malfunction_reset();
261261
honda_hw = HONDA_N_HW;
262262
honda_alt_brake_msg = false;
263263
}
264264

265265
static void honda_bosch_giraffe_init(int16_t param) {
266266
controls_allowed = false;
267-
relay_malfunction = false;
267+
relay_malfunction_reset();
268268
honda_hw = HONDA_BG_HW;
269269
// Checking for alternate brake override from safety parameter
270270
honda_alt_brake_msg = (param == 1) ? true : false;
271271
}
272272

273273
static void honda_bosch_harness_init(int16_t param) {
274274
controls_allowed = false;
275-
relay_malfunction = false;
275+
relay_malfunction_reset();
276276
honda_hw = HONDA_BH_HW;
277277
// Checking for alternate brake override from safety parameter
278278
honda_alt_brake_msg = (param == 1) ? true : false;

‎board/safety/safety_hyundai.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
8181

8282
// check if stock camera ECU is on bus 0
8383
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (addr == 832)) {
84-
relay_malfunction = true;
84+
relay_malfunction_set();
8585
}
8686
}
8787
return valid;

‎board/safety/safety_mazda.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int mazda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
5555

5656
// if we see wheel speed msgs on MAZDA_CAM bus then relay is closed
5757
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == MAZDA_CAM) && (addr == MAZDA_WHEEL_SPEED)) {
58-
relay_malfunction = true;
58+
relay_malfunction_set();
5959
}
6060
return 1;
6161
}

‎board/safety/safety_nissan.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static int nissan_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
7878

7979
// 0x169 is lkas cmd. If it is on bus 0, then relay is unexpectedly closed
8080
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (addr == 0x169)) {
81-
relay_malfunction = true;
81+
relay_malfunction_set();
8282
}
8383
}
8484

‎board/safety/safety_subaru.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
126126

127127
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) &&
128128
(((addr == 0x122) && subaru_global) || ((addr == 0x164) && !subaru_global))) {
129-
relay_malfunction = true;
129+
relay_malfunction_set();
130130
}
131131
}
132132
return valid;
@@ -228,14 +228,14 @@ static int subaru_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
228228
static void subaru_init(int16_t param) {
229229
UNUSED(param);
230230
controls_allowed = false;
231-
relay_malfunction = false;
231+
relay_malfunction_reset();
232232
subaru_global = true;
233233
}
234234

235235
static void subaru_legacy_init(int16_t param) {
236236
UNUSED(param);
237237
controls_allowed = false;
238-
relay_malfunction = false;
238+
relay_malfunction_reset();
239239
subaru_global = false;
240240
}
241241

‎board/safety/safety_toyota.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static int toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
143143

144144
// 0x2E4 is lkas cmd. If it is on bus 0, then relay is unexpectedly closed
145145
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (addr == 0x2E4)) {
146-
relay_malfunction = true;
146+
relay_malfunction_set();
147147
}
148148
}
149149
return valid;
@@ -247,7 +247,7 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
247247

248248
static void toyota_init(int16_t param) {
249249
controls_allowed = 0;
250-
relay_malfunction = 0;
250+
relay_malfunction_reset();
251251
toyota_dbc_eps_torque_factor = param;
252252
}
253253

‎board/safety/safety_volkswagen.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void volkswagen_mqb_init(int16_t param) {
126126
UNUSED(param);
127127

128128
controls_allowed = false;
129-
relay_malfunction = false;
129+
relay_malfunction_reset();
130130
volkswagen_torque_msg = MSG_HCA_01;
131131
volkswagen_lane_msg = MSG_LDW_02;
132132
gen_crc_lookup_table(0x2F, volkswagen_crc8_lut_8h2f);
@@ -136,7 +136,7 @@ static void volkswagen_pq_init(int16_t param) {
136136
UNUSED(param);
137137

138138
controls_allowed = false;
139-
relay_malfunction = false;
139+
relay_malfunction_reset();
140140
volkswagen_torque_msg = MSG_HCA_1;
141141
volkswagen_lane_msg = MSG_LDW_1;
142142
}
@@ -201,7 +201,7 @@ static int volkswagen_mqb_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
201201

202202
// If there are HCA messages on bus 0 not sent by OP, there's a relay problem
203203
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (addr == MSG_HCA_01)) {
204-
relay_malfunction = true;
204+
relay_malfunction_set();
205205
}
206206
}
207207
return valid;
@@ -268,7 +268,7 @@ static int volkswagen_pq_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
268268

269269
// If there are HCA messages on bus 0 not sent by OP, there's a relay problem
270270
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && (addr == MSG_HCA_1)) {
271-
relay_malfunction = true;
271+
relay_malfunction_set();
272272
}
273273
}
274274
return valid;

‎board/safety_declarations.h

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ bool addr_safety_check(CAN_FIFOMailBox_TypeDef *to_push,
6161
uint8_t (*get_checksum)(CAN_FIFOMailBox_TypeDef *to_push),
6262
uint8_t (*compute_checksum)(CAN_FIFOMailBox_TypeDef *to_push),
6363
uint8_t (*get_counter)(CAN_FIFOMailBox_TypeDef *to_push));
64+
void relay_malfunction_set(void);
65+
void relay_malfunction_reset(void);
6466

6567
typedef void (*safety_hook_init)(int16_t param);
6668
typedef int (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push);

‎tests/safety/test.c

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ uint8_t hw_type = HW_TYPE_UNKNOWN;
6262
({ __typeof__ (a) _a = (a); \
6363
(_a > 0) ? _a : (-_a); })
6464

65+
// from faults.h
66+
#define FAULT_RELAY_MALFUNCTION (1U << 0)
67+
void fault_occurred(uint32_t fault) {
68+
}
69+
void fault_recovered(uint32_t fault) {
70+
}
71+
6572
// from llcan.h
6673
#define GET_BUS(msg) (((msg)->RDTR >> 4) & 0xFF)
6774
#define GET_LEN(msg) ((msg)->RDTR & 0xf)

0 commit comments

Comments
 (0)