From d99789b4871d2f6d72ae2131b2b9772704103149 Mon Sep 17 00:00:00 2001 From: Robin Madsen Date: Thu, 3 Sep 2026 14:48:51 +0200 Subject: [PATCH] Tesla - Wake on CAN --- .../package_sources/panda/board/drivers/can_common.h | 8 ++++++++ .../panda/board/drivers/can_common_declarations.h | 3 +++ artifacts/package_sources/panda/board/main.c | 8 +++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/artifacts/package_sources/panda/board/drivers/can_common.h b/artifacts/package_sources/panda/board/drivers/can_common.h index 6d0385a53..6ebe3d2cb 100644 --- a/artifacts/package_sources/panda/board/drivers/can_common.h +++ b/artifacts/package_sources/panda/board/drivers/can_common.h @@ -11,6 +11,10 @@ can_health_t can_health[PANDA_CAN_CNT] = {{0}, {0}, {0}}; bool ignition_can = false; uint32_t ignition_can_cnt = 0U; +// Wake (bootkick) the device from CAN messages, without engaging ignition +bool wake_on_can = false; +uint32_t wake_on_can_cnt = 0U; + // set only once a Toyota SecOC hybrid gear source is positively identified: those cars keep // the harness ignition line live in Park, so the reported line has to follow the gear instead bool ignition_can_gates_line = false; @@ -229,6 +233,10 @@ void ignition_can_hook(CANPacket_t *msg) { bool tesla_in_park = !tesla_gear_seen || (tesla_gear == TESLA_DI_GEAR_P); ignition_can = (power_state == 0x3) && !tesla_in_park; // VEHICLE_POWER_STATE_DRIVE=3 ignition_can_cnt = 0U; + // Also bootkick the device on any non-OFF LV power state (e.g. Tesla + // app wake / preconditioning), so sunnypilot is loaded before driving + wake_on_can = power_state != 0x0; // not VEHICLE_POWER_STATE_OFF + wake_on_can_cnt = 0U; } prev_counter_tesla = counter; } diff --git a/artifacts/package_sources/panda/board/drivers/can_common_declarations.h b/artifacts/package_sources/panda/board/drivers/can_common_declarations.h index 2b4c9350d..7ea1a28f0 100644 --- a/artifacts/package_sources/panda/board/drivers/can_common_declarations.h +++ b/artifacts/package_sources/panda/board/drivers/can_common_declarations.h @@ -32,6 +32,9 @@ extern can_health_t can_health[PANDA_CAN_CNT]; extern bool ignition_can; extern uint32_t ignition_can_cnt; extern bool ignition_can_gates_line; +// Wake (bootkick) the device from CAN messages, without engaging ignition +extern bool wake_on_can; +extern uint32_t wake_on_can_cnt; extern bool can_silent; extern bool can_loopback; diff --git a/artifacts/package_sources/panda/board/main.c b/artifacts/package_sources/panda/board/main.c index 8033ad629..959e97610 100644 --- a/artifacts/package_sources/panda/board/main.c +++ b/artifacts/package_sources/panda/board/main.c @@ -193,7 +193,8 @@ static void tick_handler(void) { // tick drivers at 1Hz bool started = harness_check_ignition() || ignition_can; - bootkick_tick(started, recent_heartbeat); + bool wake_up = started || wake_on_can; + bootkick_tick(wake_up, recent_heartbeat); // increase heartbeat counter and cap it at the uint32 limit if (heartbeat_counter < UINT32_MAX) { @@ -273,11 +274,16 @@ static void tick_handler(void) { if (ignition_can_cnt > 2U) { ignition_can = false; } + // Set wake on can after 2s of no CAN seen + if (wake_on_can_cnt > 2U) { + wake_on_can = false; + } // on to the next one uptime_cnt += 1U; safety_mode_cnt += 1U; ignition_can_cnt += 1U; + wake_on_can_cnt += 1U; // synchronous safety check safety_tick(¤t_safety_config);