From 3810452a028832b89197fc9b80a16532080cf2ad Mon Sep 17 00:00:00 2001 From: George Hotz Date: Tue, 21 May 2019 18:14:30 -0700 Subject: [PATCH] WTF WHY WAS THIS SHIT PUT EVERYWHERE --- board/drivers/can.h | 20 +++---- board/drivers/lline_relay.h | 88 ------------------------------- board/gpio.h | 6 +-- board/main.c | 15 ------ board/safety.h | 16 +----- board/safety/safety_cadillac.h | 4 -- board/safety/safety_chrysler.h | 4 -- board/safety/safety_defaults.h | 16 ------ board/safety/safety_elm327.h | 1 - board/safety/safety_ford.h | 1 - board/safety/safety_gm.h | 4 -- board/safety/safety_gm_ascm.h | 1 - board/safety/safety_honda.h | 8 --- board/safety/safety_hyundai.h | 4 -- board/safety/safety_subaru.h | 4 -- board/safety/safety_tesla.h | 16 +++--- board/safety/safety_toyota.h | 8 --- board/safety/safety_toyota_ipas.h | 1 - python/__init__.py | 3 -- tests/safety/test.c | 8 --- 20 files changed, 17 insertions(+), 211 deletions(-) delete mode 100644 board/drivers/lline_relay.h diff --git a/board/drivers/can.h b/board/drivers/can.h index 1bcb46966ab617..c2786f235db9b4 100644 --- a/board/drivers/can.h +++ b/board/drivers/can.h @@ -37,7 +37,6 @@ int can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem); #define ALL_CAN_LIVE 0 #include "llcan.h" -#include "lline_relay.h" int can_live = 0, pending_can_live = 0, can_loopback = 0, can_silent = ALL_CAN_SILENT; @@ -381,17 +380,14 @@ void can_rx(uint8_t can_number) { to_push.RDTR = (to_push.RDTR & 0xFFFF000F) | (bus_number << 4); // forwarding (panda only) - // relay engaged or relay isn't controlled, allow fwd - if ((get_lline_status() != 0) || !relay_control) { - int bus_fwd_num = can_forwarding[bus_number] != -1 ? can_forwarding[bus_number] : safety_fwd_hook(bus_number, &to_push); - if (bus_fwd_num != -1) { - CAN_FIFOMailBox_TypeDef to_send; - to_send.RIR = to_push.RIR | 1; // TXRQ - to_send.RDTR = to_push.RDTR; - to_send.RDLR = to_push.RDLR; - to_send.RDHR = to_push.RDHR; - can_send(&to_send, bus_fwd_num); - } + int bus_fwd_num = can_forwarding[bus_number] != -1 ? can_forwarding[bus_number] : safety_fwd_hook(bus_number, &to_push); + if (bus_fwd_num != -1) { + CAN_FIFOMailBox_TypeDef to_send; + to_send.RIR = to_push.RIR | 1; // TXRQ + to_send.RDTR = to_push.RDTR; + to_send.RDLR = to_push.RDLR; + to_send.RDHR = to_push.RDHR; + can_send(&to_send, bus_fwd_num); } safety_rx_hook(&to_push); diff --git a/board/drivers/lline_relay.h b/board/drivers/lline_relay.h deleted file mode 100644 index 217e7dfe3006bf..00000000000000 --- a/board/drivers/lline_relay.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifdef PANDA - -int relay_control = 0; // True if relay is controlled through l-line - -/* Conrol a relay connected to l-line pin */ - -// 160us cycles, 1 high, 25 low - -volatile int turn_on_relay = 0; -volatile int on_cycles = 25; - -//5s timeout -#define LLINE_TIMEOUT_CYCLES 31250 -volatile int timeout_cycles = LLINE_TIMEOUT_CYCLES; - -void TIM5_IRQHandler(void) { - if (TIM5->SR & TIM_SR_UIF) { - on_cycles--; - timeout_cycles--; - if (timeout_cycles == 0) { - turn_on_relay = 0; - } - if (on_cycles > 0) { - if (turn_on_relay) { - set_gpio_output(GPIOC, 10, 0); - } - } - else { - set_gpio_output(GPIOC, 10, 1); - on_cycles = 25; - } - } - TIM5->ARR = 160-1; - TIM5->SR = 0; -} - -void lline_relay_init (void) { - set_lline_output(0); - relay_control = 1; - set_gpio_output(GPIOC, 10, 1); - - // setup - TIM5->PSC = 48-1; // tick on 1 us - TIM5->CR1 = TIM_CR1_CEN; // enable - TIM5->ARR = 50-1; // 50 us - TIM5->DIER = TIM_DIER_UIE; // update interrupt - TIM5->CNT = 0; - - NVIC_EnableIRQ(TIM5_IRQn); - -#ifdef DEBUG - puts("INIT LLINE\n"); - puts(" SR "); - putui(TIM5->SR); - puts(" PSC "); - putui(TIM5->PSC); - puts(" CR1 "); - putui(TIM5->CR1); - puts(" ARR "); - putui(TIM5->ARR); - puts(" DIER "); - putui(TIM5->DIER); - puts(" SR "); - putui(TIM5->SR); - puts(" CNT "); - putui(TIM5->CNT); - puts("\n"); -#endif -} - -void lline_relay_release (void) { - set_lline_output(0); - relay_control = 0; - puts("RELEASE LLINE\n"); - set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3); - NVIC_DisableIRQ(TIM5_IRQn); -} - -void set_lline_output(int to_set) { - timeout_cycles = LLINE_TIMEOUT_CYCLES; - turn_on_relay = to_set; -} - -int get_lline_status() { - return turn_on_relay; -} - -#endif diff --git a/board/gpio.h b/board/gpio.h index 203484e9a70255..eb58a08f535c01 100644 --- a/board/gpio.h +++ b/board/gpio.h @@ -83,7 +83,7 @@ void periph_init() { RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; - RCC->APB1ENR |= RCC_APB1ENR_TIM5EN; + //RCC->APB1ENR |= RCC_APB1ENR_TIM5EN; //RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; RCC->APB2ENR |= RCC_APB2ENR_USART1EN; RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN; @@ -349,9 +349,7 @@ void gpio_init() { set_gpio_output(GPIOA, 14, 1); // C10,C11: L-Line setup on USART 3 - // LLine now used for relay output - set_gpio_output(GPIOC, 10, 1); - //set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3); + set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3); set_gpio_alternate(GPIOC, 11, GPIO_AF7_USART3); set_gpio_pullup(GPIOC, 11, PULL_UP); #endif diff --git a/board/main.c b/board/main.c index 3e075a2629284e..9cdb708b03f7fa 100644 --- a/board/main.c +++ b/board/main.c @@ -139,13 +139,6 @@ void usb_cb_ep3_out(uint8_t *usbdata, int len, int hardwired) { uint8_t bus_number = (to_push.RDTR >> 4) & CAN_BUS_NUM_MASK; can_send(&to_push, bus_number); - - // TODO: wtf, why is this here? - // Enable relay on can message if allowed. - // Temporary until OP has support for relay - if (safety_relay_hook()) { - set_lline_output(1); - } } } @@ -414,14 +407,6 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired) { } break; } - // **** 0xf3: set l-line relay - case 0xf3: - { - if (safety_relay_hook()) { - set_lline_output(setup->b.wValue.w == 1); - } - break; - } default: puts("NO HANDLER "); puth(setup->b.bRequest); diff --git a/board/safety.h b/board/safety.h index 5543333e3a6cb0..3e39830408a4f9 100644 --- a/board/safety.h +++ b/board/safety.h @@ -5,13 +5,11 @@ struct sample_t { int max; } sample_t_default = {{0}, 0, 0}; -// no float support in STM32F2 micros (cortex-m3) -#ifdef PANDA +// safety code requires floats struct lookup_t { float x[3]; float y[3]; }; -#endif void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push); int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send); @@ -27,21 +25,14 @@ int driver_limit_check(int val, int val_last, struct sample_t *val_driver, const int MAX, const int MAX_RATE_UP, const int MAX_RATE_DOWN, const int MAX_ALLOWANCE, const int DRIVER_FACTOR); int rt_rate_limit_check(int val, int val_last, const int MAX_RT_DELTA); -#ifdef PANDA float interpolate(struct lookup_t xy, float x); -void lline_relay_init (void); -void lline_relay_release (void); -void set_lline_output(int to_set); -#endif - 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)(); typedef int (*fwd_hook)(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd); -typedef int (*relay_hook)(); typedef struct { safety_hook_init init; @@ -50,7 +41,6 @@ typedef struct { tx_hook tx; tx_lin_hook tx_lin; fwd_hook fwd; - relay_hook relay; } safety_hooks; // This can be set by the safety hooks. @@ -97,10 +87,6 @@ int safety_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { return current_hooks->fwd(bus_num, to_fwd); } -int safety_relay_hook(void) { - return current_hooks->relay(); -} - typedef struct { uint16_t id; const safety_hooks *hooks; diff --git a/board/safety/safety_cadillac.h b/board/safety/safety_cadillac.h index 0e6636a1a0764d..2a2d8b9857ff91 100644 --- a/board/safety/safety_cadillac.h +++ b/board/safety/safety_cadillac.h @@ -115,9 +115,6 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { static void cadillac_init(int16_t param) { controls_allowed = 0; cadillac_ign = 0; - #ifdef PANDA - lline_relay_release(); - #endif } static int cadillac_ign_hook() { @@ -131,5 +128,4 @@ const safety_hooks cadillac_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = cadillac_ign_hook, .fwd = alloutput_fwd_hook, - .relay = nooutput_relay_hook, }; diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index a8826b9154e80d..4af588401e0ec0 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -127,9 +127,6 @@ static int chrysler_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { static void chrysler_init(int16_t param) { chrysler_camera_detected = 0; - #ifdef PANDA - lline_relay_release(); - #endif } static int chrysler_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { @@ -153,5 +150,4 @@ const safety_hooks chrysler_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = chrysler_fwd_hook, - .relay = nooutput_relay_hook, }; diff --git a/board/safety/safety_defaults.h b/board/safety/safety_defaults.h index 88d31a7de57b48..196df65d2f8eb6 100644 --- a/board/safety/safety_defaults.h +++ b/board/safety/safety_defaults.h @@ -8,9 +8,6 @@ int default_ign_hook() { static void nooutput_init(int16_t param) { controls_allowed = 0; - #ifdef PANDA - lline_relay_release(); - #endif } static int nooutput_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { @@ -25,10 +22,6 @@ static int nooutput_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { return -1; } -static int nooutput_relay_hook(int to_set) { - return false; -} - const safety_hooks nooutput_hooks = { .init = nooutput_init, .rx = default_rx_hook, @@ -36,16 +29,12 @@ const safety_hooks nooutput_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = nooutput_fwd_hook, - .relay = nooutput_relay_hook, }; // *** all output safety mode *** static void alloutput_init(int16_t param) { controls_allowed = 1; - #ifdef PANDA - lline_relay_release(); - #endif } static int alloutput_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { @@ -60,10 +49,6 @@ static int alloutput_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { return -1; } -static int alloutput_relay_hook(int to_set) { - return true; -} - const safety_hooks alloutput_hooks = { .init = alloutput_init, .rx = default_rx_hook, @@ -71,5 +56,4 @@ const safety_hooks alloutput_hooks = { .tx_lin = alloutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = alloutput_fwd_hook, - .relay = alloutput_relay_hook, }; diff --git a/board/safety/safety_elm327.h b/board/safety/safety_elm327.h index ae0ce8106cbe7c..823d553dd738f1 100644 --- a/board/safety/safety_elm327.h +++ b/board/safety/safety_elm327.h @@ -32,5 +32,4 @@ const safety_hooks elm327_hooks = { .tx_lin = elm327_tx_lin_hook, .ignition = default_ign_hook, .fwd = nooutput_fwd_hook, - .relay = nooutput_relay_hook, }; diff --git a/board/safety/safety_ford.h b/board/safety/safety_ford.h index 1d3f16d0694676..075029fb623e0f 100644 --- a/board/safety/safety_ford.h +++ b/board/safety/safety_ford.h @@ -90,5 +90,4 @@ const safety_hooks ford_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = nooutput_fwd_hook, - .relay = nooutput_relay_hook, }; diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index 396fb8770c36f4..0aae46d0f4c0b9 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -228,9 +228,6 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { static void gm_init(int16_t param) { controls_allowed = 0; gm_ignition_started = 0; - #ifdef PANDA - lline_relay_release(); - #endif } static int gm_ign_hook() { @@ -244,5 +241,4 @@ const safety_hooks gm_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = gm_ign_hook, .fwd = nooutput_fwd_hook, - .relay = nooutput_relay_hook, }; diff --git a/board/safety/safety_gm_ascm.h b/board/safety/safety_gm_ascm.h index b145466d9de225..70a042ec514a69 100644 --- a/board/safety/safety_gm_ascm.h +++ b/board/safety/safety_gm_ascm.h @@ -48,6 +48,5 @@ const safety_hooks gm_ascm_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = gm_ascm_fwd_hook, - .relay = nooutput_relay_hook, }; diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index 40c6917b0b4c43..fbee6cfe861f53 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -136,9 +136,6 @@ static void honda_init(int16_t param) { controls_allowed = 0; bosch_hardware = false; honda_alt_brake_msg = false; - #ifdef PANDA - lline_relay_release(); - #endif } static void honda_bosch_init(int16_t param) { @@ -146,9 +143,6 @@ static void honda_bosch_init(int16_t param) { bosch_hardware = true; // Checking for alternate brake override from safety parameter honda_alt_brake_msg = param == 1 ? true : false; - #ifdef PANDA - lline_relay_release(); - #endif } static int honda_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { @@ -182,7 +176,6 @@ const safety_hooks honda_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = honda_fwd_hook, - .relay = nooutput_relay_hook, }; const safety_hooks honda_bosch_hooks = { @@ -192,5 +185,4 @@ const safety_hooks honda_bosch_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = honda_bosch_fwd_hook, - .relay = nooutput_relay_hook, }; diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index 9470e34d1556bd..b67632141d8365 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -152,9 +152,6 @@ static int hyundai_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { static void hyundai_init(int16_t param) { controls_allowed = 0; hyundai_giraffe_switch_2 = 0; - #ifdef PANDA - lline_relay_release(); - #endif } const safety_hooks hyundai_hooks = { @@ -164,5 +161,4 @@ const safety_hooks hyundai_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = hyundai_fwd_hook, - .relay = nooutput_relay_hook, }; diff --git a/board/safety/safety_subaru.h b/board/safety/safety_subaru.h index 5d2bd23d24b6a9..e64c777195da4d 100644 --- a/board/safety/safety_subaru.h +++ b/board/safety/safety_subaru.h @@ -15,9 +15,6 @@ uint32_t subaru_ts_last = 0; struct sample_t subaru_torque_driver; // last few driver torques measured static void subaru_init(int16_t param) { - #ifdef PANDA - lline_relay_init(); - #endif } static void subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { @@ -142,5 +139,4 @@ const safety_hooks subaru_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = subaru_fwd_hook, - .relay = alloutput_relay_hook, }; diff --git a/board/safety/safety_tesla.h b/board/safety/safety_tesla.h index 4a1c6e71e48a4d..430a42ce94a827 100644 --- a/board/safety/safety_tesla.h +++ b/board/safety/safety_tesla.h @@ -224,9 +224,6 @@ static void tesla_init(int16_t param) controls_allowed = 0; tesla_ignition_started = 0; gmlan_switch_init(1); //init the gmlan switch with 1s timeout enabled - #ifdef PANDA - lline_relay_release(); - #endif } static int tesla_ign_hook() @@ -275,11 +272,10 @@ static int tesla_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) } const safety_hooks tesla_hooks = { - .init = tesla_init, - .rx = tesla_rx_hook, - .tx = tesla_tx_hook, - .tx_lin = nooutput_tx_lin_hook, - .ignition = tesla_ign_hook, - .fwd = tesla_fwd_hook, - .relay = nooutput_relay_hook, + .init = tesla_init, + .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 cbc83860875fde..202625b70d4a7d 100644 --- a/board/safety/safety_toyota.h +++ b/board/safety/safety_toyota.h @@ -160,9 +160,6 @@ static void toyota_init(int16_t param) { toyota_giraffe_switch_1 = 0; toyota_camera_forwarded = 0; toyota_dbc_eps_torque_factor = param; - #ifdef PANDA - lline_relay_release(); - #endif } static int toyota_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { @@ -186,7 +183,6 @@ const safety_hooks toyota_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = toyota_fwd_hook, - .relay = nooutput_relay_hook, }; static void toyota_nolimits_init(int16_t param) { @@ -195,9 +191,6 @@ static void toyota_nolimits_init(int16_t param) { toyota_giraffe_switch_1 = 0; toyota_camera_forwarded = 0; toyota_dbc_eps_torque_factor = param; - #ifdef PANDA - lline_relay_release(); - #endif } const safety_hooks toyota_nolimits_hooks = { @@ -207,5 +200,4 @@ const safety_hooks toyota_nolimits_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = toyota_fwd_hook, - .relay = nooutput_relay_hook, }; diff --git a/board/safety/safety_toyota_ipas.h b/board/safety/safety_toyota_ipas.h index 13e664c0f9d88e..2f0b42f649319b 100644 --- a/board/safety/safety_toyota_ipas.h +++ b/board/safety/safety_toyota_ipas.h @@ -152,5 +152,4 @@ const safety_hooks toyota_ipas_hooks = { .tx_lin = nooutput_tx_lin_hook, .ignition = default_ign_hook, .fwd = toyota_fwd_hook, - .relay = nooutput_relay_hook, }; diff --git a/python/__init__.py b/python/__init__.py index 8c0bc5a9a2ae2d..bfca642e8256f7 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -392,9 +392,6 @@ def set_gmlan(self, bus=2): elif bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]: self._handle.controlWrite(Panda.REQUEST_OUT, 0xdb, 1, bus, b'') - def set_lline_relay(self, enable): - self._handle.controlWrite(Panda.REQUEST_OUT, 0xf3, int(enable), 0, b'') - def set_can_loopback(self, enable): # set can loopback mode for all buses self._handle.controlWrite(Panda.REQUEST_OUT, 0xe5, int(enable), 0, b'') diff --git a/tests/safety/test.c b/tests/safety/test.c index 04e6576fb8072c..d70cbb85c371cc 100644 --- a/tests/safety/test.c +++ b/tests/safety/test.c @@ -247,11 +247,3 @@ void reset_gmlan_switch_timeout(void){ void gmlan_switch_init(int timeout_enable){ } -void lline_relay_init (void) { -} - -void lline_relay_release (void) { -} - -void set_lline_output(int to_set) { -}