bxCAN: check overrun flag on error irq

This commit is contained in:
Igor Biletksyy
2023-06-27 16:03:43 -07:00
parent 6309bb8a6a
commit 3a06eeec3c
2 changed files with 9 additions and 5 deletions

View File

@@ -74,6 +74,12 @@ void update_can_health_pkt(uint8_t can_number, uint32_t ir_reg) {
if (ir_reg != 0U) {
can_health[can_number].total_error_cnt += 1U;
// RX message lost due to FIFO overrun
if ((CAN->RF0R & (CAN_RF0R_FOVR0)) != 0) {
can_health[can_number].total_rx_lost_cnt += 1U;
CAN->RF0R &= ~(CAN_RF0R_FOVR0);
}
llcan_clear_send(CAN);
}
@@ -165,11 +171,6 @@ void can_rx(uint8_t can_number) {
CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number);
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);
if ((CAN->RF0R & (CAN_RF0R_FOVR0)) != 0) { // RX message lost due to FIFO overrun
can_health[can_number].total_rx_lost_cnt += 1U;
CAN->RF0R &= ~(CAN_RF0R_FOVR0);
}
while ((CAN->RF0R & CAN_RF0R_FMP0) != 0) {
can_health[can_number].total_rx_cnt += 1U;

View File

@@ -110,6 +110,9 @@ bool llcan_init(CAN_TypeDef *CAN_obj) {
// enable certain CAN interrupts
register_set_bits(&(CAN_obj->IER), CAN_IER_TMEIE | CAN_IER_FMPIE0 | CAN_IER_ERRIE | CAN_IER_LECIE | CAN_IER_BOFIE | CAN_IER_EPVIE | CAN_IER_EWGIE | CAN_IER_FOVIE0 | CAN_IER_FFIE0);
// clear overrun flag on init
CAN_obj->RF0R &= ~(CAN_RF0R_FOVR0);
if (CAN_obj == CAN1) {
NVIC_EnableIRQ(CAN1_TX_IRQn);
NVIC_EnableIRQ(CAN1_RX0_IRQn);