Skip to content

Commit

Permalink
WTF WHY WAS THIS SHIT PUT EVERYWHERE
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed May 23, 2019
1 parent 3cf8db9 commit 3810452
Show file tree
Hide file tree
Showing 20 changed files with 17 additions and 211 deletions.
20 changes: 8 additions & 12 deletions board/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ int can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem);
#define ALL_CAN_LIVE 0

#include "llcan.h"
#include "lline_relay.h"

int can_live = 0, pending_can_live = 0, can_loopback = 0, can_silent = ALL_CAN_SILENT;

Expand Down Expand Up @@ -381,17 +380,14 @@ void can_rx(uint8_t can_number) {
to_push.RDTR = (to_push.RDTR & 0xFFFF000F) | (bus_number << 4);

// forwarding (panda only)
// relay engaged or relay isn't controlled, allow fwd
if ((get_lline_status() != 0) || !relay_control) {
int bus_fwd_num = can_forwarding[bus_number] != -1 ? can_forwarding[bus_number] : safety_fwd_hook(bus_number, &to_push);
if (bus_fwd_num != -1) {
CAN_FIFOMailBox_TypeDef to_send;
to_send.RIR = to_push.RIR | 1; // TXRQ
to_send.RDTR = to_push.RDTR;
to_send.RDLR = to_push.RDLR;
to_send.RDHR = to_push.RDHR;
can_send(&to_send, bus_fwd_num);
}
int bus_fwd_num = can_forwarding[bus_number] != -1 ? can_forwarding[bus_number] : safety_fwd_hook(bus_number, &to_push);
if (bus_fwd_num != -1) {
CAN_FIFOMailBox_TypeDef to_send;
to_send.RIR = to_push.RIR | 1; // TXRQ
to_send.RDTR = to_push.RDTR;
to_send.RDLR = to_push.RDLR;
to_send.RDHR = to_push.RDHR;
can_send(&to_send, bus_fwd_num);
}

safety_rx_hook(&to_push);
Expand Down
88 changes: 0 additions & 88 deletions board/drivers/lline_relay.h

This file was deleted.

6 changes: 2 additions & 4 deletions board/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void periph_init() {
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;
//RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;
//RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
Expand Down Expand Up @@ -349,9 +349,7 @@ void gpio_init() {
set_gpio_output(GPIOA, 14, 1);

// C10,C11: L-Line setup on USART 3
// LLine now used for relay output
set_gpio_output(GPIOC, 10, 1);
//set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
set_gpio_alternate(GPIOC, 11, GPIO_AF7_USART3);
set_gpio_pullup(GPIOC, 11, PULL_UP);
#endif
Expand Down
15 changes: 0 additions & 15 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ void usb_cb_ep3_out(uint8_t *usbdata, int len, int hardwired) {

uint8_t bus_number = (to_push.RDTR >> 4) & CAN_BUS_NUM_MASK;
can_send(&to_push, bus_number);

// TODO: wtf, why is this here?
// Enable relay on can message if allowed.
// Temporary until OP has support for relay
if (safety_relay_hook()) {
set_lline_output(1);
}
}
}

Expand Down Expand Up @@ -414,14 +407,6 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired) {
}
break;
}
// **** 0xf3: set l-line relay
case 0xf3:
{
if (safety_relay_hook()) {
set_lline_output(setup->b.wValue.w == 1);
}
break;
}
default:
puts("NO HANDLER ");
puth(setup->b.bRequest);
Expand Down
16 changes: 1 addition & 15 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ struct sample_t {
int max;
} sample_t_default = {{0}, 0, 0};

// no float support in STM32F2 micros (cortex-m3)
#ifdef PANDA
// safety code requires floats
struct lookup_t {
float x[3];
float y[3];
};
#endif

void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send);
Expand All @@ -27,21 +25,14 @@ int driver_limit_check(int val, int val_last, struct sample_t *val_driver,
const int MAX, const int MAX_RATE_UP, const int MAX_RATE_DOWN,
const int MAX_ALLOWANCE, const int DRIVER_FACTOR);
int rt_rate_limit_check(int val, int val_last, const int MAX_RT_DELTA);
#ifdef PANDA
float interpolate(struct lookup_t xy, float x);

void lline_relay_init (void);
void lline_relay_release (void);
void set_lline_output(int to_set);
#endif

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 int (*fwd_hook)(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd);
typedef int (*relay_hook)();

typedef struct {
safety_hook_init init;
Expand All @@ -50,7 +41,6 @@ typedef struct {
tx_hook tx;
tx_lin_hook tx_lin;
fwd_hook fwd;
relay_hook relay;
} safety_hooks;

// This can be set by the safety hooks.
Expand Down Expand Up @@ -97,10 +87,6 @@ int safety_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
return current_hooks->fwd(bus_num, to_fwd);
}

int safety_relay_hook(void) {
return current_hooks->relay();
}

