Conversation
- Updated version in Cargo.toml from 0.2.4 to 0.3.0. - Changed rdif-serial dependency to a local path. - Refactored `write_reg` method in `Kind` trait and its implementations to take `&self` instead of `&mut self`. - Updated `Ns16550` struct to include IRQ, TX, and RX handlers. - Implemented `InterfaceRaw` for `Ns16550` to manage IRQ and data transmission. - Added `Pl011Sender`, `Pl011Reciever`, and `Pl011IrqHandler` structs with appropriate methods for handling UART operations. - Removed unused methods and cleaned up code for better readability and maintainability.
…terface - Add configurable register width parameter to MMIO interface - Add boxed constructors for dynamic trait object creation - Refactor receiver interface to return Option<Result> instead of Result<Option> - Improve error handling consistency across UART implementations - Fix overrun error handling in bulk read operations
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the serial driver interface to version 0.3.0, migrating from the old rdif-serial v0.5.4 to v0.6.0 API. The major changes include:
- Redesigned the interface to split serial port into separate Sender, Receiver, and IrqHandler components
- Introduced
enum_dispatchfor efficient trait dispatch across different driver types - Updated method names for consistency (
write_bytes,read_bytes,base_addr) - Removed deprecated methods and simplified the API surface
Reviewed Changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test.rs | Updated test code to use new API methods, added clean_rx helper function, removed unused helper functions |
| src/pl011.rs | Refactored PL011 driver to implement new interface with split sender/receiver pattern |
| src/ns16550/mod.rs | Major restructuring to implement new InterfaceRaw trait and split components |
| src/ns16550/mmio.rs | Updated MMIO interface to support configurable register width and new factory methods |
| src/ns16550/pio.rs | Updated port-based interface methods and signatures |
| src/ns16550/registers.rs | Removed outdated comment |
| src/lib.rs | Added enum_dispatch based Sender/Receiver enums with unified traits |
| Cargo.toml | Version bump to 0.3.0, updated dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let mut bytes = b"TX mask test".as_slice(); | ||
| while !bytes.is_empty() { | ||
| let n = tx.send(bytes).unwrap(); | ||
| let n = tx.write_bytes(bytes); |
There was a problem hiding this comment.
The return value of write_bytes is not checked. If n is 0 (transmission failed), this will result in an infinite loop. Consider adding a check: if n == 0 { panic!(\"Failed to write bytes\"); }.
| let n = tx.write_bytes(bytes); | |
| let n = tx.write_bytes(bytes); | |
| if n == 0 { | |
| panic!("Failed to write bytes"); | |
| } |
|
|
||
| while !bytes.is_empty() { | ||
| let n = tx.send(bytes).unwrap(); | ||
| let n = tx.write_bytes(bytes); |
There was a problem hiding this comment.
Same issue as line 167: the return value is not checked for zero, which could cause an infinite loop if transmission fails.
| let n = tx.write_bytes(bytes); | |
| let n = tx.write_bytes(bytes); | |
| if n == 0 { | |
| info!("Error: tx.write_bytes returned 0, transmission may have failed. Breaking out of loop to avoid infinite loop."); | |
| break; | |
| } |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
变更描述
简洁明了地描述这个 PR 的变更内容。
变更类型
请选择适用的选项:
This pull request introduces significant refactoring and feature enhancements to the serial driver crate, focusing on improved architecture for UART interfaces, streamlined trait usage, and better support for multiple platforms. The changes modernize the codebase by introducing enum-based dispatch for sender/receiver traits, revising the PL011 and NS16550 UART implementations, and updating configuration and test logic to work with these new abstractions.
Architecture and Trait Refactoring
SenderandRecieverenums withenum_dispatchto unify and abstract over different UART implementations, and replaced previous trait implementations with newRawSenderandRawRecievertraits for more flexible and type-safe serial communication. (src/lib.rs, src/lib.rsR63-R142)Registertrait implementation with the newInterfaceRawtrait. (src/pl011.rs, [1] [2] [3] [4] [5]NS16550 UART Improvements
src/ns16550/mmio.rs, [1];src/ns16550/pio.rs, [2] [3]Platform and Dependency Updates
.vscode/settings.jsonand.cargo/config.tomltoaarch64-unknown-none-softfloatfor better cross-platform support; revised dependencies inCargo.tomlto use newer versions and addedenum_dispatch. (.vscode/settings.json, [1];.cargo/config.toml, [2];Cargo.toml, [3]Test Suite Modernization
write_bytes,read_bytes), replaced legacy methods, and added a utility to clean receive buffers for compatibility with the new interface. (tests/test.rs, [1] [2] [3] [4] [5] [6] [7] [8]Minor Cleanups
src/ns16550/registers.rs, src/ns16550/registers.rsL324)These changes collectively modernize the codebase, improve maintainability, and provide a more robust and flexible foundation for embedded serial communication across different platforms.
测试
描述你如何测试了这些变更:
检查清单
请确认以下项目:
相关 Issue
如果这个 PR 解决了某个 issue,请在这里引用:
Closes #
附加信息
在这里添加任何其他审查者需要知道的信息。