diff --git a/VERSION b/VERSION index b4e17366c07252..c5c4119ee45a09 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v1.5.4 \ No newline at end of file +v1.5.5 \ No newline at end of file diff --git a/board/boards/black.h b/board/boards/black.h index c6078e3b56b370..bfe598ed18b901 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -23,7 +23,8 @@ void black_enable_can_transciever(uint8_t transciever, bool enabled) { } void black_enable_can_transcievers(bool enabled) { - for(uint8_t i=1U; i<=4U; i++){ + uint8_t t1 = enabled ? 1U : 2U; // leave transciever 1 enabled to detect CAN ignition + for(uint8_t i=t1; i<=4U; i++) { black_enable_can_transciever(i, enabled); } } diff --git a/board/boards/white.h b/board/boards/white.h index 241f1b91bcf8dd..0634c32104baf7 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -20,8 +20,10 @@ void white_enable_can_transciever(uint8_t transciever, bool enabled) { } void white_enable_can_transcievers(bool enabled) { - for(uint8_t i=1; i<=3U; i++) + uint8_t t1 = enabled ? 1U : 2U; // leave transciever 1 enabled to detect CAN ignition + for(uint8_t i=t1; i<=3U; i++) { white_enable_can_transciever(i, enabled); + } } void white_set_led(uint8_t color, bool enabled) { diff --git a/board/drivers/can.h b/board/drivers/can.h index c45a3fe8d1d754..56642a6c2e965d 100644 --- a/board/drivers/can.h +++ b/board/drivers/can.h @@ -30,6 +30,9 @@ void can_init_all(void); void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number); bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem); +// Ignition detected from CAN meessages +bool ignition_can = false; + // end API #define ALL_CAN_SILENT 0xFF @@ -332,6 +335,38 @@ void process_can(uint8_t can_number) { } } +void ignition_can_hook(CAN_FIFOMailBox_TypeDef *to_push) { + + int bus = GET_BUS(to_push); + int addr = GET_ADDR(to_push); + int len = GET_LEN(to_push); + + if (bus == 0) { + // GM exception + if ((addr == 0x1F1) && (len == 8)) { + //Bit 5 is ignition "on" + ignition_can = (GET_BYTE(to_push, 0) & 0x20) != 0; + } + // Tesla exception + if ((addr == 0x348) && (len == 8)) { + // GTW_status + ignition_can = (GET_BYTE(to_push, 0) & 0x1) != 0; + } + // Cadillac exception + if ((addr == 0x160) && (len == 5)) { + // this message isn't all zeros when ignition is on + ignition_can = GET_BYTES_04(to_push) != 0; + } + // VW exception (not used yet) + // While we do monitor VW Terminal 15 (ignition-on) state, we are not currently acting on it. Instead we use the + // default GPIO ignition hook. We may do so in the future for harness integrations at the camera (where we only have + // T30 unswitched power) instead of the gateway (where we have both T30 and T15 ignition-switched power). + //if ((bus == 0) && (addr == 0x3C0)) { + // vw_ignition_started = (GET_BYTE(to_push, 2) & 0x2) >> 1; + //} + } +} + // CAN receive handlers // blink blue when we are receiving CAN messages void can_rx(uint8_t can_number) { @@ -365,6 +400,7 @@ void can_rx(uint8_t can_number) { } safety_rx_hook(&to_push); + ignition_can_hook(&to_push); current_board->set_led(LED_BLUE, true); can_send_errs += can_push(&can_rx_q, &to_push) ? 0U : 1U; diff --git a/board/main.c b/board/main.c index df134e046baaad..a38f6db8f15b68 100644 --- a/board/main.c +++ b/board/main.c @@ -139,13 +139,6 @@ void set_safety_mode(uint16_t mode, int16_t param) { can_silent = ALL_CAN_LIVE; break; } - if (safety_ignition_hook() != -1) { - // if the ignition hook depends on something other than the started GPIO - // we have to disable power savings (fix for GM and Tesla) - set_power_save_state(POWER_SAVE_STATUS_DISABLED); - } else { - // power mode is already POWER_SAVE_STATUS_DISABLED and CAN TXs are active - } can_init_all(); } } @@ -175,14 +168,9 @@ int get_health_pkt(void *dat) { health->current_pkt = 0; } - int safety_ignition = safety_ignition_hook(); - if (safety_ignition < 0) { - //Use the GPIO pin to determine ignition - health->started_pkt = (uint8_t)(current_board->check_ignition()); - } else { - //Current safety hooks want to determine ignition (ex: GM) - health->started_pkt = safety_ignition; - } + //Use the GPIO pin to determine ignition or use a CAN based logic + bool ignition = current_board->check_ignition() || ignition_can; + health->started_pkt = (uint8_t)(ignition); health->controls_allowed_pkt = controls_allowed; health->gas_interceptor_detected_pkt = gas_interceptor_detected; diff --git a/board/power_saving.h b/board/power_saving.h index 0a926c119d3e22..cf599282c9de42 100644 --- a/board/power_saving.h +++ b/board/power_saving.h @@ -25,7 +25,6 @@ void set_power_save_state(int state) { enable = true; } - // Switch CAN transcievers current_board->enable_can_transcievers(enable); // Switch EPS/GPS @@ -34,13 +33,13 @@ void set_power_save_state(int state) { } else { current_board->set_esp_gps_mode(ESP_GPS_DISABLED); } - + if(hw_type != HW_TYPE_BLACK_PANDA){ // turn on GMLAN set_gpio_output(GPIOB, 14, enable); set_gpio_output(GPIOB, 15, enable); - // turn on LIN + // turn on LIN set_gpio_output(GPIOB, 7, enable); set_gpio_output(GPIOA, 14, enable); } diff --git a/board/safety.h b/board/safety.h index 65322193dfcd42..c68eda2c4a4864 100644 --- a/board/safety.h +++ b/board/safety.h @@ -30,7 +30,6 @@ #define SAFETY_CHRYSLER 9U #define SAFETY_TESLA 10U #define SAFETY_SUBARU 11U -#define SAFETY_GM_PASSIVE 12U #define SAFETY_MAZDA 13U #define SAFETY_VOLKSWAGEN 15U #define SAFETY_TOYOTA_IPAS 16U @@ -52,12 +51,6 @@ int safety_tx_lin_hook(int lin_num, uint8_t *data, int len){ return current_hooks->tx_lin(lin_num, data, len); } -// -1 = Disabled (Use GPIO to determine ignition) -// 0 = Off (not started) -// 1 = On (started) -int safety_ignition_hook() { - return current_hooks->ignition(); -} int safety_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { return current_hooks->fwd(bus_num, to_fwd); } @@ -80,7 +73,6 @@ const safety_hook_config safety_hook_registry[] = { {SAFETY_CHRYSLER, &chrysler_hooks}, {SAFETY_TESLA, &tesla_hooks}, {SAFETY_SUBARU, &subaru_hooks}, - {SAFETY_GM_PASSIVE, &gm_passive_hooks}, {SAFETY_MAZDA, &mazda_hooks}, {SAFETY_VOLKSWAGEN, &volkswagen_hooks}, {SAFETY_TOYOTA_IPAS, &toyota_ipas_hooks}, diff --git a/board/safety/safety_cadillac.h b/board/safety/safety_cadillac.h index ef63360955fe7f..4ae2045505d8a7 100644 --- a/board/safety/safety_cadillac.h +++ b/board/safety/safety_cadillac.h @@ -10,7 +10,6 @@ const int CADILLAC_MAX_RATE_DOWN = 5; const int CADILLAC_DRIVER_TORQUE_ALLOWANCE = 50; const int CADILLAC_DRIVER_TORQUE_FACTOR = 4; -bool cadillac_ign = 0; int cadillac_cruise_engaged_last = 0; int cadillac_rt_torque_last = 0; const int cadillac_torque_msgs_n = 4; @@ -35,11 +34,6 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { update_sample(&cadillac_torque_driver, torque_driver_new); } - // this message isn't all zeros when ignition is on - if ((addr == 0x160) && (bus == 0)) { - cadillac_ign = GET_BYTES_04(to_push) != 0; - } - // enter controls on rising edge of ACC, exit controls on ACC off if ((addr == 0x370) && (bus == 0)) { int cruise_engaged = GET_BYTE(to_push, 2) & 0x80; // bit 23 @@ -118,11 +112,6 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { static void cadillac_init(int16_t param) { UNUSED(param); controls_allowed = 0; - cadillac_ign = 0; -} - -static int cadillac_ign_hook(void) { - return cadillac_ign; } const safety_hooks cadillac_hooks = { @@ -130,6 +119,5 @@ const safety_hooks cadillac_hooks = { .rx = cadillac_rx_hook, .tx = cadillac_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = cadillac_ign_hook, .fwd = default_fwd_hook, }; diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index e608785739b109..9b8fc361546f59 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -136,6 +136,5 @@ const safety_hooks chrysler_hooks = { .rx = chrysler_rx_hook, .tx = chrysler_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = chrysler_fwd_hook, }; diff --git a/board/safety/safety_defaults.h b/board/safety/safety_defaults.h index 9dc23b54b79906..2743db96fe6eff 100644 --- a/board/safety/safety_defaults.h +++ b/board/safety/safety_defaults.h @@ -2,10 +2,6 @@ void default_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { UNUSED(to_push); } -int default_ign_hook(void) { - return -1; // use GPIO to determine ignition -} - // *** no output safety mode *** static void nooutput_init(int16_t param) { @@ -36,7 +32,6 @@ const safety_hooks nooutput_hooks = { .rx = default_rx_hook, .tx = nooutput_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = default_fwd_hook, }; @@ -64,6 +59,5 @@ const safety_hooks alloutput_hooks = { .rx = default_rx_hook, .tx = alloutput_tx_hook, .tx_lin = alloutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = default_fwd_hook, }; diff --git a/board/safety/safety_elm327.h b/board/safety/safety_elm327.h index bbad909f28cb37..ce405b47675f11 100644 --- a/board/safety/safety_elm327.h +++ b/board/safety/safety_elm327.h @@ -38,6 +38,5 @@ const safety_hooks elm327_hooks = { .rx = default_rx_hook, .tx = elm327_tx_hook, .tx_lin = elm327_tx_lin_hook, - .ignition = default_ign_hook, .fwd = default_fwd_hook, }; diff --git a/board/safety/safety_ford.h b/board/safety/safety_ford.h index 0bb839f2f6513d..22fc604ff1dd9d 100644 --- a/board/safety/safety_ford.h +++ b/board/safety/safety_ford.h @@ -97,6 +97,5 @@ const safety_hooks ford_hooks = { .rx = ford_rx_hook, .tx = ford_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = default_fwd_hook, }; diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index ed8217fc025c86..452f70953df640 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -24,7 +24,6 @@ int gm_gas_prev = 0; bool gm_moving = false; // silence everything if stock car control ECUs are still online bool gm_ascm_detected = 0; -bool gm_ignition_started = 0; int gm_rt_torque_last = 0; int gm_desired_torque_last = 0; uint32_t gm_ts_last = 0; @@ -41,13 +40,6 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { update_sample(&gm_torque_driver, torque_driver_new); } - if ((addr == 0x1F1) && (bus_number == 0)) { - //Bit 5 should be ignition "on" - //Backup plan is Bit 2 (accessory power) - bool ign = (GET_BYTE(to_push, 0) & 0x20) != 0; - gm_ignition_started = ign; - } - // sample speed, really only care if car is moving or not // rear left wheel speed if (addr == 842) { @@ -224,41 +216,13 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { static void gm_init(int16_t param) { UNUSED(param); controls_allowed = 0; - gm_ignition_started = 0; -} - -static int gm_ign_hook(void) { - return gm_ignition_started; } -// All sending is disallowed. -// The only difference from "no output" model -// is using GM ignition hook. - -static void gm_passive_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { - int bus_number = GET_BUS(to_push); - int addr = GET_ADDR(to_push); - - if ((addr == 0x1F1) && (bus_number == 0)) { - bool ign = (GET_BYTE(to_push, 0) & 0x20) != 0; - gm_ignition_started = ign; - } -} const safety_hooks gm_hooks = { .init = gm_init, .rx = gm_rx_hook, .tx = gm_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = gm_ign_hook, - .fwd = default_fwd_hook, -}; - -const safety_hooks gm_passive_hooks = { - .init = gm_init, - .rx = gm_passive_rx_hook, - .tx = nooutput_tx_hook, - .tx_lin = nooutput_tx_lin_hook, - .ignition = gm_ign_hook, .fwd = default_fwd_hook, }; diff --git a/board/safety/safety_gm_ascm.h b/board/safety/safety_gm_ascm.h index 82f1db6ae5741e..36fd1d8f2adfa9 100644 --- a/board/safety/safety_gm_ascm.h +++ b/board/safety/safety_gm_ascm.h @@ -39,7 +39,6 @@ const safety_hooks gm_ascm_hooks = { .rx = default_rx_hook, .tx = alloutput_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = gm_ascm_fwd_hook, }; diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index ebaa15642afbb3..7df3d38b4333ff 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -231,7 +231,6 @@ const safety_hooks honda_hooks = { .rx = honda_rx_hook, .tx = honda_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = honda_fwd_hook, }; @@ -240,6 +239,5 @@ const safety_hooks honda_bosch_hooks = { .rx = honda_rx_hook, .tx = honda_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = honda_bosch_fwd_hook, }; diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index aed30621f44b00..21796e4caaf128 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -155,6 +155,5 @@ const safety_hooks hyundai_hooks = { .rx = hyundai_rx_hook, .tx = hyundai_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = hyundai_fwd_hook, }; diff --git a/board/safety/safety_mazda.h b/board/safety/safety_mazda.h index 63fbcdfd6f919f..60d8b2bda9b16a 100644 --- a/board/safety/safety_mazda.h +++ b/board/safety/safety_mazda.h @@ -164,6 +164,5 @@ const safety_hooks mazda_hooks = { .rx = mazda_rx_hook, .tx = mazda_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = mazda_fwd_hook, }; diff --git a/board/safety/safety_subaru.h b/board/safety/safety_subaru.h index 5b482973e6ec2f..c09b9d6225ed19 100644 --- a/board/safety/safety_subaru.h +++ b/board/safety/safety_subaru.h @@ -124,6 +124,5 @@ const safety_hooks subaru_hooks = { .rx = subaru_rx_hook, .tx = subaru_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = subaru_fwd_hook, }; diff --git a/board/safety/safety_tesla.h b/board/safety/safety_tesla.h index 188b12ac481dfc..2e5d20c622826e 100644 --- a/board/safety/safety_tesla.h +++ b/board/safety/safety_tesla.h @@ -39,9 +39,6 @@ int tesla_gas_prev = 0; int tesla_speed = 0; int eac_status = 0; -int tesla_ignition_started = 0; - - void set_gmlan_digital_output(int to_set); void reset_gmlan_switch_timeout(void); void gmlan_switch_init(int timeout_enable); @@ -66,13 +63,6 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } } - // Detect drive rail on (ignition) (start recording) - if (addr == 0x348) { - // GTW_status - int drive_rail_on = GET_BYTE(to_push, 0) & 0x1; - tesla_ignition_started = drive_rail_on == 1; - } - // exit controls on brake press // DI_torque2::DI_brakePedal 0x118 if (addr == 0x118) { @@ -183,14 +173,9 @@ static int tesla_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { static void tesla_init(int16_t param) { UNUSED(param); controls_allowed = 0; - tesla_ignition_started = 0; gmlan_switch_init(1); //init the gmlan switch with 1s timeout enabled } -static int tesla_ign_hook(void) { - return tesla_ignition_started; -} - static int tesla_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { int bus_fwd = -1; @@ -224,6 +209,5 @@ const safety_hooks tesla_hooks = { .rx = tesla_rx_hook, .tx = tesla_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = tesla_ign_hook, .fwd = tesla_fwd_hook, }; diff --git a/board/safety/safety_toyota.h b/board/safety/safety_toyota.h index c1ce996058611b..134cc845c97283 100644 --- a/board/safety/safety_toyota.h +++ b/board/safety/safety_toyota.h @@ -224,6 +224,5 @@ const safety_hooks toyota_hooks = { .rx = toyota_rx_hook, .tx = toyota_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = toyota_fwd_hook, }; diff --git a/board/safety/safety_toyota_ipas.h b/board/safety/safety_toyota_ipas.h index 3e3a3b3a24134f..d5833e45db5544 100644 --- a/board/safety/safety_toyota_ipas.h +++ b/board/safety/safety_toyota_ipas.h @@ -164,6 +164,5 @@ const safety_hooks toyota_ipas_hooks = { .rx = toyota_ipas_rx_hook, .tx = toyota_ipas_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = toyota_fwd_hook, }; diff --git a/board/safety/safety_volkswagen.h b/board/safety/safety_volkswagen.h index ff38a3f401f44d..0c64efebc7fabf 100644 --- a/board/safety/safety_volkswagen.h +++ b/board/safety/safety_volkswagen.h @@ -6,7 +6,6 @@ const int VW_MAX_RATE_DOWN = 10; // 5.0 nm/s available rate of change const int VW_DRIVER_TORQUE_ALLOWANCE = 100; const int VW_DRIVER_TORQUE_FACTOR = 4; -int vw_ignition_started = 0; struct sample_t vw_torque_driver; // last few driver torques measured int vw_rt_torque_last = 0; int vw_desired_torque_last = 0; @@ -23,17 +22,11 @@ uint32_t vw_ts_last = 0; static void volkswagen_init(int16_t param) { UNUSED(param); // May use param in the future to indicate MQB vs PQ35/PQ46/NMS vs MLB, or wiring configuration. controls_allowed = 0; - vw_ignition_started = 0; } static void volkswagen_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { int bus = GET_BUS(to_push); int addr = GET_ADDR(to_push); - // Monitor Klemmen_Status_01.ZAS_Kl_15 for Terminal 15 (ignition-on) status, but we make no use of it at the moment. - if ((bus == 0) && (addr == MSG_KLEMMEN_STATUS_01)) { - vw_ignition_started = (GET_BYTE(to_push, 2) & 0x2) >> 1; - } - // Update driver input torque samples from EPS_01.Driver_Strain for absolute torque, and EPS_01.Driver_Strain_VZ // for the direction. if ((bus == 0) && (addr == MSG_EPS_01)) { @@ -148,15 +141,10 @@ static int volkswagen_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { return bus_fwd; } -// While we do monitor VW Terminal 15 (ignition-on) state, we are not currently acting on it. Instead we use the -// default GPIO ignition hook. We may do so in the future for harness integrations at the camera (where we only have -// T30 unswitched power) instead of the gateway (where we have both T30 and T15 ignition-switched power). - const safety_hooks volkswagen_hooks = { .init = volkswagen_init, .rx = volkswagen_rx_hook, .tx = volkswagen_tx_hook, .tx_lin = nooutput_tx_lin_hook, - .ignition = default_ign_hook, .fwd = volkswagen_fwd_hook, }; diff --git a/board/safety_declarations.h b/board/safety_declarations.h index 7e0a54d73e8231..efa6a4e2b8744c 100644 --- a/board/safety_declarations.h +++ b/board/safety_declarations.h @@ -14,7 +14,6 @@ struct lookup_t { 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(void); uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last); int to_signed(int d, int bits); void update_sample(struct sample_t *sample, int sample_new); @@ -31,12 +30,10 @@ typedef void (*safety_hook_init)(int16_t param); typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push); typedef int (*tx_hook)(CAN_FIFOMailBox_TypeDef *to_send); typedef int (*tx_lin_hook)(int lin_num, uint8_t *data, int len); -typedef int (*ign_hook)(void); typedef int (*fwd_hook)(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd); typedef struct { safety_hook_init init; - ign_hook ignition; rx_hook rx; tx_hook tx; tx_lin_hook tx_lin; diff --git a/python/__init__.py b/python/__init__.py index 95070a423b026c..0ce4fa051f5740 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -122,7 +122,6 @@ class Panda(object): SAFETY_CHRYSLER = 9 SAFETY_TESLA = 10 SAFETY_SUBARU = 11 - SAFETY_GM_PASSIVE = 12 SAFETY_MAZDA = 13 SAFETY_VOLKSWAGEN = 15 SAFETY_TOYOTA_IPAS = 16