Skip to content

Commit

Permalink
Cadillac: changed ignition logic to be based on can presence
Browse files Browse the repository at this point in the history
  • Loading branch information
Commaremote committed May 25, 2018
1 parent 528f901 commit e2c89d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send);
int safety_tx_lin_hook(int lin_num, uint8_t *data, int len);
int safety_ignition_hook();
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last);

typedef void (*safety_hook_init)(int16_t param);
typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push);
Expand Down Expand Up @@ -104,3 +105,7 @@ int safety_set_mode(uint16_t mode, int16_t param) {
return -1;
}

// compute the time elapsed (in microseconds) from 2 counter samples
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last) {
return ts > ts_last ? ts - ts_last : (0xFFFFFFFF - ts_last) + 1 + ts;
}
16 changes: 12 additions & 4 deletions board/safety/safety_cadillac.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
int cadillac_ignition_started = 0;
const int CADILLAC_IGNITION_TIMEOUT = 1000000;
int cadillac_can_seen = 0;
uint32_t cadillac_ts_last = 0;

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

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

static void cadillac_init(int16_t param) {
cadillac_ignition_started = 0;
cadillac_can_seen = 0;
}

static int cadillac_ign_hook() {
return cadillac_ignition_started;
uint32_t ts = TIM2->CNT;
uint32_t ts_elapsed = get_ts_elapsed(ts, cadillac_ts_last);
if ((ts_elapsed > CADILLAC_IGNITION_TIMEOUT) || (!cadillac_can_seen)) {
return 0;
}
return 1;
}

// Placeholder file, actual safety is TODO.
Expand Down
4 changes: 0 additions & 4 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ int16_t rt_torque_last = 0; // last desired torque for real time chec
uint32_t ts_last = 0;
int cruise_engaged_last = 0; // cruise state

uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last) {
return ts > ts_last ? ts - ts_last : (0xFFFFFFFF - ts_last) + 1 + ts;
}

void update_sample(struct sample_t *sample, int sample_new) {
for (int i = sizeof(sample->values)/sizeof(sample->values[0]) - 1; i > 0; i--) {
sample->values[i] = sample->values[i-1];
Expand Down

0 comments on commit e2c89d6

Please sign in to comment.