Tesla - Wake on CAN

This commit is contained in:
2026-09-03 14:48:51 +02:00
parent 7745f48100
commit d99789b487
3 changed files with 18 additions and 1 deletions

View File

@@ -11,6 +11,10 @@ can_health_t can_health[PANDA_CAN_CNT] = {{0}, {0}, {0}};
bool ignition_can = false; bool ignition_can = false;
uint32_t ignition_can_cnt = 0U; 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 // 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 // the harness ignition line live in Park, so the reported line has to follow the gear instead
bool ignition_can_gates_line = false; 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); 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 = (power_state == 0x3) && !tesla_in_park; // VEHICLE_POWER_STATE_DRIVE=3
ignition_can_cnt = 0U; 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; prev_counter_tesla = counter;
} }

View File

@@ -32,6 +32,9 @@ extern can_health_t can_health[PANDA_CAN_CNT];
extern bool ignition_can; extern bool ignition_can;
extern uint32_t ignition_can_cnt; extern uint32_t ignition_can_cnt;
extern bool ignition_can_gates_line; 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_silent;
extern bool can_loopback; extern bool can_loopback;

View File

@@ -193,7 +193,8 @@ static void tick_handler(void) {
// tick drivers at 1Hz // tick drivers at 1Hz
bool started = harness_check_ignition() || ignition_can; 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 // increase heartbeat counter and cap it at the uint32 limit
if (heartbeat_counter < UINT32_MAX) { if (heartbeat_counter < UINT32_MAX) {
@@ -273,11 +274,16 @@ static void tick_handler(void) {
if (ignition_can_cnt > 2U) { if (ignition_can_cnt > 2U) {
ignition_can = false; 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 // on to the next one
uptime_cnt += 1U; uptime_cnt += 1U;
safety_mode_cnt += 1U; safety_mode_cnt += 1U;
ignition_can_cnt += 1U; ignition_can_cnt += 1U;
wake_on_can_cnt += 1U;
// synchronous safety check // synchronous safety check
safety_tick(&current_safety_config); safety_tick(&current_safety_config);