From d9db21bc47d8eee67cb176f35cee73415d0378e6 Mon Sep 17 00:00:00 2001 From: Vehicle Researcher Date: Mon, 17 Feb 2020 16:29:45 -0800 Subject: [PATCH] Squashed 'panda/' changes from 73a60d5c9..769ade051 769ade051 Harness orientation designation fixes (#435) eb5020b7a Add the ability to communicate with BSM (#433) git-subtree-dir: panda git-subtree-split: 769ade0511483c4ba6e4e9a3b5380ffe50d01f13 --- board/boards/black.h | 12 ++++++------ board/boards/uno.h | 12 ++++++------ board/drivers/harness.h | 31 ++++++++++++------------------- board/safety/safety_toyota.h | 2 +- tests/safety/test_toyota.py | 2 +- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 7165aa6cbb85b2..97f322f69b04b0 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -99,7 +99,7 @@ void black_set_can_mode(uint8_t mode){ switch (mode) { case CAN_MODE_NORMAL: case CAN_MODE_OBD_CAN2: - if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_NORMAL)) { + if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_FLIPPED)) { // B12,B13: disable OBD mode set_gpio_mode(GPIOB, 12, MODE_INPUT); set_gpio_mode(GPIOB, 13, MODE_INPUT); @@ -198,7 +198,7 @@ void black_init(void) { black_set_can_mode(CAN_MODE_NORMAL); // flip CAN0 and CAN2 if we are flipped - if (car_harness_status == HARNESS_STATUS_NORMAL) { + if (car_harness_status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } @@ -210,12 +210,12 @@ const harness_configuration black_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, .GPIO_SBU2 = GPIOC, - .GPIO_relay_normal = GPIOC, - .GPIO_relay_flipped = GPIOC, + .GPIO_relay_SBU1 = GPIOC, + .GPIO_relay_SBU2 = GPIOC, .pin_SBU1 = 0, .pin_SBU2 = 3, - .pin_relay_normal = 10, - .pin_relay_flipped = 11, + .pin_relay_SBU1 = 10, + .pin_relay_SBU2 = 11, .adc_channel_SBU1 = 10, .adc_channel_SBU2 = 13 }; diff --git a/board/boards/uno.h b/board/boards/uno.h index 1545a3f2dbcddf..a6a06eff3e9974 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -113,7 +113,7 @@ void uno_set_can_mode(uint8_t mode){ switch (mode) { case CAN_MODE_NORMAL: case CAN_MODE_OBD_CAN2: - if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_NORMAL)) { + if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_FLIPPED)) { // B12,B13: disable OBD mode set_gpio_mode(GPIOB, 12, MODE_INPUT); set_gpio_mode(GPIOB, 13, MODE_INPUT); @@ -230,7 +230,7 @@ void uno_init(void) { uno_set_can_mode(CAN_MODE_NORMAL); // flip CAN0 and CAN2 if we are flipped - if (car_harness_status == HARNESS_STATUS_NORMAL) { + if (car_harness_status == HARNESS_STATUS_FLIPPED) { can_flip_buses(0, 2); } @@ -252,12 +252,12 @@ const harness_configuration uno_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, .GPIO_SBU2 = GPIOC, - .GPIO_relay_normal = GPIOC, - .GPIO_relay_flipped = GPIOC, + .GPIO_relay_SBU1 = GPIOC, + .GPIO_relay_SBU2 = GPIOC, .pin_SBU1 = 0, .pin_SBU2 = 3, - .pin_relay_normal = 10, - .pin_relay_flipped = 11, + .pin_relay_SBU1 = 10, + .pin_relay_SBU2 = 11, .adc_channel_SBU1 = 10, .adc_channel_SBU2 = 13 }; diff --git a/board/drivers/harness.h b/board/drivers/harness.h index c996bff0b2efe7..4aeb41fe6300b0 100644 --- a/board/drivers/harness.h +++ b/board/drivers/harness.h @@ -10,12 +10,12 @@ struct harness_configuration { const bool has_harness; GPIO_TypeDef *GPIO_SBU1; GPIO_TypeDef *GPIO_SBU2; - GPIO_TypeDef *GPIO_relay_normal; - GPIO_TypeDef *GPIO_relay_flipped; + GPIO_TypeDef *GPIO_relay_SBU1; + GPIO_TypeDef *GPIO_relay_SBU2; uint8_t pin_SBU1; uint8_t pin_SBU2; - uint8_t pin_relay_normal; - uint8_t pin_relay_flipped; + uint8_t pin_relay_SBU1; + uint8_t pin_relay_SBU2; uint8_t adc_channel_SBU1; uint8_t adc_channel_SBU2; }; @@ -30,9 +30,9 @@ void set_intercept_relay(bool intercept) { } if(car_harness_status == HARNESS_STATUS_NORMAL){ - set_gpio_output(current_board->harness_config->GPIO_relay_normal, current_board->harness_config->pin_relay_normal, !intercept); + set_gpio_output(current_board->harness_config->GPIO_relay_SBU2, current_board->harness_config->pin_relay_SBU2, !intercept); } else { - set_gpio_output(current_board->harness_config->GPIO_relay_flipped, current_board->harness_config->pin_relay_flipped, !intercept); + set_gpio_output(current_board->harness_config->GPIO_relay_SBU1, current_board->harness_config->pin_relay_SBU1, !intercept); } } } @@ -41,10 +41,10 @@ bool harness_check_ignition(void) { bool ret = false; switch(car_harness_status){ case HARNESS_STATUS_NORMAL: - ret = !get_gpio_input(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2); + ret = !get_gpio_input(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1); break; case HARNESS_STATUS_FLIPPED: - ret = !get_gpio_input(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1); + ret = !get_gpio_input(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2); break; default: break; @@ -62,11 +62,11 @@ uint8_t harness_detect_orientation(void) { // Detect connection and orientation if((sbu1_voltage < HARNESS_CONNECTED_THRESHOLD) || (sbu2_voltage < HARNESS_CONNECTED_THRESHOLD)){ if (sbu1_voltage < sbu2_voltage) { - // orientation normal - ret = HARNESS_STATUS_NORMAL; - } else { - // orientation flipped + // orientation flipped (PANDA_SBU1->HARNESS_SBU1(relay), PANDA_SBU2->HARNESS_SBU2(ign)) ret = HARNESS_STATUS_FLIPPED; + } else { + // orientation normal (PANDA_SBU2->HARNESS_SBU1(relay), PANDA_SBU1->HARNESS_SBU2(ign)) + ret = HARNESS_STATUS_NORMAL; } } #endif @@ -90,13 +90,6 @@ void harness_init(void) { set_gpio_mode(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1, MODE_INPUT); set_gpio_mode(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2, MODE_INPUT); - // now we have orientation, set pin ignition detection - if(car_harness_status == HARNESS_STATUS_NORMAL){ - set_gpio_mode(current_board->harness_config->GPIO_SBU2, current_board->harness_config->pin_SBU2, MODE_INPUT); - } else { - set_gpio_mode(current_board->harness_config->GPIO_SBU1, current_board->harness_config->pin_SBU1, MODE_INPUT); - } - // keep busses connected by default set_intercept_relay(false); } else { diff --git a/board/safety/safety_toyota.h b/board/safety/safety_toyota.h index 844e387fef7716..4bf0a5de43d067 100644 --- a/board/safety/safety_toyota.h +++ b/board/safety/safety_toyota.h @@ -21,7 +21,7 @@ const int TOYOTA_GAS_INTERCEPTOR_THRESHOLD = 475; // ratio between offset and g const AddrBus TOYOTA_TX_MSGS[] = {{0x283, 0}, {0x2E6, 0}, {0x2E7, 0}, {0x33E, 0}, {0x344, 0}, {0x365, 0}, {0x366, 0}, {0x4CB, 0}, // DSU bus 0 {0x128, 1}, {0x141, 1}, {0x160, 1}, {0x161, 1}, {0x470, 1}, // DSU bus 1 {0x2E4, 0}, {0x411, 0}, {0x412, 0}, {0x343, 0}, {0x1D2, 0}, // LKAS + ACC - {0x200, 0}}; // interceptor + {0x200, 0}, {0x750, 0}}; // interceptor + Blindspot monitor AddrCheckStruct toyota_rx_checks[] = { {.addr = {0x260}, .bus = 0, .check_checksum = true, .max_counter = 0U, .expected_timestep = 20000U}, diff --git a/tests/safety/test_toyota.py b/tests/safety/test_toyota.py index 10181624547946..493fb1f62b0ae3 100644 --- a/tests/safety/test_toyota.py +++ b/tests/safety/test_toyota.py @@ -21,7 +21,7 @@ TX_MSGS = [[0x283, 0], [0x2E6, 0], [0x2E7, 0], [0x33E, 0], [0x344, 0], [0x365, 0], [0x366, 0], [0x4CB, 0], # DSU bus 0 [0x128, 1], [0x141, 1], [0x160, 1], [0x161, 1], [0x470, 1], # DSU bus 1 [0x2E4, 0], [0x411, 0], [0x412, 0], [0x343, 0], [0x1D2, 0], # LKAS + ACC - [0x200, 0]]; # interceptor + [0x200, 0], [0x750, 0]]; # interceptor + blindspot monitor def twos_comp(val, bits):