Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: log can core reset when switching multiplexing #1972

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -99,7 +99,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
Loading