Skip to content

Commit

Permalink
Propagate can_push errors (commaai#249)
Browse files Browse the repository at this point in the history
* Misra 17.7: counting can_push errors
  • Loading branch information
rbiasini authored Jul 11, 2019
1 parent ce1daf2 commit fd68c26
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
11 changes: 7 additions & 4 deletions board/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ typedef struct {

#define BUS_MAX 4U

uint32_t can_send_errs = 0;
uint32_t can_fwd_errs = 0;
uint32_t gmlan_send_errs = 0;
extern int can_live, pending_can_live;

// must reinit after changing these
Expand Down Expand Up @@ -255,7 +258,7 @@ void process_can(uint8_t can_number) {
to_push.RDTR = (CAN->sTxMailBox[0].TDTR & 0xFFFF000FU) | ((CAN_BUS_RET_FLAG | bus_number) << 4);
to_push.RDLR = CAN->sTxMailBox[0].TDLR;
to_push.RDHR = CAN->sTxMailBox[0].TDHR;
can_push(&can_rx_q, &to_push);
can_send_errs += !can_push(&can_rx_q, &to_push);
}

if ((CAN->TSR & CAN_TSR_TERR0) == CAN_TSR_TERR0) {
Expand Down Expand Up @@ -324,7 +327,7 @@ void can_rx(uint8_t can_number) {
safety_rx_hook(&to_push);

set_led(LED_BLUE, 1);
can_push(&can_rx_q, &to_push);
can_send_errs += !can_push(&can_rx_q, &to_push);

// next
CAN->RF0R |= CAN_RF0R_RFOM0;
Expand All @@ -351,9 +354,9 @@ void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number) {
to_push->RDTR &= 0xF;
if ((bus_number == 3U) && (can_num_lookup[3] == 0xFFU)) {
// TODO: why uint8 bro? only int8?
bitbang_gmlan(to_push);
gmlan_send_errs += !bitbang_gmlan(to_push);
} else {
can_push(can_queues[bus_number], to_push);
can_fwd_errs += !can_push(can_queues[bus_number], to_push);
process_can(CAN_NUM_FROM_BUS_NUM(bus_number));
}
}
Expand Down
10 changes: 6 additions & 4 deletions board/drivers/gmlan_alt.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void set_bitbanged_gmlan(int val) {
char pkt_stuffed[MAX_BITS_CAN_PACKET];
int gmlan_sending = -1;
int gmlan_sendmax = -1;
bool gmlan_send_ok = true;

int gmlan_silent_count = 0;
int gmlan_fail_count = 0;
Expand Down Expand Up @@ -220,6 +221,7 @@ void TIM4_IRQHandler(void) {
gmlan_fail_count++;
if (gmlan_fail_count == MAX_FAIL_COUNT) {
puts("GMLAN ERR: giving up send\n");
gmlan_send_ok = false;
}
} else {
set_bitbanged_gmlan(pkt_stuffed[gmlan_sending]);
Expand Down Expand Up @@ -263,22 +265,22 @@ void TIM4_IRQHandler(void) {
}
}

void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
bool bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
gmlan_send_ok = true;
gmlan_alt_mode = BITBANG;
// TODO: make failure less silent
if (gmlan_sendmax == -1) {

if (gmlan_sendmax == -1) {
int len = get_bit_message(pkt_stuffed, to_bang);
gmlan_fail_count = 0;
gmlan_silent_count = 0;
gmlan_sending = 0;
gmlan_sendmax = len;

// setup for bitbang loop
set_bitbanged_gmlan(1); // recessive
set_gpio_mode(GPIOB, 13, MODE_OUTPUT);

setup_timer4();
}
return gmlan_send_ok;
}

12 changes: 6 additions & 6 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ int get_health_pkt(void *dat) {
uint8_t started_pkt;
uint8_t controls_allowed_pkt;
uint8_t gas_interceptor_detected_pkt;
uint8_t started_signal_detected_pkt;
uint8_t started_alt_pkt;
uint32_t can_send_errs_pkt;
uint32_t can_fwd_errs_pkt;
uint32_t gmlan_send_errs_pkt;
} *health = dat;

//Voltage will be measured in mv. 5000 = 5V
Expand All @@ -132,10 +133,9 @@ int get_health_pkt(void *dat) {

health->controls_allowed_pkt = controls_allowed;
health->gas_interceptor_detected_pkt = gas_interceptor_detected;

// DEPRECATED
health->started_alt_pkt = 0;
health->started_signal_detected_pkt = 0;
health->can_send_errs_pkt = can_send_errs;
health->can_fwd_errs_pkt = can_fwd_errs;
health->gmlan_send_errs_pkt = gmlan_send_errs;

return sizeof(*health);
}
Expand Down

0 comments on commit fd68c26

Please sign in to comment.