Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions board/drivers/bootkick.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

bool bootkick_reset_triggered = false;

void bootkick_tick(bool ignition, bool recent_heartbeat) {
void bootkick_tick(bool wake_up, bool recent_heartbeat) {
static uint16_t bootkick_last_serial_ptr = 0;
static uint8_t waiting_to_boot_countdown = 0;
static uint8_t boot_reset_countdown = 0;
static uint8_t bootkick_harness_status_prev = HARNESS_STATUS_NC;
static bool bootkick_ign_prev = false;
static bool bootkick_wake_up_prev = false;
static BootState boot_state = BOOT_BOOTKICK;
BootState boot_state_prev = boot_state;
const bool harness_inserted = (harness.status != bootkick_harness_status_prev) && (harness.status != HARNESS_STATUS_NC);

if ((ignition && !bootkick_ign_prev) || harness_inserted) {
// bootkick on rising edge of ignition or harness insertion
if ((wake_up && !bootkick_wake_up_prev) || harness_inserted) {
// bootkick on rising edge of wake-up or harness insertion
boot_state = BOOT_BOOTKICK;
} else if (recent_heartbeat) {
// disable bootkick once openpilot is up
Expand Down Expand Up @@ -55,7 +55,7 @@ void bootkick_tick(bool ignition, bool recent_heartbeat) {
}

// update state
bootkick_ign_prev = ignition;
bootkick_wake_up_prev = wake_up;
bootkick_harness_status_prev = harness.status;
bootkick_last_serial_ptr = uart_ring_som_debug.w_ptr_tx;
if (waiting_to_boot_countdown > 0U) {
Expand Down
6 changes: 5 additions & 1 deletion board/drivers/can_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ uint32_t rx_buffer_overflow = 0;

can_health_t can_health[PANDA_CAN_CNT] = {{0}, {0}, {0}};

// Ignition detected from CAN meessages
// Wake-up and ignition detected from CAN messages
bool wake_on_can = false;
uint32_t wake_on_can_cnt = 0U;
bool ignition_can = false;
uint32_t ignition_can_cnt = 0U;

Expand Down Expand Up @@ -189,6 +191,8 @@ void ignition_can_hook(CANPacket_t *msg) {
if ((counter == ((prev_counter_tesla + 1) % 16)) && (prev_counter_tesla != -1)) {
// VCFRONT_LVPowerState->VCFRONT_vehiclePowerState
int power_state = (msg->data[0] >> 5U) & 0x3U;
wake_on_can = power_state != 0x0; // VEHICLE_POWER_STATE_OFF=0
wake_on_can_cnt = 0U;
ignition_can = power_state == 0x3; // VEHICLE_POWER_STATE_DRIVE=3
ignition_can_cnt = 0U;
}
Expand Down
6 changes: 4 additions & 2 deletions board/drivers/drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

extern bool bootkick_reset_triggered;

void bootkick_tick(bool ignition, bool recent_heartbeat);
void bootkick_tick(bool wake_up, bool recent_heartbeat);

// ******************** can_common ********************

Expand Down Expand Up @@ -41,7 +41,9 @@ extern uint32_t rx_buffer_overflow;

extern can_health_t can_health[PANDA_CAN_CNT];

// Ignition detected from CAN meessages
// Wake-up and ignition detected from CAN messages
extern bool wake_on_can;
extern uint32_t wake_on_can_cnt;
extern bool ignition_can;
extern uint32_t ignition_can_cnt;

Expand Down
7 changes: 6 additions & 1 deletion board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,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) {
Expand Down Expand Up @@ -251,11 +252,15 @@ static void tick_handler(void) {
if (ignition_can_cnt > 2U) {
ignition_can = false;
}
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(&current_safety_config);
Expand Down
Loading