Skip to content

Commit 40c8dda

Browse files
committed
Cadillac ignition: simplified logic
1 parent 69be556 commit 40c8dda

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

board/safety/safety_cadillac.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
const int STEER_MAX = 150; // 1s
22
const int CADILLAC_IGNITION_TIMEOUT = 1000000; // 1s
33

4-
int cadillac_can_seen = 0;
4+
int cadillac_ign = 0;
55
int cadillac_cruise_engaged_last = 0;
66
uint32_t cadillac_ts_last = 0;
77

88
static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
99
int bus_number = (to_push->RDTR >> 4) & 0xFF;
1010
uint32_t addr = to_push->RIR >> 21;
1111

12-
// this message isn't all zeros when car is on
12+
// this message isn't all zeros when ignition is on
1313
if ((addr == 0x160) && (bus_number == 0) && to_push->RDLR) {
14-
cadillac_can_seen = 1;
15-
cadillac_ts_last = TIM2->CNT; // reset timer when gear msg is received
14+
cadillac_ign = 1;
15+
cadillac_ts_last = TIM2->CNT; // reset timer when ign is received
1616
}
1717

1818
// enter controls on rising edge of ACC, exit controls on ACC off
@@ -44,17 +44,16 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
4444
}
4545

4646
static void cadillac_init(int16_t param) {
47-
cadillac_can_seen = 0;
47+
cadillac_ign = 0;
4848
}
4949

5050
static int cadillac_ign_hook() {
5151
uint32_t ts = TIM2->CNT;
5252
uint32_t ts_elapsed = get_ts_elapsed(ts, cadillac_ts_last);
53-
if ((ts_elapsed > CADILLAC_IGNITION_TIMEOUT) || (!cadillac_can_seen)) {
54-
cadillac_can_seen = 0;
55-
return 0;
53+
if (ts_elapsed > CADILLAC_IGNITION_TIMEOUT) {
54+
cadillac_ign = 0;
5655
}
57-
return 1;
56+
return cadillac_ign;
5857
}
5958

6059
// Placeholder file, actual safety is TODO.

0 commit comments

Comments
 (0)