Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

safety: fix race condition on controls allowed timeout #1436

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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: 0 additions & 10 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,6 @@ void tick_handler(void) {

}

// exit controls allowed if unused by openpilot for a few seconds
if (controls_allowed && !heartbeat_engaged) {
heartbeat_engaged_mismatches += 1U;
if (heartbeat_engaged_mismatches >= 3U) {
controls_allowed = 0U;
}
} else {
heartbeat_engaged_mismatches = 0U;
}

if (!heartbeat_disabled) {
// if the heartbeat has been gone for a while, go to SILENT safety mode and enter power save
if (heartbeat_counter >= (check_started() ? HEARTBEAT_IGNITION_CNT_ON : HEARTBEAT_IGNITION_CNT_OFF)) {
Expand Down
14 changes: 12 additions & 2 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ int get_addr_check_index(CANPacket_t *to_push, AddrCheckStruct addr_list[], cons
return index;
}

// 1Hz safety function called by main. Now just a check for lagging safety messages
// 1Hz safety function called by main
void safety_tick(const addr_checks *rx_checks) {
// check for lagging messages
bool rx_checks_invalid = false;
uint32_t ts = microsecond_timer_get();
if (rx_checks != NULL) {
Expand All @@ -182,8 +183,17 @@ void safety_tick(const addr_checks *rx_checks) {
}
}
}

safety_rx_checks_invalid = rx_checks_invalid;

// exit controls allowed if unused by openpilot for a few seconds
if (controls_allowed && !heartbeat_engaged) {
heartbeat_engaged_mismatches += 1U;
if (heartbeat_engaged_mismatches >= 3U) {
controls_allowed = 0U;
}
} else {
heartbeat_engaged_mismatches = 0U;
}
}

void update_counter(AddrCheckStruct addr_list[], int index, uint8_t counter) {
Expand Down