| //! Unsafe synchronous dump-string-to-uart impl and macro for debugging. |
| |
| use core2::io::{Cursor, Write}; |
| use core::fmt; |
| |
| pub const TX_BUSY: *const u32 = 0x4000_0010 as *const u32; |
| pub const TX_PORT: *mut u32 = 0x4000_0018 as *mut u32; |
| |
| pub fn send_sync(buf: &[u8], len: usize) { |
| unsafe { |
| for i in 0..len { |
| while (TX_BUSY.read_volatile() & 1) != 0 {} |
| TX_PORT.write_volatile(buf[i] as u32); |
| } |
| } |
| } |
| |
| pub fn vdprintf(args: fmt::Arguments) { |
| let mut uart_buf = [0u8; 256]; |
| let mut cur = Cursor::new(&mut uart_buf[..]); |
| if cur.write_fmt(args).is_ok() { |
| let pos = cur.position(); |
| send_sync(&uart_buf, pos as usize); |
| } |
| } |
| |
| #[macro_export] |
| macro_rules! dprintf { |
| ($msg:expr) => ({ |
| $crate::debug_uart::vdprintf(format_args!($msg)) |
| }); |
| ($fmt:expr, $($arg:tt)+) => ({ |
| $crate::debug_uart::vdprintf(format_args!($fmt, $($arg)+)) |
| }); |
| } |