Repository navigation
[components][dfs]Avoid colliding with POSIX by using the shifted 'ctr… - #11881
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-11-17 17:11 CST)
📝 Review Instructions
|
|
Rbb666
left a comment
There was a problem hiding this comment.
当前两项 CI 有明确失败,请修正后再合并:
- clang-format 22.1.8:
dev_serial_v2.h:192-194、rtdef.h:1322-1323、1343-1351的尾注对齐不符合仓库格式。 - Doxygen:
rtdef.h:1328的RT_Device_Class_##Type被解析成对 Type 的显式链接,报explicit link request to 'Type' could not be resolved。建议使用 Doxygen 代码块展示 token-paste 表达式。
日志:https://github.com/RT-Thread/rt-thread/actions/runs/41269911785/job/124740372130
https://github.com/RT-Thread/rt-thread/actions/runs/41269911855/job/124740372369
Rbb666
left a comment
There was a problem hiding this comment.
确认两处由通用控制命令重编号引入的功能回归:RT-Link 的配置命令与阻塞接收标志冲突,以及 EFM32 控制回调的 8 位命令参数截断。请同步修复相关调用方后再合并,具体触发条件和建议见两条行内意见。
已提取 PR 中的原始控制函数,以最小依赖桩进行 GCC 前后对照验证;未进行真机测试。
English: Two functional regressions were confirmed: a collision with RT-Link's blocking-receive flag and command truncation in EFM32 control callbacks. Please update the affected consumers before merging. Both were reproduced with the original control functions in minimal GCC harnesses; no hardware testing was performed.
| { | ||
| RT_DEVICE_CTRL_RESUME = RT_DEVICE_CTRL_BASE(Unknown) + 1, /**< resume device */ | ||
| RT_DEVICE_CTRL_SUSPEND, /**< suspend device */ | ||
| RT_DEVICE_CTRL_CONFIG, /**< configure device */ |
There was a problem hiding this comment.
[P2] 修复 RT-Link 的命令/标志冲突 / Fix the RT-Link command/flag collision
中文:RT_DEVICE_CTRL_CONFIG 改为 0x2003 后,与 RT_LINK_RX_BLOCKING = 0x2000 重叠。现有 rt_link_dev_control() 分别使用 cmd & RT_DEVICE_CTRL_CONFIG 和 cmd & RT_LINK_RX_BLOCKING 判断:调用 rt_device_control(dev, RT_LINK_RX_BLOCKING, RT_NULL) 会误入配置分支,返回 -RT_EINVAL;调用 rt_device_control(dev, RT_DEVICE_CTRL_CONFIG, &cfg) 又会意外清除已有的 rx_indicate,使接收回调失效并切换为阻塞接收。请同步调整 RT-Link 的命令与标志判定,避免编号重叠。
English: The new CONFIG value (0x2003) overlaps RT_LINK_RX_BLOCKING (0x2000). Since rt_link_dev_control() tests both with bitwise AND, a blocking-mode request with NULL arguments now fails with -RT_EINVAL, while an ordinary configuration request clears an existing receive callback and switches reception to blocking mode. Please update RT-Link's command/flag handling alongside this renumbering.
GCC 对照复现 / GCC reproduction:
Before: RX_BLOCKING + NULL -> ret=0, callback cleared
After: RX_BLOCKING + NULL -> ret=-22, callback retained
Before: CONFIG + valid config -> ret=0, callback retained
After: CONFIG + valid config -> ret=0, callback cleared
| RT_DEVICE_CTRL_RESUME = RT_DEVICE_CTRL_BASE(Unknown) + 1, /**< resume device */ | ||
| RT_DEVICE_CTRL_SUSPEND, /**< suspend device */ |
There was a problem hiding this comment.
[P2] 同步扩宽 EFM32 控制回调的命令参数 / Widen EFM32 control callback parameters
中文:EFM32 的 ADC、USART、LEUART、I²C、比较器和定时器控制回调仍使用 rt_uint8_t cmd,例如 rt_hs_timer_control()。新 RESUME/SUSPEND = 0x2001/0x2002 无法用 8 位表示,被截断后不能匹配对应的 switch 分支,操作仍可能返回成功但硬件状态不变。bsp/efm32/dev_misc.c:69、102 还通过 RESUME 启动温度/VDD 的 ADC 转换,更新后无法启动新转换。请将受影响回调的命令参数同步改为与设备接口一致的 int。
English: Several EFM32 control callbacks still accept rt_uint8_t cmd. The new RESUME/SUSPEND values cannot fit in eight bits, making their switch cases unreachable. Calls can report success without changing peripheral state; the temperature/VDD path also relies on RESUME to start an ADC conversion. Please change the affected callbacks to use int cmd, matching the device interface.
提取原始定时器控制函数的 GCC 对照结果 / GCC result using the extracted timer control function:
Before: resume=0x1 return=0 enabled=1 suspended=0
After: resume=0x2001 return=0 enabled=0 suspended=1
GCC also reports that the case label values exceed the command type's range.
|
本次 CI 失败位于 所有源文件编译完成后,链接阶段因 ROM 超出容量 4 字节而失败: 目前可确认的是该配置的固件体积超过 64 KB Flash 限制;是否由本 PR 的控制命令重编号引起,仍需在相同工具链与配置下对比基线和 PR 的 ELF/map 文件确认。该失败发生于 HK32F030C8(Cortex-M0),不是此前修复控制回调参数的 EFM32。 CI 日志:https://github.com/RT-Thread/rt-thread/actions/runs/43793773973/job/133058008395?pr=11881 |
通过修改 rtconfig.py的cflags if BUILD == 'debug':
CFLAGS += ' -O0 -gdwarf-2 -g'
AFLAGS += ' -gdwarf-2'
else:
CFLAGS += ' -O2'更改为: if BUILD == 'debug':
CFLAGS += ' -Og -gdwarf-2 -g'
AFLAGS += ' -gdwarf-2'
else:
CFLAGS += ' -O2' |
BernardXiong
left a comment
There was a problem hiding this comment.
【P1】Char class 命令号冲突
RT_HW_SERIAL_CTRL_GETC 现在定义为 RT_DEVICE_CTRL_BASE(Char) + 1,与 RT_DEVICE_CTRL_CHAR_STREAM 的数值完全相同(均为 0x0101):
两者都会经 rt_device_control() 分派到同一设备的 control 回调。若驱动在同一 switch 中同时处理,会产生 duplicate case 编译错误;若只处理其中一个,则会把另一个命令误判。当前树内尚无 RT_DEVICE_CTRL_CHAR_STREAM 使用点,所以未立即暴露,但本 PR 的目的正是消除命令号冲突,建议给 RT_HW_SERIAL_CTRL_* 分配独立索引区间(例如从 BASE(Char) + 0x40 起),并在头文件注明保留区间。
其余改动(Unknown class 基址、rtlink 掩码、PIN_CONFIG 偏移、RT_DEVICE_CTRL_MASK 已无引用)核对一致。
…dev command collisions: class in high byte, index low byte.
已修复该 P1 冲突。 修改文件:components/drivers/include/drivers/dev_serial_v2.h:190 RT_HW_SERIAL_CTRL_GETC 从 RT_DEVICE_CTRL_BASE(Char) + 1 调整为 + 0x40,数值由 0x0101 变为 0x0140。 |
BernardXiong
left a comment
There was a problem hiding this comment.
复核 4be939ac:P1 已修复。RT_HW_SERIAL_CTRL_GETC/PUTC/GET_DMA_PING_BUF 改为 BASE(Char)+0x40/0x41/0x42(0x0140–0x0142),与 RT_DEVICE_CTRL_CHAR_STREAM(0x0101)不再重叠,并在 dev_serial_v2.h 注明 0x40–0x4f 为硬件串口保留区间。
同时核对了 general commands 迁至 BASE(Unknown)+1..9(Unknown=31,基址 0x2000)、PIN_CONFIG_* 基址、rt-link 高字节掩码,以及 efm32 控制回调 int cmd 签名;树内未发现 RT_DEVICE_CTRL_MASK 残留或窄类型控制回调,CI 全绿。
非阻塞建议:PIN_CONFIG_* 现从 BASE(Pin)+1(0x1A01)开始,已超出仍在使用的 PIN_CONFIG_END(0x7f) / PIN_CONFIG_MAX(0xff) 边界定义;当前树内没有按范围校验的消费点,建议后续统一这两个宏或补充注释,避免外部 pinctrl 代码误用。
… nullness
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
关联issue:#5073
F_GETFL (=3) 在数值上与 RT_DEVICE_CTRL_CONFIG (=3) 撞码,F_SETFL (=4) 与 RT_DEVICE_CTRL_CLOSE (=4) 撞码。两套 cmd 共享同一个 int 参数,POSIX 路径下(fcntl → dfs_file_ioctl / dfs_file_fcntl → fops->ioctl)会被 driver 误解释。
你的解决方案是什么 (what is your solution)
1.
include/rtdef.h:把通用 cmd 编码从"低字节 index"换成"高字节 class + 低字节 index"。引入
RT_DEVICE_CTRL_BASE(Type) = (RT_Device_Class_##Type + 1) * 0x100(include/rtdef.h:1321)。通用RT_DEVICE_CTRL_*9 个宏改用BASE(Unknown) + 1..9(include/rtdef.h:1332-1340),实测落在0x2001..0x2009,与 POSIX 0–4 完全错开。RT_DEVICE_CTRL_MASK=0x1f跟 BASE 宏不兼容(BASE 把 class 放高字节,MASK 只看低 5 位),且全仓 grep 零 caller,删。拆成两个 mask:请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up