Refactor
This commit is contained in:
18
src/uart.rs
18
src/uart.rs
@@ -1,15 +1,27 @@
|
||||
//! UART low-level driver.
|
||||
//!
|
||||
//! Minimal polling driver used by the kernel for early console output.
|
||||
const UART_BASE: *mut u8 = 0x10000000 as *mut _;
|
||||
/// Write a single character to the UART using a simple polling loop.
|
||||
///
|
||||
/// This is a very small, platform-specific driver used for early boot
|
||||
/// console output; it busy-waits until the UART indicates it can accept
|
||||
/// a new byte.
|
||||
pub fn write_char_uart(c: char) {
|
||||
while unsafe { core::ptr::read_volatile(UART_BASE.byte_add(0x5)) } >> 5 & 1 == 0 {}
|
||||
while unsafe { (core::ptr::read_volatile(UART_BASE.byte_add(0x5)) >> 5) & 1 == 0 } {}
|
||||
unsafe { core::ptr::write_volatile(UART_BASE, c as u8) };
|
||||
}
|
||||
|
||||
/// Write a UTF-8 string to the UART.
|
||||
///
|
||||
/// Automatically injects a carriage-return after newline to support terminals
|
||||
/// that expect CRLF pairs.
|
||||
pub fn write_uart<T: AsRef<str>>(print: T) {
|
||||
print.as_ref().chars().for_each(|a| {
|
||||
for a in print.as_ref().chars() {
|
||||
// Add \r if needed
|
||||
write_char_uart(a);
|
||||
if a == '\n' {
|
||||
write_char_uart('\r');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user