1
0
Fork 0
zynq-rs/src/stdio.rs

40 lines
878 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 => {
2019-08-11 06:55:27 +08:00
let uart = Uart::serial(UART_RATE);
2019-06-20 06:30:18 +08:00
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();
2019-08-11 06:55:27 +08:00
let _ = write!(uart, $($arg)*);
2019-06-21 07:18:24 +08:00
})
}
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();
2019-08-11 06:55:27 +08:00
let _ = write!(uart, $($arg)*);
let _ = write!(uart, "\r\n");
2019-06-20 06:30:18 +08:00
while !uart.tx_fifo_empty() {}
})
}