feat(serial): implement own serial driver
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
106e907438
commit
b9557bdc5e
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -20,7 +20,6 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"spin",
|
"spin",
|
||||||
"uart_16550",
|
|
||||||
"volatile 0.2.7",
|
"volatile 0.2.7",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
]
|
]
|
||||||
@ -40,16 +39,6 @@ version = "0.5.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "uart_16550"
|
|
||||||
version = "0.2.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "65ad019480ef5ff8ffe66d6f6a259cd87cf317649481394981db1739d844f374"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"x86_64",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "volatile"
|
name = "volatile"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
|
@ -12,7 +12,6 @@ crate-type = ["staticlib"]
|
|||||||
volatile = "0.2.6"
|
volatile = "0.2.6"
|
||||||
spin = "0.5.2"
|
spin = "0.5.2"
|
||||||
x86_64 = "0.14.2"
|
x86_64 = "0.14.2"
|
||||||
uart_16550 = "0.2.0"
|
|
||||||
|
|
||||||
[dependencies.lazy_static]
|
[dependencies.lazy_static]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
@ -1,10 +1,19 @@
|
|||||||
use uart_16550::SerialPort;
|
use core::fmt;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
use lazy_static::lazy_static;
|
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! {
|
lazy_static! {
|
||||||
pub static ref SERIAL1: Mutex<SerialPort> = {
|
pub static ref SERIAL1: Mutex<SerialPort> = {
|
||||||
let mut serial_port = unsafe { SerialPort::new(0x3F8) };
|
let mut serial_port = SerialPort::new(COM1);
|
||||||
serial_port.init();
|
serial_port.init();
|
||||||
Mutex::new(serial_port)
|
Mutex::new(serial_port)
|
||||||
};
|
};
|
||||||
@ -32,3 +41,37 @@ macro_rules! serial_println {
|
|||||||
($fmt:expr, $($arg:tt)*) => ($crate::serial_print!(
|
($fmt:expr, $($arg:tt)*) => ($crate::serial_print!(
|
||||||
concat!($fmt, "\n"), $($arg)*));
|
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(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user