From d6668fe4ef1cc2c568e18200ad284e4c5fef7358 Mon Sep 17 00:00:00 2001 From: robbederks Date: Thu, 11 Jun 2020 18:14:41 -0700 Subject: [PATCH] Turn on fan if panda is enumerated but not receiving heartbeat (#553) * fix linter * Turn on fan if panda is enumerated but not receiving heartbeat * Upped to 50% --- board/drivers/usb.h | 5 +++++ board/main.c | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/board/drivers/usb.h b/board/drivers/usb.h index 4cfd90d..2ec4b8b 100644 --- a/board/drivers/usb.h +++ b/board/drivers/usb.h @@ -957,6 +957,11 @@ void OTG_FS_IRQ_Handler(void) { NVIC_EnableIRQ(OTG_FS_IRQn); } +bool usb_enumerated(void) { + // This relies on the USB being suspended after no activity for 3ms. Seems pretty stable + return (!(USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS)); +} + // ***************************** USB init ***************************** void usb_init(void) { diff --git a/board/main.c b/board/main.c index 2df28fd..8e62e69 100644 --- a/board/main.c +++ b/board/main.c @@ -697,7 +697,6 @@ void TIM1_BRK_TIM9_IRQ_Handler(void) { // Tick fan driver fan_tick(); - //puts("Fan speed: "); puth((unsigned int) fan_rpm); puts("rpm\n"); // set green LED to be controls allowed current_board->set_led(LED_GREEN, controls_allowed); @@ -725,9 +724,15 @@ void TIM1_BRK_TIM9_IRQ_Handler(void) { set_power_save_state(POWER_SAVE_STATUS_ENABLED); } - // Also disable fan and IR when the heartbeat goes missing - current_board->set_fan_power(0U); + // Also disable IR when the heartbeat goes missing current_board->set_ir_power(0U); + + // If enumerated but no heartbeat (phone up, boardd not running), turn the fan on to cool the device + if(usb_enumerated()){ + current_board->set_fan_power(50U); + } else { + current_board->set_fan_power(0U); + } } // enter CDP mode when car starts to ensure we are charging a turned off EON