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

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.

Initialises the UART with common settings and interrupts enabled.

More customised initialisation can be done using other methods below.

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.

Reads a byte from the UART.

Returns None when data is not ready (RBR[0] != 1)

Writes a byte to the UART.

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 RateDivisor (in decimal)Divisor Latch High ByteDivisor Latch Low Byte
502304$09$00
1101047$04$17
220524$02$0C
300384$01$80
600192$00$C0
120096$00$60
240048$00$30
480024$00$18
960012$00$0C
192006$00$06
384003$00$03
576002$00$02
1152001$00$01

Write IER (offset + 1)

Write Interrupt Enable Register to turn on/off interrupts

get whether low power mode (16750) is enabled (IER[5])

enable low power mode (16750) (IER[5])

disable low power mode (16750) (IER[5])

get whether sleep mode (16750) is enabled (IER[4])

enable sleep mode (16750) (IER[4])

disable sleep mode (16750) (IER[4])

get whether modem status interrupt is enabled (IER[3])

enable modem status interrupt (IER[3])

disable modem status interrupt (IER[3])

get whether receiver line status interrupt is enabled (IER[2])

enable receiver line status interrupt (IER[2])

disable receiver line status interrupt (IER[2])

get whether transmitter holding register empty interrupt is enabled (IER[1])

enable transmitter holding register empty interrupt (IER[1])

disable transmitter holding register empty interrupt (IER[1])

get whether received data available is enabled (IER[0])

enable received data available (IER[0])

disable received data available (IER[0])

Read IIR[7:6] to get FIFO status

get whether 64 Byte fifo (16750 only) is enabled (IIR[5])

Read IIR[3:1] to get interrupt type

get parity of used data protocol

set parity

get stop bit of used data protocol

Simply return a u8 to indicate 1 or 1.5/2 bits

set stop bit, only 1 and 2 can be used as stop_bit

get word length of used data protocol

set word length, only 5..=8 can be used as length

get whether there is an error in received FIFO

Gets whether data holding registers are empty, i.e. the UART has finished transmitting all the data it has been given.

Gets whether transmitter holding register is empty, i.e. the UART is ready to be given more data to transmit.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.