mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-29 05:55:16 -04:00
Add uart
This commit is contained in:
parent
b00df2032d
commit
71b76c153d
2 changed files with 53 additions and 0 deletions
33
exosphere/uart.c
Normal file
33
exosphere/uart.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "uart.h"
|
||||
|
||||
volatile void *g_uart_registers = NULL;
|
||||
|
||||
void set_uart_address(void *uart_base) {
|
||||
g_uart_registers = uart_base;
|
||||
}
|
||||
|
||||
inline void *get_uart_address(void) {
|
||||
return g_uart_registers;
|
||||
}
|
||||
|
||||
void uart_initialize(uint16_t divider) {
|
||||
/* Setup UART in 16450 mode. We assume the relevant UART clock has been enabled. */
|
||||
|
||||
/* Disable FIFO */
|
||||
UART_IIR_FCR_0 = 0x00;
|
||||
|
||||
/* Set DLAB */
|
||||
UART_LCR_0 = 0x80;
|
||||
UART_THR_DLAB_0_0 = (uint8_t)divider;
|
||||
UART_IER_DLAB_0_0 = (uint8_t)(divider >> 8);
|
||||
|
||||
/* 8N1 mode */
|
||||
UART_LCR_0 = 0x03;
|
||||
}
|
||||
|
||||
void uart_transmit_char(char ch) {
|
||||
/* Wait for THR to be empty */
|
||||
while (!(UART_LSR_0 & 0x20)) {}
|
||||
|
||||
UART_THR_DLAB_0_0 = ch;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue