From 368770ce36354c7ff17e9c8575307a07aca61367 Mon Sep 17 00:00:00 2001 From: wdfk-prog <1425075683@qq.com> Date: Sat, 7 Feb 2026 15:28:02 +0800 Subject: [PATCH] fix(CAN): Avoid double counting RX overflow drops --- components/drivers/can/dev_can.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/drivers/can/dev_can.c b/components/drivers/can/dev_can.c index e0cf0db9b27..04f12620f3e 100644 --- a/components/drivers/can/dev_can.c +++ b/components/drivers/can/dev_can.c @@ -968,15 +968,19 @@ rt_err_t rt_hw_can_register(struct rt_can_device *can, */ void rt_hw_can_isr(struct rt_can_device *can, int event) { + rt_bool_t is_rxof_event = RT_FALSE; + switch (event & 0xff) { case RT_CAN_EVENT_RXOF_IND: { rt_base_t level; + is_rxof_event = RT_TRUE; level = rt_hw_local_irq_disable(); can->status.dropedrcvpkg++; rt_hw_local_irq_enable(level); } + /* FALLTHROUGH: RX overflow still tries to fetch one pending frame into software FIFO. */ case RT_CAN_EVENT_RX_IND: { struct rt_can_msg tmpmsg; @@ -1020,7 +1024,10 @@ void rt_hw_can_isr(struct rt_can_device *can, int event) else if (!rt_list_isempty(&rx_fifo->uselist)) { listmsg = rt_list_entry(rx_fifo->uselist.next, struct rt_can_msg_list, list); - can->status.dropedrcvpkg++; + if (!is_rxof_event) + { + can->status.dropedrcvpkg++; + } rt_list_remove(&listmsg->list); #ifdef RT_CAN_USING_HDR rt_list_remove(&listmsg->hdrlist);