Improvements for aarch64 serial driver on real hardware
This commit is contained in:
@@ -10,6 +10,11 @@ use crate::paging::{ActivePageTable, Page, PageFlags, PhysicalAddress, TableKind
|
||||
pub static COM1: Mutex<Option<SerialPort>> = Mutex::new(None);
|
||||
|
||||
pub unsafe fn init_early(dtb_base: usize, dtb_size: usize) {
|
||||
if COM1.lock().is_some() {
|
||||
// Hardcoded UART
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some((phys, size)) = device_tree::diag_uart_range(dtb_base, dtb_size) {
|
||||
let virt = crate::KERNEL_DEVMAP_OFFSET + phys;
|
||||
{
|
||||
|
||||
@@ -145,12 +145,6 @@ impl SerialPort {
|
||||
self.write_reg(self.data_reg, data as u16);
|
||||
}
|
||||
|
||||
pub fn send_dbg(&mut self, data: u16) {
|
||||
if self.base != 0 {
|
||||
self.write_reg(self.data_reg, data);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear_all_irqs(&mut self) {
|
||||
let flags = UartIcrFlags::RXIC;
|
||||
self.write_reg(self.intr_clr_reg, flags.bits());
|
||||
@@ -166,9 +160,21 @@ impl SerialPort {
|
||||
}
|
||||
|
||||
pub fn write(&mut self, buf: &[u8]) {
|
||||
//TODO: some character conversion like in uart_16550.rs
|
||||
for &b in buf {
|
||||
self.send_dbg(b as u16);
|
||||
match b {
|
||||
8 | 0x7F => {
|
||||
self.send(8);
|
||||
self.send(b' ');
|
||||
self.send(8);
|
||||
}
|
||||
b'\n' => {
|
||||
self.send(b'\r');
|
||||
self.send(b'\n');
|
||||
}
|
||||
_ => {
|
||||
self.send(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user