Skip to content

fix(can): Eliminate persistent CAN RX latency after startup bursts#64

Merged
qzhhhi merged 1 commit into
mainfrom
dev/fix-can
Jul 6, 2026
Merged

fix(can): Eliminate persistent CAN RX latency after startup bursts#64
qzhhhi merged 1 commit into
mainfrom
dev/fix-can

Conversation

@qzhhhi

@qzhhhi qzhhhi commented Jul 6, 2026

Copy link
Copy Markdown
Member

Drain all pending CAN frames in each RX interrupt on c_board and rmcs_board, and clear the MCAN RX new-message interrupt before draining the FIFO.

This fixes a long-standing issue where heavy CAN traffic during board startup could leave a backlog that delayed all later CAN reception.

本次变更优化了 c_board 与 rmcs_board 的 CAN 接收中断处理,核心目标是消除启动阶段突发流量后残留的 RX 积压与后续接收延迟。

主要改动:

  • c_board:Can::handle_uplink 改为在 FIFO0 中仍有待处理报文时持续循环读取并逐条处理,而不是只读一帧;每次处理后清除 FIFO0 读完成标记。
  • rmcs_board:Can::handle_uplink 同样改为持续读取 MCAN RX FIFO0,直到队列为空为止。
  • rmcs_board:Can::irq_handler 调整了中断标志清除顺序,先处理并清除 RXFIFO0_NEW_MSG,执行接收处理后,再统一清除剩余标志,避免一次性清除带来的处理时序问题。

整体效果是让中断服务期间尽可能“清空”当前积压的 CAN 帧,减少高负载启动场景下的接收滞后。

Drain all pending CAN frames in each RX interrupt on c_board and rmcs_board, and clear the MCAN RX new-message interrupt before draining the FIFO.

This fixes a long-standing issue where heavy CAN traffic during board startup could leave a backlog that delayed all later CAN reception.
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 532541f5-0d4c-4e19-9edc-357f7b087695

📥 Commits

Reviewing files that changed from the base of the PR and between ce221e5 and 6718650.

📒 Files selected for processing (2)
  • firmware/c_board/app/src/can/can.hpp
  • firmware/rmcs_board/app/src/can/can.hpp

Walkthrough

修改c_board与rmcs_board固件中CAN模块的上行接收处理逻辑,将原先单次读取一条报文的方式改为循环读取直至FIFO为空。同时调整rmcs_board中断处理函数对中断标志的清除时机,改为分阶段清除。未涉及公开接口声明变更。

Changes

CAN上行FIFO批量读取改造

Layer / File(s) Summary
c_board FIFO0循环读取与解析
firmware/c_board/app/src/can/can.hpp
handle_uplink基于RF0R.FMP0引入while循环,循环体内重新断言寄存器状态、解析RIR/RDTR/RDLR/RDHR并组装数据,调用serializer.write_can后设置RF0R.RFOM0逐条清除FIFO0。
rmcs_board FIFO0循环读取与分阶段标志清除
firmware/rmcs_board/app/src/can/can.hpp
handle_uplink循环调用mcan_read_rxfifo直到返回空状态再逐条写入serializer.write_canirq_handler引入remaining_flags,先清除并处理RXFIFO0_NEW_MSG标志,再统一清除剩余标志。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant IRQ as CAN中断
  participant Handle as handle_uplink
  participant Reg as FIFO寄存器/MCAN接口
  participant Serializer as serializer

  IRQ->>Handle: 触发上行中断处理
  loop 队列非空
    Handle->>Reg: 读取一条报文数据
    Handle->>Serializer: write_can(数据)
    Handle->>Reg: 清除/推进队列指针
  end
  Handle-->>IRQ: 处理完成返回
Loading

Poem

一只兔子蹲在FIFO边,
从前只啃一口就走远,
如今循环嚼到盘底光,
报文颗颗都不留仓,
蹦跳着把标志位轻轻拂 🐰📡

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了通过清空启动突发后的 CAN 接收积压来消除持续 RX 延迟的核心改动。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/fix-can

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qzhhhi qzhhhi merged commit ee674bd into main Jul 6, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in RMCS Slave SDK Jul 6, 2026
@qzhhhi qzhhhi deleted the dev/fix-can branch July 6, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant