Fix locking in serial port

This commit is contained in:
Jeremy Soller 2016-08-17 17:24:10 -06:00
parent b756dd59eb
commit 979d80a8c7
2 changed files with 10 additions and 13 deletions

View file

@ -19,13 +19,8 @@ extern crate x86;
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ({
{
use core::fmt::Write;
//TODO: let mut serial_console = $crate::serial::SERIAL_CONSOLE.lock();
let mut serial_console = $crate::serial::SerialConsole::new();
let _ = write!(serial_console, $($arg)*);
drop(serial_console);
}
let _ = write!($crate::serial::SerialConsole, $($arg)*);
});
}

View file

@ -3,16 +3,16 @@ use spin::Mutex;
use super::io::{Io, Pio};
pub static SERIAL_CONSOLE: Mutex<SerialConsole> = Mutex::new(SerialConsole::new());
static SERIAL_PORT: Mutex<SerialPort> = Mutex::new(SerialPort::new());
pub struct SerialConsole {
struct SerialPort {
status: Pio<u8>,
data: Pio<u8>
}
impl SerialConsole {
pub const fn new() -> SerialConsole {
SerialConsole {
impl SerialPort {
pub const fn new() -> SerialPort {
SerialPort {
status: Pio::new(0x3F8 + 5),
data: Pio::new(0x3F8)
}
@ -34,9 +34,11 @@ impl SerialConsole {
}
}
pub struct SerialConsole;
impl fmt::Write for SerialConsole {
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
self.write(s.as_bytes());
SERIAL_PORT.lock().write(s.as_bytes());
Ok(())
}