Add safety hook for ignition and have GM use gear selector to determine ignition

master
Thomas Helms 2018-04-10 17:55:55 -07:00
parent 2434f1cdab
commit 4fc83a5f5c
7 changed files with 60 additions and 4 deletions

View File

@ -104,7 +104,14 @@ int get_health_pkt(void *dat) {
#ifdef PANDA
health->current = adc_get(ADCCHAN_CURRENT);
health->started = (GPIOA->IDR & (1 << 1)) == 0;
int safety_ignition = safety_ignition_hook();
if (safety_ignition < 0) {
//Use the GPIO pin to determine ignition
health->started = (GPIOA->IDR & (1 << 1)) == 0;
} else {
//Current safety hooks want to determine ignition (ex: GM)
health-> started = safety_ignition;
}
#else
health->current = 0;
health->started = (GPIOC->IDR & (1 << 13)) != 0;
@ -534,8 +541,8 @@ int main() {
usb_init();
// default to silent mode to prevent issues with Ford
safety_set_mode(SAFETY_NOOUTPUT, 0);
can_silent = ALL_CAN_SILENT;
safety_set_mode(SAFETY_GM, 0);
can_silent = ALL_CAN_LIVE;
can_init_all();
adc_init();

View File

@ -1,14 +1,17 @@
void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send);
int safety_tx_lin_hook(int lin_num, uint8_t *data, int len);
int safety_ignition_hook();
typedef void (*safety_hook_init)(int16_t param);
typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push);
typedef int (*tx_hook)(CAN_FIFOMailBox_TypeDef *to_send);
typedef int (*tx_lin_hook)(int lin_num, uint8_t *data, int len);
typedef int (*ign_hook)();
typedef struct {
safety_hook_init init;
ign_hook ignition;
rx_hook rx;
tx_hook tx;
tx_lin_hook tx_lin;
@ -38,6 +41,13 @@ int safety_tx_lin_hook(int lin_num, uint8_t *data, int len){
return current_hooks->tx_lin(lin_num, data, len);
}
// -1 = Disabled (Use GPIO to determine ignition)
// 0 = Off (not started)
// 1 = On (started)
int safety_ignition_hook() {
return current_hooks->ignition();
}
typedef struct {
uint16_t id;
const safety_hooks *hooks;

View File

@ -14,11 +14,16 @@ static int nooutput_tx_lin_hook(int lin_num, uint8_t *data, int len) {
return false;
}
static int nooutput_ign_hook() {
return -1;
}
const safety_hooks nooutput_hooks = {
.init = nooutput_init,
.rx = default_rx_hook,
.tx = nooutput_tx_hook,
.tx_lin = nooutput_tx_lin_hook,
.ignition = nooutput_ign_hook
};
// *** all output safety mode ***
@ -35,10 +40,15 @@ static int alloutput_tx_lin_hook(int lin_num, uint8_t *data, int len) {
return true;
}
static int alloutput_ign_hook() {
return -1;
}
const safety_hooks alloutput_hooks = {
.init = alloutput_init,
.rx = default_rx_hook,
.tx = alloutput_tx_hook,
.tx_lin = alloutput_tx_lin_hook,
.ignition = alloutput_ign_hook
};

View File

@ -31,9 +31,14 @@ static void elm327_init(int16_t param) {
controls_allowed = 1;
}
static int elm327_ign_hook() {
return -1;
}
const safety_hooks elm327_hooks = {
.init = elm327_init,
.rx = elm327_rx_hook,
.tx = elm327_tx_hook,
.tx_lin = elm327_tx_lin_hook,
.ignition = elm327_ign_hook
};

View File

@ -16,8 +16,9 @@ int gm_speed = 0;
// silence everything if stock ECUs are still online
int gm_ascm_detected = 0;
static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
int gm_ignition_started = 0;
static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
uint32_t addr;
if (to_push->RIR & 4) {
// Extended
@ -29,6 +30,12 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
addr = to_push->RIR >> 21;
}
if (addr == 0x135) {
//Gear selector (used for determining ignition)
int gear = to_push->RDLR & 0x7;
gm_ignition_started = gear > 0; //Park = 0. If out of park, we're "on."
}
// sample speed, really only care if car is moving or not
// rear left wheel speed
if (addr == 842) {
@ -170,6 +177,11 @@ static int gm_tx_lin_hook(int lin_num, uint8_t *data, int len) {
static void gm_init(int16_t param) {
controls_allowed = 0;
gm_ignition_started = 0;
}
static int gm_ign_hook() {
return gm_ignition_started;
}
const safety_hooks gm_hooks = {
@ -177,5 +189,6 @@ const safety_hooks gm_hooks = {
.rx = gm_rx_hook,
.tx = gm_tx_hook,
.tx_lin = gm_tx_lin_hook,
.ignition = gm_ign_hook
};

View File

@ -119,10 +119,15 @@ static void honda_init(int16_t param) {
controls_allowed = 0;
}
static int honda_ign_hook() {
return -1;
}
const safety_hooks honda_hooks = {
.init = honda_init,
.rx = honda_rx_hook,
.tx = honda_tx_hook,
.tx_lin = honda_tx_lin_hook,
.ignition = honda_ign_hook
};

View File

@ -161,11 +161,16 @@ static void toyota_init(int16_t param) {
dbc_eps_torque_factor = param;
}
static int toyota_ign_hook() {
return -1;
}
const safety_hooks toyota_hooks = {
.init = toyota_init,
.rx = toyota_rx_hook,
.tx = toyota_tx_hook,
.tx_lin = toyota_tx_lin_hook,
.ignition = toyota_ign_hook
};
static void toyota_nolimits_init(int16_t param) {
@ -179,4 +184,5 @@ const safety_hooks toyota_nolimits_hooks = {
.rx = toyota_rx_hook,
.tx = toyota_tx_hook,
.tx_lin = toyota_tx_lin_hook,
.ignition = toyota_ign_hook
};