From dfce5f6e36a58a7f966d1e4d9a6e019748984dfd Mon Sep 17 00:00:00 2001 From: George Hotz Date: Wed, 22 May 2019 14:48:08 -0700 Subject: [PATCH] minor fixes, and no more autobaud --- board/drivers/can.h | 63 ++++---------------------------------------- board/main.c | 9 +++---- board/power_saving.h | 4 +-- 3 files changed, 10 insertions(+), 66 deletions(-) diff --git a/board/drivers/can.h b/board/drivers/can.h index 514f115c5bca5c..43e4d41de8cbf4 100644 --- a/board/drivers/can.h +++ b/board/drivers/can.h @@ -109,44 +109,14 @@ uint8_t bus_lookup[] = {0,1,2}; uint8_t can_num_lookup[] = {0,1,2,-1}; int8_t can_forwarding[] = {-1,-1,-1,-1}; uint32_t can_speed[] = {5000, 5000, 5000, 333}; -bool can_autobaud_enabled[] = {false, false, false, false}; #define CAN_MAX 3 -uint32_t can_autobaud_speeds[] = {5000, 2500, 1250, 1000, 10000}; -#define AUTOBAUD_SPEEDS_LEN (sizeof(can_autobaud_speeds) / sizeof(can_autobaud_speeds[0])) - #define CANIF_FROM_CAN_NUM(num) (cans[num]) #define CAN_NUM_FROM_CANIF(CAN) (CAN==CAN1 ? 0 : (CAN==CAN2 ? 1 : 2)) #define CAN_NAME_FROM_CANIF(CAN) (CAN==CAN1 ? "CAN1" : (CAN==CAN2 ? "CAN2" : "CAN3")) #define BUS_NUM_FROM_CAN_NUM(num) (bus_lookup[num]) #define CAN_NUM_FROM_BUS_NUM(num) (can_num_lookup[num]) -// other option -/*#define CAN_QUANTA 16 -#define CAN_SEQ1 13 -#define CAN_SEQ2 2*/ - -void can_autobaud_speed_increment(uint8_t can_number) { - uint32_t autobaud_speed = can_autobaud_speeds[0]; - uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number); - for (int i = 0; i < AUTOBAUD_SPEEDS_LEN; i++) { - if (can_speed[bus_number] == can_autobaud_speeds[i]) { - if (i+1 < AUTOBAUD_SPEEDS_LEN) { - autobaud_speed = can_autobaud_speeds[i+1]; - } - break; - } - } - can_speed[bus_number] = autobaud_speed; -#ifdef DEBUG - CAN_TypeDef* CAN = CANIF_FROM_CAN_NUM(can_number); - puts(CAN_NAME_FROM_CANIF(CAN)); - puts(" auto-baud test "); - putui(can_speed[bus_number]); - puts(" cbps\n"); -#endif -} - void process_can(uint8_t can_number); void can_set_speed(uint8_t can_number) { @@ -158,14 +128,10 @@ void can_set_speed(uint8_t can_number) { return; } - if (can_autobaud_enabled[bus_number]) { - can_autobaud_speed_increment(can_number); - } else { - puts("CAN init FAILED!!!!!\n"); - puth(can_number); puts(" "); - puth(BUS_NUM_FROM_CAN_NUM(can_number)); puts("\n"); - return; - } + puts("CAN init FAILED!!!!!\n"); + puth(can_number); puts(" "); + puth(BUS_NUM_FROM_CAN_NUM(can_number)); puts("\n"); + return; } } @@ -253,16 +219,7 @@ void can_sce(CAN_TypeDef *CAN) { puts("\n"); #endif - uint8_t can_number = CAN_NUM_FROM_CANIF(CAN); - uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number); - can_err_cnt += 1; - - if (can_autobaud_enabled[bus_number] && (CAN->ESR & CAN_ESR_LEC)) { - can_autobaud_speed_increment(can_number); - can_set_speed(can_number); - } - llcan_clear_send(CAN); exit_critical_section(); } @@ -339,16 +296,6 @@ void can_rx(uint8_t can_number) { CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number); uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number); while (CAN->RF0R & CAN_RF0R_FMP0) { - if (can_autobaud_enabled[bus_number]) { - can_autobaud_enabled[bus_number] = false; - puts(CAN_NAME_FROM_CANIF(CAN)); - #ifdef DEBUG - puts(" auto-baud "); - putui(can_speed[bus_number]); - puts(" cbps\n"); - #endif - } - can_rx_cnt += 1; // can is live @@ -398,7 +345,7 @@ void CAN3_RX0_IRQHandler() { can_rx(2); } void CAN3_SCE_IRQHandler() { can_sce(CAN3); } void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number) { - if (safety_tx_hook(to_push) && !can_autobaud_enabled[bus_number]) { + if (safety_tx_hook(to_push)) { if (bus_number < BUS_MAX) { // add CAN packet to send queue // bus number isn't passed through diff --git a/board/main.c b/board/main.c index 5b21399c81871a..e5e4a0b246ef1f 100644 --- a/board/main.c +++ b/board/main.c @@ -291,13 +291,9 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired) { break; case SAFETY_ELM327: can_silent = ALL_CAN_BUT_MAIN_SILENT; - can_autobaud_enabled[0] = false; break; default: can_silent = ALL_CAN_LIVE; - can_autobaud_enabled[0] = false; - can_autobaud_enabled[1] = false; - can_autobaud_enabled[2] = false; break; } can_init_all(); @@ -317,7 +313,6 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired) { // **** 0xde: set can bitrate case 0xde: if (setup->b.wValue.w < BUS_MAX) { - can_autobaud_enabled[setup->b.wValue.w] = false; can_speed[setup->b.wValue.w] = setup->b.wIndex.w; can_init(CAN_NUM_FROM_BUS_NUM(setup->b.wValue.w)); } @@ -557,7 +552,9 @@ int main() { #ifdef EON // have to save power - set_esp_mode(ESP_DISABLED); + if (!is_grey_panda) { + set_esp_mode(ESP_DISABLED); + } if (is_gpio_started() == 0) { power_save_enable(); } diff --git a/board/power_saving.h b/board/power_saving.h index 7743a9b474e367..3f40bce28f1209 100644 --- a/board/power_saving.h +++ b/board/power_saving.h @@ -21,7 +21,7 @@ void power_save_enable(void) { set_gpio_output(GPIOA, 14, 0); if (is_grey_panda) { - char* UBLOX_SLEEP_MSG = "\xb5\x62\x06\x04\x04\x00\x01\x00\x08\x00\x17\x78"; + char UBLOX_SLEEP_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x08\x00\x17\x78"; uart_ring *ur = get_ring_by_number(1); for (int i = 0; i < sizeof(UBLOX_SLEEP_MSG)-1; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i])); } @@ -47,7 +47,7 @@ void power_save_disable(void) { set_gpio_output(GPIOA, 14, 1); if (is_grey_panda) { - char* UBLOX_WAKE_MSG = "\xb5\x62\x06\x04\x04\x00\x01\x00\x09\x00\x18\x7a"; + char UBLOX_WAKE_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x09\x00\x18\x7a"; uart_ring *ur = get_ring_by_number(1); for (int i = 0; i < sizeof(UBLOX_WAKE_MSG)-1; i++) while (!putc(ur, UBLOX_WAKE_MSG[i])); }