typedef struct {
uint16_t id;
const safety_hooks *hooks;
Expand Down
4 changes: 0 additions & 4 deletions board/safety/safety_cadillac.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
static void cadillac_init(int16_t param) {
controls_allowed = 0;
cadillac_ign = 0;
#ifdef PANDA
lline_relay_release();
#endif
}

static int cadillac_ign_hook() {
Expand All @@ -131,5 +128,4 @@ const safety_hooks cadillac_hooks = {
.tx_lin = nooutput_tx_lin_hook,
.ignition = cadillac_ign_hook,
.fwd = alloutput_fwd_hook,
.relay = nooutput_relay_hook,
};
4 changes: 0 additions & 4 deletions board/safety/safety_chrysler.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ static int chrysler_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {

static void chrysler_init(int16_t param) {
chrysler_camera_detected = 0;
#ifdef PANDA
lline_relay_release();
#endif
}

static int chrysler_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
Expand All @@ -153,5 +150,4 @@ const safety_hooks chrysler_hooks = {
.tx_lin = nooutput_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = chrysler_fwd_hook,
.relay = nooutput_relay_hook,
};
16 changes: 0 additions & 16 deletions board/safety/safety_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ int default_ign_hook() {

static void nooutput_init(int16_t param) {
controls_allowed = 0;
#ifdef PANDA
lline_relay_release();
#endif
}

static int nooutput_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
Expand All @@ -25,27 +22,19 @@ static int nooutput_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
return -1;
}

static int nooutput_relay_hook(int to_set) {
return false;
}

const safety_hooks nooutput_hooks = {
.init = nooutput_init,
.rx = default_rx_hook,
.tx = nooutput_tx_hook,
.tx_lin = nooutput_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = nooutput_fwd_hook,
.relay = nooutput_relay_hook,
};

// *** all output safety mode ***

static void alloutput_init(int16_t param) {
controls_allowed = 1;
#ifdef PANDA
lline_relay_release();
#endif
}

static int alloutput_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
Expand All @@ -60,16 +49,11 @@ static int alloutput_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
return -1;
}

static int alloutput_relay_hook(int to_set) {
return true;
}

const safety_hooks alloutput_hooks = {
.init = alloutput_init,
.rx = default_rx_hook,
.tx = alloutput_tx_hook,
.tx_lin = alloutput_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = alloutput_fwd_hook,
.relay = alloutput_relay_hook,
};
1 change: 0 additions & 1 deletion board/safety/safety_elm327.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ const safety_hooks elm327_hooks = {
.tx_lin = elm327_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = nooutput_fwd_hook,
.relay = nooutput_relay_hook,
};
1 change: 0 additions & 1 deletion board/safety/safety_ford.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,4 @@ const safety_hooks ford_hooks = {
.tx_lin = nooutput_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = nooutput_fwd_hook,
.relay = nooutput_relay_hook,
};
4 changes: 0 additions & 4 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
static void gm_init(int16_t param) {
controls_allowed = 0;
gm_ignition_started = 0;
#ifdef PANDA
lline_relay_release();
#endif
}

static int gm_ign_hook() {
Expand All @@ -244,5 +241,4 @@ const safety_hooks gm_hooks = {
.tx_lin = nooutput_tx_lin_hook,
.ignition = gm_ign_hook,
.fwd = nooutput_fwd_hook,
.relay = nooutput_relay_hook,
};
1 change: 0 additions & 1 deletion board/safety/safety_gm_ascm.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ const safety_hooks gm_ascm_hooks = {
.tx_lin = nooutput_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = gm_ascm_fwd_hook,
.relay = nooutput_relay_hook,
};

8 changes: 0 additions & 8 deletions board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,13 @@ static void honda_init(int16_t param) {
controls_allowed = 0;
bosch_hardware = false;
honda_alt_brake_msg = false;
#ifdef PANDA
lline_relay_release();
#endif
}

static void honda_bosch_init(int16_t param) {
controls_allowed = 0;
bosch_hardware = true;
// Checking for alternate brake override from safety parameter
honda_alt_brake_msg = param == 1 ? true : false;
#ifdef PANDA
lline_relay_release();
#endif
}

static int honda_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
Expand Down Expand Up @@ -182,7 +176,6 @@ const safety_hooks honda_hooks = {
.tx_lin = nooutput_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = honda_fwd_hook,
.relay = nooutput_relay_hook,
};

const safety_hooks honda_bosch_hooks = {
Expand All @@ -192,5 +185,4 @@ const safety_hooks honda_bosch_hooks = {
.tx_lin = nooutput_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = honda_bosch_fwd_hook,
.relay = nooutput_relay_hook,
};
4 changes: 0 additions & 4 deletions board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ static int hyundai_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
static void hyundai_init(int16_t param) {
controls_allowed = 0;
hyundai_giraffe_switch_2 = 0;
#ifdef PANDA
lline_relay_release();
#endif
}

const safety_hooks hyundai_hooks = {
Expand All @@ -164,5 +161,4 @@ const safety_hooks hyundai_hooks = {
.tx_lin = nooutput_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = hyundai_fwd_hook,
.relay = nooutput_relay_hook,
};
Loading

0 comments on commit 3810452

Please sign in to comment.