Cadillac: simplified the ignition code by removing the timeout logic and resetting controls_allowed = 0 at each init
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
@@ -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;
@@ -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
@@ -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;
}
