Skip to content

Commit

Permalink
drivers: log can core reset when switching multiplexing (commaai#1972)
Browse files Browse the repository at this point in the history
fdcan: log lost tx messages when resetting can core for multiplexing
  • Loading branch information
sshane authored Aug 27, 2024
1 parent 0a09122 commit 8587ae3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions board/drivers/bxcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ bool can_set_speed(uint8_t can_number) {
return ret;
}

void can_clear_send(CAN_TypeDef *CANx, uint8_t can_number) {
can_health[can_number].can_core_reset_cnt += 1U;
llcan_clear_send(CANx);
}

void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
CAN_TypeDef *CANx = CANIF_FROM_CAN_NUM(can_number);
uint32_t esr_reg = CANx->ESR;
Expand Down Expand Up @@ -52,8 +57,7 @@ void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
can_health[can_number].total_rx_lost_cnt += 1U;
CANx->RF0R &= ~(CAN_RF0R_FOVR0);
}
can_health[can_number].can_core_reset_cnt += 1U;
llcan_clear_send(CANx);
can_clear_send(CANx, can_number);
}
}

Expand Down
10 changes: 7 additions & 3 deletions board/drivers/fdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ bool can_set_speed(uint8_t can_number) {
return ret;
}

void can_clear_send(FDCAN_GlobalTypeDef *FDCANx, uint8_t can_number) {
can_health[can_number].can_core_reset_cnt += 1U;
can_health[can_number].total_tx_lost_cnt += (FDCAN_TX_FIFO_EL_CNT - (FDCANx->TXFQS & FDCAN_TXFQS_TFFL)); // TX FIFO msgs will be lost after reset
llcan_clear_send(FDCANx);
}

void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
FDCAN_GlobalTypeDef *FDCANx = CANIF_FROM_CAN_NUM(can_number);
uint32_t psr_reg = FDCANx->PSR;
Expand Down Expand Up @@ -75,9 +81,7 @@ void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
// 2. H7 gets stuck in bus off recovery state indefinitely
if ((((can_health[can_number].last_error == CAN_ACK_ERROR) || (can_health[can_number].last_data_error == CAN_ACK_ERROR)) && (can_health[can_number].transmit_error_cnt > 127U)) ||
((ir_reg & FDCAN_IR_BO) != 0U)) {
can_health[can_number].can_core_reset_cnt += 1U;
can_health[can_number].total_tx_lost_cnt += (FDCAN_TX_FIFO_EL_CNT - (FDCANx->TXFQS & FDCAN_TXFQS_TFFL)); // TX FIFO msgs will be lost after reset
llcan_clear_send(FDCANx);
can_clear_send(FDCANx, can_number);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void set_safety_mode(uint16_t mode, uint16_t param) {
if (current_board->has_obd) {
// Clear any pending messages in the can core (i.e. sending while comma power is unplugged)
// TODO: rewrite using hardware queues rather than fifo to cancel specific messages
llcan_clear_send(CANIF_FROM_CAN_NUM(1));
can_clear_send(CANIF_FROM_CAN_NUM(1), 1);
if (param == 0U) {
current_board->set_can_mode(CAN_MODE_OBD_CAN2);
} else {
Expand Down

0 comments on commit 8587ae3

Please sign in to comment.