Skip to content

Commit

Permalink
Cadillac ignition: simplified logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini committed May 31, 2018
1 parent 69be556 commit 40c8dda
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions board/safety/safety_cadillac.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const int STEER_MAX = 150; // 1s
const int CADILLAC_IGNITION_TIMEOUT = 1000000; // 1s

int cadillac_can_seen = 0;
int cadillac_ign = 0;
int cadillac_cruise_engaged_last = 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;

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

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

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

static int cadillac_ign_hook() {
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)) {
cadillac_can_seen = 0;
return 0;
if (ts_elapsed > CADILLAC_IGNITION_TIMEOUT) {
cadillac_ign = 0;
}
return 1;
return cadillac_ign;
}

// Placeholder file, actual safety is TODO.
Expand Down

0 comments on commit 40c8dda

Please sign in to comment.