Skip to content

Commit

Permalink
enabled DEBUG_SAFETY
Browse files Browse the repository at this point in the history
  • Loading branch information
MoreTore committed Nov 19, 2023
1 parent ecdeb00 commit f5bcccc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion board/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//#define DEBUG_FAULTS
//#define DEBUG_COMMS
//#define DEBUG_FAN
//#define DEBUG_SAFETY
#define DEBUG_SAFETY

#define CAN_INIT_TIMEOUT_MS 500U
#define DEEPSLEEP_WAKEUP_DELAY 3U
Expand Down
6 changes: 6 additions & 0 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ bool is_msg_valid(AddrCheckStruct addr_list[], int index) {
if (!addr_list[index].valid_checksum || !addr_list[index].valid_quality_flag || (addr_list[index].wrong_counters >= MAX_WRONG_COUNTERS)) {
valid = false;
controls_allowed = false;
safety_print("is_msg_valid: False");
}
}
return valid;
Expand Down Expand Up @@ -260,18 +261,21 @@ void generic_rx_checks(bool stock_ecu_detected) {
// exit controls on rising edge of gas press
if (gas_pressed && !gas_pressed_prev && !(alternative_experience & ALT_EXP_DISABLE_DISENGAGE_ON_GAS)) {
controls_allowed = false;
safety_print("generic_rx_checks L264: False");
}
gas_pressed_prev = gas_pressed;

// exit controls on rising edge of brake press
if (brake_pressed && (!brake_pressed_prev || vehicle_moving)) {
controls_allowed = false;
safety_print("generic_rx_checks L271: False");
}
brake_pressed_prev = brake_pressed;

// exit controls on rising edge of regen paddle
if (regen_braking && (!regen_braking_prev || vehicle_moving)) {
controls_allowed = false;
safety_print("generic_rx_checks L278: False");
}
regen_braking_prev = regen_braking;

Expand Down Expand Up @@ -710,6 +714,8 @@ void pcm_cruise_check(bool cruise_engaged) {
}
if (cruise_engaged && !cruise_engaged_prev) {
controls_allowed = true;
safety_print("controls_allowed: True");
}
cruise_engaged_prev = cruise_engaged;

}
9 changes: 9 additions & 0 deletions board/safety/safety_mazda.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ static int mazda_rx_hook(CANPacket_t *to_push) {
// enter controls on rising edge of ACC, exit controls on ACC off
if (addr == MAZDA_CRZ_CTRL && !radar_intercept && !use_crz_events) {
bool cruise_engaged = GET_BYTE(to_push, 0) & 0x8U;
safety_print("L93 safety_mazda.h");
pcm_cruise_check(cruise_engaged);
}

if (addr == MAZDA_CRZ_EVENTS && use_crz_events && radar_intercept) {
bool cruise_engaged = GET_BYTE(to_push, 2) & 0x1U;
safety_print("L99 safety_mazda.h");
pcm_cruise_check(cruise_engaged);
}

Expand Down Expand Up @@ -122,6 +124,7 @@ static int mazda_rx_hook(CANPacket_t *to_push) {
// enter controls on rising edge of ACC, exit controls on ACC off
if (addr == MAZDA_CRZ_CTRL) {
bool cruise_engaged = GET_BYTE(to_push, 0) & 0x8U;
safety_print("L127 safety_mazda.h");
pcm_cruise_check(cruise_engaged);
}
}
Expand Down Expand Up @@ -198,6 +201,12 @@ static const addr_checks* mazda_init(uint16_t param) {
return &mazda_rx_checks;
radar_intercept = GET_FLAG(param, MAZDA_RADAR_INTERCEPT_MODE);
use_crz_events = GET_FLAG(param, MAZDA_RI_USE_CRZ_EVENTS);
if (radar_intercept){
safety_print("radar_intercept");
}
if (use_crz_events){
safety_print("use_crz_events");
}
}

const safety_hooks mazda_hooks = {
Expand Down

0 comments on commit f5bcccc

Please sign in to comment.