Skip to content

Commit

Permalink
Cadillac: simplified the ignition code by removing the timeout logic …
Browse files Browse the repository at this point in the history
…and resetting controls_allowed = 0 at each init
  • Loading branch information
rbiasini committed Jun 3, 2018
1 parent 293fd1a commit d9f1e61
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions board/safety/safety_cadillac.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const int CADILLAC_STEER_MAX = 150; // 1s
const int CADILLAC_IGNITION_TIMEOUT = 1000000; // 1s
// real time torque limit to prevent controls spamming
// the real time limit is 1500/sec
const int CADILLAC_MAX_RT_DELTA = 75; // max delta torque allowed for real time checks
Expand All @@ -11,7 +10,6 @@ const int CADILLAC_DRIVER_TORQUE_FACTOR = 4;

int cadillac_ign = 0;
int cadillac_cruise_engaged_last = 0;
uint32_t cadillac_ts_ign_last = 0;
int cadillac_rt_torque_last = 0;
int cadillac_desired_torque_last = 0;
uint32_t cadillac_ts_last = 0;
Expand All @@ -31,9 +29,8 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
}

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

// enter controls on rising edge of ACC, exit controls on ACC off
Expand Down Expand Up @@ -131,15 +128,11 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
}

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

static int cadillac_ign_hook() {
uint32_t ts = TIM2->CNT;
uint32_t ts_elapsed = get_ts_elapsed(ts, cadillac_ts_ign_last);
if (ts_elapsed > CADILLAC_IGNITION_TIMEOUT) {
cadillac_ign = 0;
}
return cadillac_ign;
}

Expand Down

0 comments on commit d9f1e61

Please sign in to comment.