Skip to content
Celve edited this page Jan 21, 2024 · 2 revisions

IO

UART Initialization

In the initialization of UART, we do these things in sequence:

  1. Set maximum speed of 38.4K for LSB.
  2. Set maximum speed of 38.4K for MSB.
  3. Set data word length to 8 bits.
  4. Enable FIFO, clear TX/RX queues and set interrupt watermark at 14 bytes.
  5. Mark data terminal ready, signal request to send and enable auxilliary output.
  6. Enable UART interrupts.

All these operations are linked to code in kernel/src/drivers/uart.rs.

UART Input

When there is a read request, we first check whether there is data in the read buffer. Otherwise, the process sleeps until an external interrupt is triggered. After that, it would wake up, read the data from the buffer, and return it to the caller.

UART Output

Because the FIFO is enabled in the intialization, therefore a write buffer is not implemented.

Due to the practicality, we spin when there is no enough space in the queue until it's available. No interrupt is introduced here.

Clone this wiki locally