Repository navigation
[drivers][serial] improve TIOCGWINSZ and termios updates - #11891
BernardXiong wants to merge 3 commits into
Conversation
- query the terminal directly instead of reading through finsh - parse the CSI 8 ; rows ; cols t response strictly - time out after 200 ms and fall back to the default size - skip UART reconfiguration when termios settings are unchanged - query the console window size before installing the serial bypass
|
👋 感谢您对 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)
🏷️ Tag: components_driver_serial_v2Reviewers: @Ryan-CW-Code Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-10-25 19:31 CST)
📝 Review Instructions
|
- format the zero-initialized response buffer - no functional change
|
| while(i < _TIO_BUFLEN) | ||
| start_tick = rt_tick_get(); | ||
| while (i < sizeof(response) - 1 && | ||
| rt_tick_get() - start_tick < rt_tick_from_millisecond(200)) |
There was a problem hiding this comment.
rt_tick_get_delta考虑了tick绕回,可以替代手写判断
There was a problem hiding this comment.
已按建议改为 rt_tick_get_delta(start_tick),commit cd8ac61。
| while (i < _TIO_BUFLEN) | ||
| start_tick = rt_tick_get(); | ||
| while (i < sizeof(response) - 1 && | ||
| rt_tick_get() - start_tick < rt_tick_from_millisecond(200)) |
There was a problem hiding this comment.
rt_tick_get_delta考虑了tick绕回,可以替代手写判断
There was a problem hiding this comment.
已按建议改为 rt_tick_get_delta(start_tick),commit cd8ac61。
| while (i < sizeof(response) - 1 && | ||
| rt_tick_get() - start_tick < rt_tick_from_millisecond(200)) | ||
| { | ||
| if (rt_device_read(dev, -1, &response[i], 1) == 1) |
There was a problem hiding this comment.
是否需要判断之前是否设置过O_NONBLOCK,v2默认read是永久等待
There was a problem hiding this comment.
已处理,commit cd8ac61。
- v1 的
_serial_poll_rx()本身是非阻塞的,问题只在 v2:RT_SERIAL_RX_BLOCKING下rx_timeout默认是RT_WAITING_FOREVER,单次rt_device_read()可能永久阻塞,而 200 ms 的 tick 检查只在两次 read 之间生效。 - 现在查询期间通过
RT_SERIAL_CTRL_GET_RX_TIMEOUT/RT_SERIAL_CTRL_SET_RX_TIMEOUT保存并切到RT_WAITING_NO,循环结束后恢复原值;poll 模式(rx_bufsz == 0)下这两个命令返回-RT_EPERM,保持原有的非阻塞行为。 - 没有直接判断
O_NONBLOCK:这里是直接操作 device,而不是 fd,O_NONBLOCK属于 fd 层状态;保存/恢复设备层rx_timeout更直接,也不会重新配置 UART。
Use rt_tick_get_delta() for the 200 ms response timeout in both serial versions instead of open-coding the wraparound-safe subtraction. In serial v2, a blocking read waits forever when the terminal does not answer the CSI 18 t query, so the tick-based timeout was ineffective. Save the current RX timeout, switch to RT_WAITING_NO while reading the response, and restore it afterwards. Verified by compiling dev_serial.o (v1) and dev_serial_v2.o (v2) for qemu-virt64-aarch64. Co-authored-by: DeepSeek 4.1 Flash <noreply@deepseek.com>
拉取/合并请求描述:(PR description)
为什么提交这份PR (why to submit this PR)
TIOCGWINSZ read the terminal response through finsh_getchar(), which only works in the tshell thread and can consume input. Termios updates also reconfigured the UART even when no hardware setting changed, resetting the FIFO.
你的解决方案是什么 (what is your solution)
请提供验证的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