Skip to content

Commit

Permalink
fdcan: rate limit CAN core reset (#2137)
Browse files Browse the repository at this point in the history
* rate limit can core resets

* overflow protection

* U
  • Loading branch information
sshane authored Jan 30, 2025
1 parent edf0428 commit 3ff9730
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions board/drivers/fdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ static bool can_set_speed(uint8_t can_number) {
}

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);
static uint32_t last_reset = 0U;
uint32_t time = microsecond_timer_get();

// Resetting CAN core is a slow blocking operation, limit frequency
if (get_ts_elapsed(time, last_reset) > 100000U) { // 10 Hz
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);
last_reset = time;
}
}

void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
Expand Down

0 comments on commit 3ff9730

Please sign in to comment.