Files
panda-meb/board/safety/safety_defaults.h
Adeeb Shihadeh 4a5fc24b75 safety: move controls_allowed and relay malfunction reset (#944)
* safety: reset controls allowed and relay malfunction before safety mode init

* add back for all output
2022-05-19 14:03:43 -07:00

93 lines
2.0 KiB
C

const addr_checks default_rx_checks = {
.check = NULL,
.len = 0,
};
int default_rx_hook(CANPacket_t *to_push) {
UNUSED(to_push);
return true;
}
// *** no output safety mode ***
static const addr_checks* nooutput_init(uint16_t param) {
UNUSED(param);
return &default_rx_checks;
}
static int nooutput_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
UNUSED(to_send);
UNUSED(longitudinal_allowed);
return false;
}
static int nooutput_tx_lin_hook(int lin_num, uint8_t *data, int len) {
UNUSED(lin_num);
UNUSED(data);
UNUSED(len);
return false;
}
static int default_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
UNUSED(bus_num);
UNUSED(to_fwd);
return -1;
}
const safety_hooks nooutput_hooks = {
.init = nooutput_init,
.rx = default_rx_hook,
.tx = nooutput_tx_hook,
.tx_lin = nooutput_tx_lin_hook,
.fwd = default_fwd_hook,
};
// *** all output safety mode ***
// Enables passthrough mode where relay is open and bus 0 gets forwarded to bus 2 and vice versa
const uint16_t ALLOUTPUT_PARAM_PASSTHROUGH = 1;
bool alloutput_passthrough = false;
static const addr_checks* alloutput_init(uint16_t param) {
controls_allowed = true;
alloutput_passthrough = GET_FLAG(param, ALLOUTPUT_PARAM_PASSTHROUGH);
return &default_rx_checks;
}
static int alloutput_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
UNUSED(to_send);
UNUSED(longitudinal_allowed);
return true;
}
static int alloutput_tx_lin_hook(int lin_num, uint8_t *data, int len) {
UNUSED(lin_num);
UNUSED(data);
UNUSED(len);
return true;
}
static int alloutput_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
UNUSED(to_fwd);
int bus_fwd = -1;
if (alloutput_passthrough) {
if (bus_num == 0) {
bus_fwd = 2;
}
if (bus_num == 2) {
bus_fwd = 0;
}
}
return bus_fwd;
}
const safety_hooks alloutput_hooks = {
.init = alloutput_init,
.rx = default_rx_hook,
.tx = alloutput_tx_hook,
.tx_lin = alloutput_tx_lin_hook,
.fwd = alloutput_fwd_hook,
};