From cee9e46ff291da9497b91a2ab5eea16a279f0613 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 30 Aug 2022 20:38:24 -0700 Subject: [PATCH 1/7] remove tick --- board/boards/black.h | 1 - board/boards/board_declarations.h | 2 -- board/boards/dos.h | 1 - board/boards/grey.h | 1 - board/boards/pedal.h | 1 - board/boards/red.h | 1 - board/boards/uno.h | 10 ---------- board/boards/unused_funcs.h | 4 ---- board/boards/white.h | 1 - board/main.c | 2 -- 10 files changed, 24 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index a1297345b26..db34c0c0b19 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -218,7 +218,6 @@ const board board_black = { .set_usb_power_mode = black_set_usb_power_mode, .set_gps_mode = black_set_gps_mode, .set_can_mode = black_set_can_mode, - .usb_power_mode_tick = unused_usb_power_mode_tick, .check_ignition = black_check_ignition, .read_current = unused_read_current, .set_fan_enabled = unused_set_fan_enabled, diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index 50a7ee451f1..4ea6554d2e2 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -6,7 +6,6 @@ typedef void (*board_set_led)(uint8_t color, bool enabled); typedef void (*board_set_usb_power_mode)(uint8_t mode); typedef void (*board_set_gps_mode)(uint8_t mode); typedef void (*board_set_can_mode)(uint8_t mode); -typedef void (*board_usb_power_mode_tick)(uint32_t uptime); typedef bool (*board_check_ignition)(void); typedef uint32_t (*board_read_current)(void); typedef void (*board_set_ir_power)(uint8_t percentage); @@ -31,7 +30,6 @@ struct board { board_set_usb_power_mode set_usb_power_mode; board_set_gps_mode set_gps_mode; board_set_can_mode set_can_mode; - board_usb_power_mode_tick usb_power_mode_tick; board_check_ignition check_ignition; board_read_current read_current; board_set_ir_power set_ir_power; diff --git a/board/boards/dos.h b/board/boards/dos.h index 38d6470377d..77400d6b93d 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -215,7 +215,6 @@ const board board_dos = { .set_usb_power_mode = dos_set_usb_power_mode, .set_gps_mode = unused_set_gps_mode, .set_can_mode = dos_set_can_mode, - .usb_power_mode_tick = unused_usb_power_mode_tick, .check_ignition = dos_check_ignition, .read_current = unused_read_current, .set_fan_enabled = dos_set_fan_enabled, diff --git a/board/boards/grey.h b/board/boards/grey.h index 4ff6f898701..3271d89f616 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -49,7 +49,6 @@ const board board_grey = { .set_usb_power_mode = white_set_usb_power_mode, .set_gps_mode = grey_set_gps_mode, .set_can_mode = white_set_can_mode, - .usb_power_mode_tick = unused_usb_power_mode_tick, .check_ignition = white_check_ignition, .read_current = white_read_current, .set_fan_enabled = unused_set_fan_enabled, diff --git a/board/boards/pedal.h b/board/boards/pedal.h index 72286e646c5..f89b7610137 100644 --- a/board/boards/pedal.h +++ b/board/boards/pedal.h @@ -92,7 +92,6 @@ const board board_pedal = { .set_usb_power_mode = pedal_set_usb_power_mode, .set_gps_mode = pedal_set_gps_mode, .set_can_mode = pedal_set_can_mode, - .usb_power_mode_tick = unused_usb_power_mode_tick, .check_ignition = pedal_check_ignition, .read_current = unused_read_current, .set_fan_enabled = unused_set_fan_enabled, diff --git a/board/boards/red.h b/board/boards/red.h index ac22f78f66e..e30077a1fb6 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -195,7 +195,6 @@ const board board_red = { .set_usb_power_mode = red_set_usb_power_mode, .set_gps_mode = unused_set_gps_mode, .set_can_mode = red_set_can_mode, - .usb_power_mode_tick = unused_usb_power_mode_tick, .check_ignition = red_check_ignition, .read_current = unused_read_current, .set_fan_enabled = unused_set_fan_enabled, diff --git a/board/boards/uno.h b/board/boards/uno.h index f5d097fd0fc..6c7f0b69ba6 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -145,15 +145,6 @@ void uno_set_can_mode(uint8_t mode){ } } -void uno_usb_power_mode_tick(uint32_t uptime){ - UNUSED(uptime); - if(bootkick_timer != 0U){ - bootkick_timer--; - } else { - uno_set_bootkick(false); - } -} - bool uno_check_ignition(void){ // ignition is checked through harness return harness_check_ignition(); @@ -276,7 +267,6 @@ const board board_uno = { .set_usb_power_mode = uno_set_usb_power_mode, .set_gps_mode = uno_set_gps_mode, .set_can_mode = uno_set_can_mode, - .usb_power_mode_tick = uno_usb_power_mode_tick, .check_ignition = uno_check_ignition, .read_current = unused_read_current, .set_fan_enabled = uno_set_fan_enabled, diff --git a/board/boards/unused_funcs.h b/board/boards/unused_funcs.h index 54010657569..99948931ded 100644 --- a/board/boards/unused_funcs.h +++ b/board/boards/unused_funcs.h @@ -2,10 +2,6 @@ void unused_set_gps_mode(uint8_t mode) { UNUSED(mode); } -void unused_usb_power_mode_tick(uint32_t uptime) { - UNUSED(uptime); -} - void unused_set_ir_power(uint8_t percentage) { UNUSED(percentage); } diff --git a/board/boards/white.h b/board/boards/white.h index 58c71a46a40..7417e43a53c 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -257,7 +257,6 @@ const board board_white = { .set_usb_power_mode = white_set_usb_power_mode, .set_gps_mode = white_set_gps_mode, .set_can_mode = white_set_can_mode, - .usb_power_mode_tick = unused_usb_power_mode_tick, .check_ignition = white_check_ignition, .read_current = white_read_current, .set_fan_enabled = unused_set_fan_enabled, diff --git a/board/main.c b/board/main.c index 7d67119b06b..003704fe92d 100644 --- a/board/main.c +++ b/board/main.c @@ -165,8 +165,6 @@ void tick_handler(void) { if (loop_counter == 0U) { can_live = pending_can_live; - current_board->usb_power_mode_tick(uptime_cnt); - //puth(usart1_dma); puts(" "); puth(DMA2_Stream5->M0AR); puts(" "); puth(DMA2_Stream5->NDTR); puts("\n"); // reset this every 16th pass From 2261af427c68409e7386b52a696ec911406ddbd0 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 30 Aug 2022 21:21:20 -0700 Subject: [PATCH 2/7] remove more --- board/main.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/board/main.c b/board/main.c index 003704fe92d..2785e704d53 100644 --- a/board/main.c +++ b/board/main.c @@ -51,20 +51,6 @@ void debug_ring_callback(uart_ring *ring) { if (rcv == 'x') { NVIC_SystemReset(); } - - // enable CDP mode - if (rcv == 'C') { - puts("switching USB to CDP mode\n"); - current_board->set_usb_power_mode(USB_POWER_CDP); - } - if (rcv == 'c') { - puts("switching USB to client mode\n"); - current_board->set_usb_power_mode(USB_POWER_CLIENT); - } - if (rcv == 'D') { - puts("switching USB to DCP mode\n"); - current_board->set_usb_power_mode(USB_POWER_DCP); - } } } @@ -252,11 +238,6 @@ void tick_handler(void) { fan_set_power(0U); } } - - // enter CDP mode when car starts to ensure we are charging a turned off EON - if (check_started() && ((usb_power_mode != USB_POWER_CDP) || !usb_enumerated)) { - current_board->set_usb_power_mode(USB_POWER_CDP); - } } // check registers @@ -287,7 +268,6 @@ void EXTI_IRQ_Handler(void) { exti_irq_clear(); clock_init(); - current_board->set_usb_power_mode(USB_POWER_CDP); set_power_save_state(POWER_SAVE_STATUS_DISABLED); deepsleep_allowed = false; heartbeat_counter = 0U; @@ -428,7 +408,6 @@ int main(void) { if (deepsleep_allowed && !usb_enumerated && !check_started() && ignition_seen && (heartbeat_counter > 20U)) { usb_soft_disconnect(true); fan_set_power(0U); - current_board->set_usb_power_mode(USB_POWER_CLIENT); NVIC_DisableIRQ(TICK_TIMER_IRQ); delay(512000U); From 95a7bad4a499247e6838b9925b2ff6790a8a8ad1 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 30 Aug 2022 21:38:34 -0700 Subject: [PATCH 3/7] delete more --- board/boards/black.h | 24 ------------------------ board/boards/board_declarations.h | 2 -- board/boards/dos.h | 21 --------------------- board/boards/grey.h | 1 - board/boards/pedal.h | 6 ------ board/boards/red.h | 23 ----------------------- board/boards/uno.h | 20 -------------------- board/boards/white.h | 7 ------- board/health.h | 1 - python/__init__.py | 3 +-- 10 files changed, 1 insertion(+), 107 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index db34c0c0b19..74beffd3a55 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -57,26 +57,6 @@ void black_set_usb_load_switch(bool enabled) { set_gpio_output(GPIOB, 1, !enabled); } -void black_set_usb_power_mode(uint8_t mode) { - bool valid = false; - switch (mode) { - case USB_POWER_CLIENT: - black_set_usb_load_switch(false); - valid = true; - break; - case USB_POWER_CDP: - black_set_usb_load_switch(true); - valid = true; - break; - default: - puts("Invalid USB power mode\n"); - break; - } - if (valid) { - usb_power_mode = mode; - } -} - void black_set_gps_mode(uint8_t mode) { switch (mode) { case GPS_DISABLED: @@ -162,9 +142,6 @@ void black_init(void) { // Turn on USB load switch. black_set_usb_load_switch(true); - // Set right power mode - black_set_usb_power_mode(USB_POWER_CDP); - // Initialize harness harness_init(); @@ -215,7 +192,6 @@ const board board_black = { .enable_can_transceiver = black_enable_can_transceiver, .enable_can_transceivers = black_enable_can_transceivers, .set_led = black_set_led, - .set_usb_power_mode = black_set_usb_power_mode, .set_gps_mode = black_set_gps_mode, .set_can_mode = black_set_can_mode, .check_ignition = black_check_ignition, diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index 4ea6554d2e2..2b2c3419c8b 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -72,5 +72,3 @@ struct board { #define CAN_MODE_GMLAN_CAN3 2U #define CAN_MODE_OBD_CAN2 3U -// ********************* Globals ********************** -uint8_t usb_power_mode = USB_POWER_NONE; diff --git a/board/boards/dos.h b/board/boards/dos.h index 77400d6b93d..62ceea3f0c3 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -53,26 +53,6 @@ void dos_set_bootkick(bool enabled){ set_gpio_output(GPIOC, 4, !enabled); } -void dos_set_usb_power_mode(uint8_t mode) { - bool valid = false; - switch (mode) { - case USB_POWER_CLIENT: - dos_set_bootkick(false); - valid = true; - break; - case USB_POWER_CDP: - dos_set_bootkick(true); - valid = true; - break; - default: - puts("Invalid USB power mode\n"); - break; - } - if (valid) { - usb_power_mode = mode; - } -} - void dos_set_can_mode(uint8_t mode){ switch (mode) { case CAN_MODE_NORMAL: @@ -212,7 +192,6 @@ const board board_dos = { .enable_can_transceiver = dos_enable_can_transceiver, .enable_can_transceivers = dos_enable_can_transceivers, .set_led = dos_set_led, - .set_usb_power_mode = dos_set_usb_power_mode, .set_gps_mode = unused_set_gps_mode, .set_can_mode = dos_set_can_mode, .check_ignition = dos_check_ignition, diff --git a/board/boards/grey.h b/board/boards/grey.h index 3271d89f616..b589df4a800 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -46,7 +46,6 @@ const board board_grey = { .enable_can_transceiver = white_enable_can_transceiver, .enable_can_transceivers = white_enable_can_transceivers, .set_led = white_set_led, - .set_usb_power_mode = white_set_usb_power_mode, .set_gps_mode = grey_set_gps_mode, .set_can_mode = white_set_can_mode, .check_ignition = white_check_ignition, diff --git a/board/boards/pedal.h b/board/boards/pedal.h index f89b7610137..51dfc486f61 100644 --- a/board/boards/pedal.h +++ b/board/boards/pedal.h @@ -30,11 +30,6 @@ void pedal_set_led(uint8_t color, bool enabled) { } } -void pedal_set_usb_power_mode(uint8_t mode){ - usb_power_mode = mode; - puts("Trying to set USB power mode on pedal. This is not supported.\n"); -} - void pedal_set_gps_mode(uint8_t mode) { UNUSED(mode); puts("Trying to set ESP/GPS mode on pedal. This is not supported.\n"); @@ -89,7 +84,6 @@ const board board_pedal = { .enable_can_transceiver = pedal_enable_can_transceiver, .enable_can_transceivers = pedal_enable_can_transceivers, .set_led = pedal_set_led, - .set_usb_power_mode = pedal_set_usb_power_mode, .set_gps_mode = pedal_set_gps_mode, .set_can_mode = pedal_set_can_mode, .check_ignition = pedal_check_ignition, diff --git a/board/boards/red.h b/board/boards/red.h index e30077a1fb6..c032a653d28 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -53,25 +53,6 @@ void red_set_usb_load_switch(bool enabled) { set_gpio_output(GPIOB, 14, !enabled); } -void red_set_usb_power_mode(uint8_t mode) { - bool valid = false; - switch (mode) { - case USB_POWER_CLIENT: - red_set_usb_load_switch(false); - valid = true; - break; - case USB_POWER_CDP: - red_set_usb_load_switch(true); - valid = true; - break; - default: - break; - } - if (valid) { - usb_power_mode = mode; - } -} - void red_set_can_mode(uint8_t mode) { switch (mode) { case CAN_MODE_NORMAL: @@ -139,9 +120,6 @@ void red_init(void) { // Turn on USB load switch. red_set_usb_load_switch(true); - // Set right power mode - red_set_usb_power_mode(USB_POWER_CDP); - // Initialize harness harness_init(); @@ -192,7 +170,6 @@ const board board_red = { .enable_can_transceiver = red_enable_can_transceiver, .enable_can_transceivers = red_enable_can_transceivers, .set_led = red_set_led, - .set_usb_power_mode = red_set_usb_power_mode, .set_gps_mode = unused_set_gps_mode, .set_can_mode = red_set_can_mode, .check_ignition = red_check_ignition, diff --git a/board/boards/uno.h b/board/boards/uno.h index 6c7f0b69ba6..9b289cd4e90 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -73,25 +73,6 @@ void uno_set_phone_power(bool enabled){ set_gpio_output(GPIOB, 4, enabled); } -void uno_set_usb_power_mode(uint8_t mode) { - bool valid = false; - switch (mode) { - case USB_POWER_CLIENT: - valid = true; - break; - case USB_POWER_CDP: - uno_bootkick(); - valid = true; - break; - default: - puts("Invalid USB power mode\n"); - break; - } - if (valid) { - usb_power_mode = mode; - } -} - void uno_set_gps_mode(uint8_t mode) { switch (mode) { case GPS_DISABLED: @@ -264,7 +245,6 @@ const board board_uno = { .enable_can_transceiver = uno_enable_can_transceiver, .enable_can_transceivers = uno_enable_can_transceivers, .set_led = uno_set_led, - .set_usb_power_mode = uno_set_usb_power_mode, .set_gps_mode = uno_set_gps_mode, .set_can_mode = uno_set_can_mode, .check_ignition = uno_check_ignition, diff --git a/board/boards/white.h b/board/boards/white.h index 7417e43a53c..35d56481f6a 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -43,7 +43,6 @@ void white_set_led(uint8_t color, bool enabled) { } void white_set_usb_power_mode(uint8_t mode){ - bool valid_mode = true; switch (mode) { case USB_POWER_CLIENT: // B2,A13: set client mode @@ -61,14 +60,9 @@ void white_set_usb_power_mode(uint8_t mode){ set_gpio_output(GPIOA, 13, 0); break; default: - valid_mode = false; puts("Invalid usb power mode\n"); break; } - - if (valid_mode) { - usb_power_mode = mode; - } } void white_set_gps_mode(uint8_t mode) { @@ -254,7 +248,6 @@ const board board_white = { .enable_can_transceiver = white_enable_can_transceiver, .enable_can_transceivers = white_enable_can_transceivers, .set_led = white_set_led, - .set_usb_power_mode = white_set_usb_power_mode, .set_gps_mode = white_set_gps_mode, .set_can_mode = white_set_can_mode, .check_ignition = white_check_ignition, diff --git a/board/health.h b/board/health.h index 3c7d144225c..a2355fbfbbe 100644 --- a/board/health.h +++ b/board/health.h @@ -14,7 +14,6 @@ struct __attribute__((packed)) health_t { uint8_t controls_allowed_pkt; uint8_t gas_interceptor_detected_pkt; uint8_t car_harness_status_pkt; - uint8_t usb_power_mode_pkt; uint8_t safety_mode_pkt; uint16_t safety_param_pkt; uint8_t fault_status_pkt; diff --git a/python/__init__.py b/python/__init__.py index e06cf0ba1ce..fc0f0acfd56 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -175,7 +175,7 @@ class Panda: CAN_PACKET_VERSION = 2 HEALTH_PACKET_VERSION = 8 - HEALTH_STRUCT = struct.Struct(" Date: Tue, 30 Aug 2022 22:38:36 -0700 Subject: [PATCH 4/7] board tick --- board/boards/black.h | 1 + board/boards/board_declarations.h | 3 ++- board/boards/dos.h | 8 +++++++- board/boards/grey.h | 1 + board/boards/pedal.h | 1 + board/boards/red.h | 1 + board/boards/uno.h | 11 ++++++++++- board/boards/unused_funcs.h | 4 ++++ board/boards/white.h | 1 + board/main.c | 4 +++- board/main_comms.h | 5 ----- 11 files changed, 31 insertions(+), 9 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 74beffd3a55..293a48dd9b5 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -181,6 +181,7 @@ const harness_configuration black_harness_config = { const board board_black = { .board_type = "Black", + .board_tick = unused_board_tick, .harness_config = &black_harness_config, .has_gps = true, .has_hw_gmlan = false, diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index 2b2c3419c8b..f037eb25cd6 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -13,6 +13,7 @@ typedef void (*board_set_fan_enabled)(bool enabled); typedef void (*board_set_phone_power)(bool enabled); typedef void (*board_set_clock_source_mode)(uint8_t mode); typedef void (*board_set_siren)(bool enabled); +typedef void (*board_board_tick)(void); struct board { const char *board_type; @@ -37,6 +38,7 @@ struct board { board_set_phone_power set_phone_power; board_set_clock_source_mode set_clock_source_mode; board_set_siren set_siren; + board_board_tick board_tick; }; // ******************* Definitions ******************** @@ -71,4 +73,3 @@ struct board { #define CAN_MODE_GMLAN_CAN2 1U #define CAN_MODE_GMLAN_CAN3 2U #define CAN_MODE_OBD_CAN2 3U - diff --git a/board/boards/dos.h b/board/boards/dos.h index 62ceea3f0c3..6b84a213b4d 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -53,6 +53,11 @@ void dos_set_bootkick(bool enabled){ set_gpio_output(GPIOC, 4, !enabled); } +void dos_board_tick(void) { + // TODO: bootkick logic here + dos_set_bootkick(true); +} + void dos_set_can_mode(uint8_t mode){ switch (mode) { case CAN_MODE_NORMAL: @@ -181,6 +186,7 @@ const harness_configuration dos_harness_config = { const board board_dos = { .board_type = "Dos", + .board_tick = dos_board_tick, .harness_config = &dos_harness_config, .has_gps = false, .has_hw_gmlan = false, @@ -200,5 +206,5 @@ const board board_dos = { .set_ir_power = dos_set_ir_power, .set_phone_power = unused_set_phone_power, .set_clock_source_mode = dos_set_clock_source_mode, - .set_siren = dos_set_siren + .set_siren = unused_set_siren }; diff --git a/board/boards/grey.h b/board/boards/grey.h index b589df4a800..fa5e67d259d 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -35,6 +35,7 @@ void grey_set_gps_mode(uint8_t mode) { const board board_grey = { .board_type = "Grey", + .board_tick = unused_board_tick, .harness_config = &white_harness_config, .has_gps = true, .has_hw_gmlan = true, diff --git a/board/boards/pedal.h b/board/boards/pedal.h index 51dfc486f61..ccd36b89b9f 100644 --- a/board/boards/pedal.h +++ b/board/boards/pedal.h @@ -73,6 +73,7 @@ const harness_configuration pedal_harness_config = { const board board_pedal = { .board_type = "Pedal", + .board_tick = unused_board_tick, .harness_config = &pedal_harness_config, .has_gps = false, .has_hw_gmlan = false, diff --git a/board/boards/red.h b/board/boards/red.h index c032a653d28..2ba2ee1e3d8 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -159,6 +159,7 @@ const harness_configuration red_harness_config = { const board board_red = { .board_type = "Red", + .board_tick = unused_board_tick, .harness_config = &red_harness_config, .has_gps = false, .has_hw_gmlan = false, diff --git a/board/boards/uno.h b/board/boards/uno.h index 9b289cd4e90..56a118f2916 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -56,7 +56,7 @@ void uno_set_gps_load_switch(bool enabled) { } void uno_set_bootkick(bool enabled){ - if(enabled){ + if (enabled) { set_gpio_output(GPIOB, 14, false); } else { // We want the pin to be floating, not forced high! @@ -126,6 +126,14 @@ void uno_set_can_mode(uint8_t mode){ } } +void uno_board_tick(void) { + if (bootkick_timer != 0U) { + bootkick_timer--; + } else { + uno_set_bootkick(false); + } +} + bool uno_check_ignition(void){ // ignition is checked through harness return harness_check_ignition(); @@ -234,6 +242,7 @@ const harness_configuration uno_harness_config = { const board board_uno = { .board_type = "Uno", + .board_tick = uno_board_tick, .harness_config = &uno_harness_config, .has_gps = true, .has_hw_gmlan = false, diff --git a/board/boards/unused_funcs.h b/board/boards/unused_funcs.h index 99948931ded..1d532de799b 100644 --- a/board/boards/unused_funcs.h +++ b/board/boards/unused_funcs.h @@ -25,3 +25,7 @@ void unused_set_siren(bool enabled) { uint32_t unused_read_current(void) { return 0U; } + +void unused_board_tick(void) { + +} \ No newline at end of file diff --git a/board/boards/white.h b/board/boards/white.h index 35d56481f6a..266370afe18 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -237,6 +237,7 @@ const harness_configuration white_harness_config = { const board board_white = { .board_type = "White", + .board_tick = unused_board_tick, .harness_config = &white_harness_config, .has_gps = false, .has_hw_gmlan = true, diff --git a/board/main.c b/board/main.c index 2785e704d53..422d619752f 100644 --- a/board/main.c +++ b/board/main.c @@ -146,6 +146,7 @@ void tick_handler(void) { // tick drivers fan_tick(); + current_board->board_tick(); // decimated to 1Hz if (loop_counter == 0U) { @@ -379,7 +380,8 @@ int main(void) { #ifdef DEBUG_FAULTS if(fault_status == FAULT_STATUS_NONE){ #endif - uint32_t div_mode = ((usb_power_mode == USB_POWER_DCP) ? 4U : 1U); + //uint32_t div_mode = ((usb_power_mode == USB_POWER_DCP) ? 4U : 1U); + uint32_t div_mode = 1U; // useful for debugging, fade breaks = panda is overloaded for(uint32_t fade = 0U; fade < MAX_LED_FADE; fade += div_mode){ diff --git a/board/main_comms.h b/board/main_comms.h index 1f4914a87ef..770c3daaf1b 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -25,7 +25,6 @@ int get_health_pkt(void *dat) { health->can_fwd_errs_pkt = can_fwd_errs; health->gmlan_send_errs_pkt = gmlan_send_errs; health->car_harness_status_pkt = car_harness_status; - health->usb_power_mode_pkt = usb_power_mode; health->safety_mode_pkt = (uint8_t)(current_safety_mode); health->safety_param_pkt = current_safety_param; health->alternative_experience_pkt = alternative_experience; @@ -459,10 +458,6 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { can_loopback = (req->param1 > 0U); can_init_all(); break; - // **** 0xe6: set USB power - case 0xe6: - current_board->set_usb_power_mode(req->param1); - break; // **** 0xe7: set power save state case 0xe7: set_power_save_state(req->param1); From 7f9393a671795d156bac6ef886ec1d00848882f3 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 31 Aug 2022 13:27:02 -0700 Subject: [PATCH 5/7] update health --- board/boards/board_declarations.h | 2 -- board/boards/dos.h | 7 +++++++ board/health.h | 4 +++- board/main.c | 3 +-- python/__init__.py | 20 ++++++++++---------- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index f037eb25cd6..95a1ab178e0 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -3,7 +3,6 @@ typedef void (*board_init)(void); typedef void (*board_enable_can_transceiver)(uint8_t transceiver, bool enabled); typedef void (*board_enable_can_transceivers)(bool enabled); typedef void (*board_set_led)(uint8_t color, bool enabled); -typedef void (*board_set_usb_power_mode)(uint8_t mode); typedef void (*board_set_gps_mode)(uint8_t mode); typedef void (*board_set_can_mode)(uint8_t mode); typedef bool (*board_check_ignition)(void); @@ -28,7 +27,6 @@ struct board { board_enable_can_transceiver enable_can_transceiver; board_enable_can_transceivers enable_can_transceivers; board_set_led set_led; - board_set_usb_power_mode set_usb_power_mode; board_set_gps_mode set_gps_mode; board_set_can_mode set_can_mode; board_check_ignition check_ignition; diff --git a/board/boards/dos.h b/board/boards/dos.h index 6b84a213b4d..db4c37516f7 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -55,6 +55,10 @@ void dos_set_bootkick(bool enabled){ void dos_board_tick(void) { // TODO: bootkick logic here + + // block bootkick on: + // - shutdown + dos_set_bootkick(true); } @@ -158,6 +162,9 @@ void dos_init(void) { dos_set_led(LED_GREEN, false); dos_set_led(LED_BLUE, false); + // Bootkick + dos_set_bootkick(true); + // Set normal CAN mode dos_set_can_mode(CAN_MODE_NORMAL); diff --git a/board/health.h b/board/health.h index a2355fbfbbe..084c03a4280 100644 --- a/board/health.h +++ b/board/health.h @@ -1,5 +1,7 @@ // When changing this struct, python/__init__.py needs to be kept up to date! -#define HEALTH_PACKET_VERSION 8 + +#define HEALTH_PACKET_VERSION 9 + struct __attribute__((packed)) health_t { uint32_t uptime_pkt; uint32_t voltage_pkt; diff --git a/board/main.c b/board/main.c index 422d619752f..d661ec6d449 100644 --- a/board/main.c +++ b/board/main.c @@ -380,8 +380,7 @@ int main(void) { #ifdef DEBUG_FAULTS if(fault_status == FAULT_STATUS_NONE){ #endif - //uint32_t div_mode = ((usb_power_mode == USB_POWER_DCP) ? 4U : 1U); - uint32_t div_mode = 1U; + const uint32_t div_mode = 1U; // useful for debugging, fade breaks = panda is overloaded for(uint32_t fade = 0U; fade < MAX_LED_FADE; fade += div_mode){ diff --git a/python/__init__.py b/python/__init__.py index fc0f0acfd56..7344b872589 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -174,7 +174,7 @@ class Panda: HW_TYPE_RED_PANDA = b'\x07' CAN_PACKET_VERSION = 2 - HEALTH_PACKET_VERSION = 8 + HEALTH_PACKET_VERSION = 9 HEALTH_STRUCT = struct.Struct(" Date: Wed, 31 Aug 2022 17:12:22 -0700 Subject: [PATCH 6/7] dos bootkicking --- board/boards/board_declarations.h | 2 +- board/boards/dos.h | 13 ++++++------- board/boards/uno.h | 5 ++++- board/boards/unused_funcs.h | 6 ++++-- board/main.c | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index 95a1ab178e0..41eff37d186 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -12,7 +12,7 @@ typedef void (*board_set_fan_enabled)(bool enabled); typedef void (*board_set_phone_power)(bool enabled); typedef void (*board_set_clock_source_mode)(uint8_t mode); typedef void (*board_set_siren)(bool enabled); -typedef void (*board_board_tick)(void); +typedef void (*board_board_tick)(bool ignition, bool usb_enum, bool heartbeat_seen); struct board { const char *board_type; diff --git a/board/boards/dos.h b/board/boards/dos.h index db4c37516f7..d99898343e2 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -53,13 +53,12 @@ void dos_set_bootkick(bool enabled){ set_gpio_output(GPIOC, 4, !enabled); } -void dos_board_tick(void) { - // TODO: bootkick logic here - - // block bootkick on: - // - shutdown - - dos_set_bootkick(true); +void dos_board_tick(bool ignition, bool usb_enum, bool heartbeat_seen) { + if (ignition && !usb_enum) { + dos_set_bootkick(true); + } else if (heartbeat_seen) { + dos_set_bootkick(false); + } } void dos_set_can_mode(uint8_t mode){ diff --git a/board/boards/uno.h b/board/boards/uno.h index 56a118f2916..1115c5f8b39 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -126,7 +126,10 @@ void uno_set_can_mode(uint8_t mode){ } } -void uno_board_tick(void) { +void uno_board_tick(bool ignition, bool usb_enum, bool heartbeat_seen) { + UNUSED(ignition); + UNUSED(usb_enum); + UNUSED(heartbeat_seen); if (bootkick_timer != 0U) { bootkick_timer--; } else { diff --git a/board/boards/unused_funcs.h b/board/boards/unused_funcs.h index 1d532de799b..be675d89fd1 100644 --- a/board/boards/unused_funcs.h +++ b/board/boards/unused_funcs.h @@ -26,6 +26,8 @@ uint32_t unused_read_current(void) { return 0U; } -void unused_board_tick(void) { - +void unused_board_tick(bool ignition, bool usb_enum, bool heartbeat_seen) { + UNUSED(ignition); + UNUSED(usb_enum); + UNUSED(heartbeat_seen); } \ No newline at end of file diff --git a/board/main.c b/board/main.c index d661ec6d449..b3800ef4dd0 100644 --- a/board/main.c +++ b/board/main.c @@ -146,7 +146,7 @@ void tick_handler(void) { // tick drivers fan_tick(); - current_board->board_tick(); + current_board->board_tick(check_started(), usb_enumerated, heartbeat_counter == 0); // decimated to 1Hz if (loop_counter == 0U) { From 1d272c76e721b29e015c2438b1c5f92659463b48 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 31 Aug 2022 19:13:06 -0700 Subject: [PATCH 7/7] cleanup --- board/boards/dos.h | 4 ++++ board/main.c | 15 ++++++++------- tests/misra/test_misra.sh | 6 +++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/board/boards/dos.h b/board/boards/dos.h index d99898343e2..1e61a2398b7 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -55,9 +55,13 @@ void dos_set_bootkick(bool enabled){ void dos_board_tick(bool ignition, bool usb_enum, bool heartbeat_seen) { if (ignition && !usb_enum) { + // enable bootkick if ignition seen dos_set_bootkick(true); } else if (heartbeat_seen) { + // disable once openpilot is up dos_set_bootkick(false); + } else { + } } diff --git a/board/main.c b/board/main.c index b3800ef4dd0..29a3ff8a494 100644 --- a/board/main.c +++ b/board/main.c @@ -144,9 +144,8 @@ void tick_handler(void) { // siren current_board->set_siren((loop_counter & 1U) && (siren_enabled || (siren_countdown > 0U))); - // tick drivers + // tick drivers at 8Hz fan_tick(); - current_board->board_tick(check_started(), usb_enumerated, heartbeat_counter == 0); // decimated to 1Hz if (loop_counter == 0U) { @@ -173,6 +172,10 @@ void tick_handler(void) { // unless we are in power saving mode current_board->set_led(LED_BLUE, (uptime_cnt & 1U) && (power_save_status == POWER_SAVE_STATUS_ENABLED)); + // tick drivers at 1Hz + const bool recent_heartbeat = heartbeat_counter == 0U; + current_board->board_tick(check_started(), usb_enumerated, recent_heartbeat); + // increase heartbeat counter and cap it at the uint32 limit if (heartbeat_counter < __UINT32_MAX__) { heartbeat_counter += 1U; @@ -378,19 +381,17 @@ int main(void) { for (cnt=0;;cnt++) { if (power_save_status == POWER_SAVE_STATUS_DISABLED) { #ifdef DEBUG_FAULTS - if(fault_status == FAULT_STATUS_NONE){ + if (fault_status == FAULT_STATUS_NONE) { #endif - const uint32_t div_mode = 1U; - // useful for debugging, fade breaks = panda is overloaded - for(uint32_t fade = 0U; fade < MAX_LED_FADE; fade += div_mode){ + for (uint32_t fade = 0U; fade < MAX_LED_FADE; fade += 1U) { current_board->set_led(LED_RED, true); delay(fade >> 4); current_board->set_led(LED_RED, false); delay((MAX_LED_FADE - fade) >> 4); } - for(uint32_t fade = MAX_LED_FADE; fade > 0U; fade -= div_mode){ + for (uint32_t fade = MAX_LED_FADE; fade > 0U; fade -= 1U) { current_board->set_led(LED_RED, true); delay(fade >> 4); current_board->set_led(LED_RED, false); diff --git a/tests/misra/test_misra.sh b/tests/misra/test_misra.sh index b3bb2ca0a61..b9d298c23a8 100755 --- a/tests/misra/test_misra.sh +++ b/tests/misra/test_misra.sh @@ -26,7 +26,7 @@ fi printf "\nPANDA F4 CODE\n" $CPPCHECK -DPANDA -DSTM32F4 -UPEDAL -DCAN3 -DUID_BASE \ - --suppressions-list=suppressions.txt --suppress=*:*inc/* \ + --suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \ -I $PANDA_DIR/board/ --dump --enable=all --inline-suppr --force \ $PANDA_DIR/board/main.c 2>/tmp/misra/cppcheck_f4_output.txt @@ -39,7 +39,7 @@ misra_f4_output=$( cat /tmp/misra/misra_f4_output.txt | grep -v ": information: printf "\nPANDA H7 CODE\n" $CPPCHECK -DPANDA -DSTM32H7 -UPEDAL -DUID_BASE \ - --suppressions-list=suppressions.txt --suppress=*:*inc/* \ + --suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \ -I $PANDA_DIR/board/ --dump --enable=all --inline-suppr --force \ $PANDA_DIR/board/main.c 2>/tmp/misra/cppcheck_h7_output.txt @@ -52,7 +52,7 @@ misra_h7_output=$( cat /tmp/misra/misra_h7_output.txt | grep -v ": information: printf "\nPEDAL CODE\n" $CPPCHECK -UPANDA -DSTM32F2 -DPEDAL -UCAN3 \ - --suppressions-list=suppressions.txt --suppress=*:*inc/* \ + --suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \ -I $PANDA_DIR/board/ --dump --enable=all --inline-suppr --force \ $PANDA_DIR/board/pedal/main.c 2>/tmp/misra/cppcheck_pedal_output.txt