From fd68c26abaeafa9f2d00a0cae7121e14fe6b79c9 Mon Sep 17 00:00:00 2001 From: rbiasini Date: Wed, 10 Jul 2019 17:27:26 -0700 Subject: [PATCH] Propagate can_push errors (#249) * Misra 17.7: counting can_push errors --- board/drivers/can.h | 11 +++++++---- board/drivers/gmlan_alt.h | 10 ++++++---- board/main.c | 12 ++++++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/board/drivers/can.h b/board/drivers/can.h index e6ad107b60157a..3db2110512fa70 100644 --- a/board/drivers/can.h +++ b/board/drivers/can.h @@ -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 @@ -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) { @@ -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; @@ -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)); } } diff --git a/board/drivers/gmlan_alt.h b/board/drivers/gmlan_alt.h index 55260162cfde27..c697a21b41ef9c 100644 --- a/board/drivers/gmlan_alt.h +++ b/board/drivers/gmlan_alt.h @@ -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; @@ -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]); @@ -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; } diff --git a/board/main.c b/board/main.c index 78e7a993aa3046..eeb0496b01e8c5 100644 --- a/board/main.c +++ b/board/main.c @@ -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 @@ -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); }