Skip to content

Commit e2c89d6

Browse files
author
Commaremote
committed
Cadillac: changed ignition logic to be based on can presence
1 parent 528f901 commit e2c89d6

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

board/safety.h

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
22
int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send);
33
int safety_tx_lin_hook(int lin_num, uint8_t *data, int len);
44
int safety_ignition_hook();
5+
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last);
56

67
typedef void (*safety_hook_init)(int16_t param);
78
typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push);
@@ -104,3 +105,7 @@ int safety_set_mode(uint16_t mode, int16_t param) {
104105
return -1;
105106
}
106107

108+
// compute the time elapsed (in microseconds) from 2 counter samples
109+
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last) {
110+
return ts > ts_last ? ts - ts_last : (0xFFFFFFFF - ts_last) + 1 + ts;
111+
}

board/safety/safety_cadillac.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
int cadillac_ignition_started = 0;
1+
const int CADILLAC_IGNITION_TIMEOUT = 1000000;
2+
int cadillac_can_seen = 0;
3+
uint32_t cadillac_ts_last = 0;
24

35
static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
46
int bus_number = (to_push->RDTR >> 4) & 0xFF;
57
uint32_t addr = to_push->RIR >> 21;
68

79
if (addr == 0x135 && bus_number == 0) {
8-
cadillac_ignition_started = 1; //as soona s we receive can msgs, ingition is on
10+
cadillac_can_seen = 1;
11+
cadillac_ts_last = TIM2->CNT; // reset timer when gear msg is received
912
}
1013
}
1114

1215
static void cadillac_init(int16_t param) {
13-
cadillac_ignition_started = 0;
16+
cadillac_can_seen = 0;
1417
}
1518

1619
static int cadillac_ign_hook() {
17-
return cadillac_ignition_started;
20+
uint32_t ts = TIM2->CNT;
21+
uint32_t ts_elapsed = get_ts_elapsed(ts, cadillac_ts_last);
22+
if ((ts_elapsed > CADILLAC_IGNITION_TIMEOUT) || (!cadillac_can_seen)) {
23+
return 0;
24+
}
25+
return 1;
1826
}
1927

2028
// Placeholder file, actual safety is TODO.

board/safety/safety_toyota.h

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ int16_t rt_torque_last = 0; // last desired torque for real time chec
3434
uint32_t ts_last = 0;
3535
int cruise_engaged_last = 0; // cruise state
3636

37-
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last) {
38-
return ts > ts_last ? ts - ts_last : (0xFFFFFFFF - ts_last) + 1 + ts;
39-
}
40-
4137
void update_sample(struct sample_t *sample, int sample_new) {
4238
for (int i = sizeof(sample->values)/sizeof(sample->values[0]) - 1; i > 0; i--) {
4339
sample->values[i] = sample->values[i-1];

0 commit comments

Comments
 (0)