Implement code for integration test post

This commit is contained in:
Philipp Oppermann
2018-06-12 19:25:53 +02:00
parent 40eb19b613
commit 8b5be6ebc0
7 changed files with 125 additions and 12 deletions

31
src/serial.rs Normal file
View File

@@ -0,0 +1,31 @@
use uart_16550::SerialPort;
use spin::Mutex;
lazy_static! {
pub static ref SERIAL1: Mutex<SerialPort> = {
let mut serial_port = SerialPort::new(0x3F8);
serial_port.init();
Mutex::new(serial_port)
};
}
pub fn print(args: ::core::fmt::Arguments) {
use core::fmt::Write;
SERIAL1.lock().write_fmt(args).expect("Printing to serial failed");
}
/// Prints to the host through the serial interface.
#[macro_export]
macro_rules! serial_print {
($($arg:tt)*) => {
$crate::serial::print(format_args!($($arg)*));
};
}
/// Prints to the host through the serial interface, appending a newline.
#[macro_export]
macro_rules! serial_println {
() => (serial_print!("\n"));
($fmt:expr) => (serial_print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (serial_print!(concat!($fmt, "\n"), $($arg)*));
}