Enhance the serial driver
Typo fixes Add an easy way to compute the baud rate
This commit is contained in:
parent
81a517de6b
commit
fcc27d50e3
@ -40,13 +40,15 @@ pub struct SerialPort {
|
|||||||
scratch: Port<u8>, // 7
|
scratch: Port<u8>, // 7
|
||||||
}
|
}
|
||||||
|
|
||||||
const SCRATCH_VALUE: u8 = 0x42;
|
const SCRATCH_VALUE: u8 = 0x42; // An arbitrary value used to test serial ports
|
||||||
|
|
||||||
const DISBALE_INTERRUPTS: u8 = 0x00;
|
const DISABLE_INTERRUPTS: u8 = 0x00; //
|
||||||
|
|
||||||
const DLAB: u8 = 0x80;
|
const DLAB: u8 = 0x80;
|
||||||
|
|
||||||
const DIVISOR: u16 = 0x03;
|
const BASE_RATE: u32 = 115200;
|
||||||
|
|
||||||
|
const DIVISOR: u16 = 0x03; // The baud rate is 38400
|
||||||
|
|
||||||
const PARITY_MODE: u8 = 0x03;
|
const PARITY_MODE: u8 = 0x03;
|
||||||
|
|
||||||
@ -81,7 +83,7 @@ impl SerialPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// disable all interrupts
|
// disable all interrupts
|
||||||
p.int_en.write(DISBALE_INTERRUPTS);
|
p.int_en.write(DISABLE_INTERRUPTS);
|
||||||
|
|
||||||
// enable DLAB to set the divisor
|
// enable DLAB to set the divisor
|
||||||
p.line_ctrl.write(DLAB);
|
p.line_ctrl.write(DLAB);
|
||||||
@ -126,6 +128,10 @@ impl SerialPort {
|
|||||||
self.data.read()
|
self.data.read()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn rate() -> u32 {
|
||||||
|
BASE_RATE / (DIVISOR as u32)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Write for SerialPort {
|
impl fmt::Write for SerialPort {
|
||||||
|
Loading…
Reference in New Issue
Block a user