zynq-rs/src/stdio.rs

40 lines
858 B
Rust
Raw Normal View History

2019-06-20 06:30:18 +08:00
use crate::uart::Uart;
const UART_RATE: u32 = 115_200;
static mut UART: Option<Uart> = None;
// TODO: locking for SMP
#[doc(hidden)]
pub fn get_uart() -> &'static mut Uart {
unsafe {
match &mut UART {
None => {
let mut uart = Uart::serial(UART_RATE);
UART = Some(uart);
UART.as_mut().unwrap()
}
Some(uart) => uart,
}
}
}
2019-06-21 07:18:24 +08:00
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ({
use core::fmt::Write;
let uart = crate::stdio::get_uart();
write!(uart, $($arg)*);
})
}
2019-06-20 06:30:18 +08:00
#[macro_export]
macro_rules! println {
($($arg:tt)*) => ({
use core::fmt::Write;
let uart = crate::stdio::get_uart();
write!(uart, $($arg)*);
write!(uart, "\r\n");
while !uart.tx_fifo_empty() {}
})
}