pub struct Uart;Expand description
UART 驱动结构体
Implementations§
Source§impl Uart
impl Uart
Sourcepub fn init() -> Result<()>
pub fn init() -> Result<()>
初始化 UART 硬件
配置波特率 38.4K,8 数据位,启用 FIFO,禁用中断。
返回 Ok(()) 表示成功,Err(UartError::InitFailed) 表示失败。
Sourcepub fn put_char_sync(c: u8) -> Result<()>
pub fn put_char_sync(c: u8) -> Result<()>
同步输出字符,用于 panic 处理
参考 xv6 的 uartputc_sync 实现,轮询发送空闲并带有超时。
在系统崩溃时确保输出,避免无限等待。
Sourcepub fn try_get_char() -> Option<u8>
pub fn try_get_char() -> Option<u8>
尝试从 UART 读取字符
如果有字符可用则返回 Some(c),否则返回 None。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Uart
impl RefUnwindSafe for Uart
impl Send for Uart
impl Sync for Uart
impl Unpin for Uart
impl UnsafeUnpin for Uart
impl UnwindSafe for Uart
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more