Repository navigation
Conversation
RT_CAN_FILTER_STD_INIT() and the other helpers initialized their mask with 0xFFFFFFFF, which carries bits outside the identifier width: 11 bits for a standard frame and 29 bits for an extended one. A mask in Mask Mode selects the identifier bits a filter compares, so bits above the width do not belong there. Add RT_CAN_STD_ID_MASK (0x7FF) and RT_CAN_EXT_ID_MASK (0x1FFFFFFF) and use them in all twelve helper macros. Drivers that shift the mask into the hardware filter registers are unaffected, because the shifted value is the same for the old and the new mask; the change makes the API correct for drivers that use the mask in software and removes the ambiguity reported in RT-Thread#11576. Signed-off-by: ymj0440 <ymj0440@users.noreply.github.com>
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-11-25 22:28 CST)
📝 Review Instructions
|
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
Description
RT_CAN_FILTER_STD_INIT()and its siblings initialize the filter mask with0xFFFFFFFF, which carries identifier bits outside the width of the frame type: a standard identifier is 11 bits (0x7FF) and an extended one is 29 bits (0x1FFFFFFF). In Mask Mode a1bit means "this ID bit must match", so bits above the width do not belong in the mask, as raised in #11576.Changes
RT_CAN_STD_ID_MASK(0x7FF) andRT_CAN_EXT_ID_MASK(0x1FFFFFFF) next to the filter helpers;RT_CAN_USING_HDRones and the six plain ones), keeping the same frame-type mapping.How to test
prints
a.mask = 0x000007FFandb.mask = 0x1FFFFFFF; the one-argument form behaves the same. Both macro branches were compiled withRT_CAN_USING_HDRand without it.For drivers that shift the mask into the hardware filter registers, the resulting register value is unchanged:
(mask << 21) >> 160xFFE00xFFE0(mask << 21) & 0xFFFF0x00000x0000(mask << 3) >> 160xFFFF0xFFFF(mask << 3) & 0xFFFF0xFFF80xFFF8So the change does not alter the filter configuration on those BSPs; it makes the value correct for drivers that consume the mask in software and removes the ambiguity in the public API.
Fixes #11576