feat(serial): implement own serial driver
continuous-integration/drone/push Build is passing

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
juju committed 2021-12-03 00:30:08 +01:00
1 parent 106e907438
commit b9557bdc5e
3 files changed
+45 -14

No files matched your search

+45 -2
View File
@@ -1,10 +1,19 @@
use uart_16550::SerialPort;
use core::fmt;
use spin::Mutex;
use lazy_static::lazy_static;
use x86_64::instructions::port::Port;
const COM1: u16 = 0x3f8;
#[allow(dead_code)]
const COM2: u16 = 0x2f8;
#[allow(dead_code)]
const COM3: u16 = 0x3e8;
#[allow(dead_code)]
const COM4: u16 = 0x2e8;
lazy_static! {
pub static ref SERIAL1: Mutex<SerialPort> = {
let mut serial_port = unsafe { SerialPort::new(0x3F8) };
let mut serial_port = SerialPort::new(COM1);
serial_port.init();
Mutex::new(serial_port)
};
@@ -32,3 +41,37 @@ macro_rules! serial_println {
($fmt:expr, $($arg:tt)*) => ($crate::serial_print!(
concat!($fmt, "\n"), $($arg)*));
}
pub struct SerialPort {
base: Port<u8>,
}
impl SerialPort {
pub fn new(port: u16) -> SerialPort {
SerialPort {
base: Port::new(port)
}
}
fn write_byte(&mut self, byte: u8) {
unsafe {
self.base.write(byte);
}
}
fn write_string(&mut self, s: &str) {
for byte in s.bytes() {
self.write_byte(byte);
}
}
fn init(&mut self) {
}
}
impl fmt::Write for SerialPort {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.write_string(s);
Ok(())
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.