Struct uart8250::MmioUart8250
source · [−]pub struct MmioUart8250<'a> { /* private fields */ }
Expand description
MMIO version of an 8250 UART.
Note This is only tested on the NS16550 compatible UART used in QEMU 5.0 virt machine of RISC-V.
Implementations
sourceimpl<'a> MmioUart8250<'a>
impl<'a> MmioUart8250<'a>
sourcepub unsafe fn new(base_address: usize) -> Self
pub unsafe fn new(base_address: usize) -> Self
Creates a new UART.
Safety
The given base address must point to the 8 MMIO control registers of an appropriate UART device, which must be mapped into the address space of the process as device memory and not have any other aliases.
sourcepub fn init(&self, clock: usize, baud_rate: usize)
pub fn init(&self, clock: usize, baud_rate: usize)
Initialises the UART with common settings and interrupts enabled.
More customised initialisation can be done using other methods below.
sourcepub unsafe fn set_base_address(&mut self, base_address: usize)
pub unsafe fn set_base_address(&mut self, base_address: usize)
Sets a new base address for the UART.
Safety
The given base address must point to the 8 MMIO control registers of an appropriate UART device, which must be mapped into the address space of the process as device memory and not have any other aliases.
sourcepub fn read_byte(&self) -> Option<u8>
pub fn read_byte(&self) -> Option<u8>
Reads a byte from the UART.
Returns None
when data is not ready (RBR[0] != 1)
sourcepub fn write_byte(&self, byte: u8) -> Result<(), TransmitError>
pub fn write_byte(&self, byte: u8) -> Result<(), TransmitError>
Writes a byte to the UART.
sourcepub fn set_divisor(&self, clock: usize, baud_rate: usize)
pub fn set_divisor(&self, clock: usize, baud_rate: usize)
Sets DLAB to true, sets divisor latch according to clock and baud_rate, then sets DLAB to false.
Divisor Latch Bytes
Offset: +0 and +1 . The Divisor Latch Bytes are what control the baud rate of the modem. As you might guess from the name of this register, it is used as a divisor to determine what baud rate that the chip is going to be transmitting at.
Used clock 1.8432 MHz as example, first divide 16 and get 115200. Then use the formula to get divisor latch value:
DivisorLatchValue = 115200 / BaudRate
This gives the following table:
Baud Rate | Divisor (in decimal) | Divisor Latch High Byte | Divisor Latch Low Byte |
---|---|---|---|
50 | 2304 | $09 | $00 |
110 | 1047 | $04 | $17 |
220 | 524 | $02 | $0C |
300 | 384 | $01 | $80 |
600 | 192 | $00 | $C0 |
1200 | 96 | $00 | $60 |
2400 | 48 | $00 | $30 |
4800 | 24 | $00 | $18 |
9600 | 12 | $00 | $0C |
19200 | 6 | $00 | $06 |
38400 | 3 | $00 | $03 |
57600 | 2 | $00 | $02 |
115200 | 1 | $00 | $01 |
sourcepub fn write_ier(&self, value: u8)
pub fn write_ier(&self, value: u8)
Write IER (offset + 1)
Write Interrupt Enable Register to turn on/off interrupts
sourcepub fn is_low_power_mode_enabled(&self) -> bool
pub fn is_low_power_mode_enabled(&self) -> bool
get whether low power mode (16750) is enabled (IER[5])
sourcepub fn enable_low_power_mode(&self)
pub fn enable_low_power_mode(&self)
enable low power mode (16750) (IER[5])
sourcepub fn disable_low_power_mode(&self)
pub fn disable_low_power_mode(&self)
disable low power mode (16750) (IER[5])
sourcepub fn is_sleep_mode_enabled(&self) -> bool
pub fn is_sleep_mode_enabled(&self) -> bool
get whether sleep mode (16750) is enabled (IER[4])
sourcepub fn enable_sleep_mode(&self)
pub fn enable_sleep_mode(&self)
enable sleep mode (16750) (IER[4])
sourcepub fn disable_sleep_mode(&self)
pub fn disable_sleep_mode(&self)
disable sleep mode (16750) (IER[4])
sourcepub fn is_modem_status_interrupt_enabled(&self) -> bool
pub fn is_modem_status_interrupt_enabled(&self) -> bool
get whether modem status interrupt is enabled (IER[3])
sourcepub fn enable_modem_status_interrupt(&self)
pub fn enable_modem_status_interrupt(&self)
enable modem status interrupt (IER[3])
sourcepub fn disable_modem_status_interrupt(&self)
pub fn disable_modem_status_interrupt(&self)
disable modem status interrupt (IER[3])
sourcepub fn is_receiver_line_status_interrupt_enabled(&self) -> bool
pub fn is_receiver_line_status_interrupt_enabled(&self) -> bool
get whether receiver line status interrupt is enabled (IER[2])
sourcepub fn enable_receiver_line_status_interrupt(&self)
pub fn enable_receiver_line_status_interrupt(&self)
enable receiver line status interrupt (IER[2])
sourcepub fn disable_receiver_line_status_interrupt(&self)
pub fn disable_receiver_line_status_interrupt(&self)
disable receiver line status interrupt (IER[2])
sourcepub fn is_transmitter_holding_register_empty_interrupt_enabled(&self) -> bool
pub fn is_transmitter_holding_register_empty_interrupt_enabled(&self) -> bool
get whether transmitter holding register empty interrupt is enabled (IER[1])
sourcepub fn enable_transmitter_holding_register_empty_interrupt(&self)
pub fn enable_transmitter_holding_register_empty_interrupt(&self)
enable transmitter holding register empty interrupt (IER[1])
sourcepub fn disable_transmitter_holding_register_empty_interrupt(&self)
pub fn disable_transmitter_holding_register_empty_interrupt(&self)
disable transmitter holding register empty interrupt (IER[1])
sourcepub fn is_received_data_available_interrupt_enabled(&self) -> bool
pub fn is_received_data_available_interrupt_enabled(&self) -> bool
get whether received data available is enabled (IER[0])
sourcepub fn enable_received_data_available_interrupt(&self)
pub fn enable_received_data_available_interrupt(&self)
enable received data available (IER[0])
sourcepub fn disable_received_data_available_interrupt(&self)
pub fn disable_received_data_available_interrupt(&self)
disable received data available (IER[0])
sourcepub fn read_fifo_status(&self) -> ChipFifoInfo
pub fn read_fifo_status(&self) -> ChipFifoInfo
Read IIR[7:6] to get FIFO status
sourcepub fn is_64byte_fifo_enabled(&self) -> bool
pub fn is_64byte_fifo_enabled(&self) -> bool
get whether 64 Byte fifo (16750 only) is enabled (IIR[5])
sourcepub fn read_interrupt_type(&self) -> Option<InterruptType>
pub fn read_interrupt_type(&self) -> Option<InterruptType>
Read IIR[3:1] to get interrupt type
sourcepub fn get_parity(&self) -> Parity
pub fn get_parity(&self) -> Parity
get parity of used data protocol
sourcepub fn set_parity(&self, parity: Parity)
pub fn set_parity(&self, parity: Parity)
set parity
sourcepub fn get_stop_bit(&self) -> u8
pub fn get_stop_bit(&self) -> u8
get stop bit of used data protocol
Simply return a u8 to indicate 1 or 1.5/2 bits
sourcepub fn set_stop_bit(&self, stop_bit: u8)
pub fn set_stop_bit(&self, stop_bit: u8)
set stop bit, only 1 and 2 can be used as stop_bit
sourcepub fn get_word_length(&self) -> u8
pub fn get_word_length(&self) -> u8
get word length of used data protocol
sourcepub fn set_word_length(&self, length: u8)
pub fn set_word_length(&self, length: u8)
set word length, only 5..=8 can be used as length
sourcepub fn is_received_fifo_error(&self) -> bool
pub fn is_received_fifo_error(&self) -> bool
get whether there is an error in received FIFO
sourcepub fn is_data_holding_registers_empty(&self) -> bool
pub fn is_data_holding_registers_empty(&self) -> bool
Gets whether data holding registers are empty, i.e. the UART has finished transmitting all the data it has been given.
sourcepub fn is_transmitter_holding_register_empty(&self) -> bool
pub fn is_transmitter_holding_register_empty(&self) -> bool
Gets whether transmitter holding register is empty, i.e. the UART is ready to be given more data to transmit.
pub fn is_break_interrupt(&self) -> bool
pub fn is_framing_error(&self) -> bool
pub fn is_parity_error(&self) -> bool
pub fn is_overrun_error(&self) -> bool
pub fn is_data_ready(&self) -> bool
pub fn is_carrier_detect(&self) -> bool
pub fn is_ring_indicator(&self) -> bool
pub fn is_data_set_ready(&self) -> bool
pub fn is_clear_to_send(&self) -> bool
pub fn is_delta_data_carrier_detect(&self) -> bool
pub fn is_trailing_edge_ring_indicator(&self) -> bool
pub fn is_delta_data_set_ready(&self) -> bool
pub fn is_delta_clear_to_send(&self) -> bool
pub fn read_sr(&self) -> u8
pub fn write_sr(&self, value: u8)
Auto Trait Implementations
impl<'a> !RefUnwindSafe for MmioUart8250<'a>
impl<'a> Send for MmioUart8250<'a>
impl<'a> !Sync for MmioUart8250<'a>
impl<'a> Unpin for MmioUart8250<'a>
impl<'a> !UnwindSafe for MmioUart8250<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more