aboutsummaryrefslogtreecommitdiff
path: root/devices/uart_16550.h
diff options
context:
space:
mode:
Diffstat (limited to 'devices/uart_16550.h')
-rw-r--r--devices/uart_16550.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/devices/uart_16550.h b/devices/uart_16550.h
new file mode 100644
index 0000000..d053985
--- /dev/null
+++ b/devices/uart_16550.h
@@ -0,0 +1,56 @@
+#pragma once
+
+enum uart_16550_offset {
+ Data = 0, // read from receive buffer / write to transmit buffer | BaudDiv_l
+ InterruptControl = 1, // interrupt enable | BaudDiv_h
+ FifoControl = 2, // interrupt ID and FIFO control
+ LineControl = 3, // most significant bit is the DLAB
+ ModemControl = 4,
+ LineStatus = 5,
+ ModemStatus = 6,
+ Scratch = 7,
+};
+// Line Control
+// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+// |dla| | parity | s | data |
+
+enum LineControl {
+ d5bit = 0b00000000, // data bits
+ d6bit = 0b00000001,
+ d7bit = 0b00000010,
+ d8bit = 0b00000011,
+ // none = 0b00000000, // parity bits
+ odd = 0b00001000,
+ even = 0b00011000,
+ mark = 0b00101000,
+ space = 0b00111000,
+ // s1bit = 0b00000000, // stop bits
+ s2bit = 0b00000100, // 1.5 for 5bit data; 2 otherwise
+ dlab = 0b10000000, // divisor latch access bit
+};
+
+// Line Status Register
+enum LineStatus {
+ DR = 0b00000001, // data ready: see if there is data to read
+ OE = 0b00000010, // overrun error: see if there has been data lost
+ PE = 0b00000100, // parity error: see if there was error in transmission
+ FE = 0b00001000, // framing error: see if a stop bit was missing
+ BI = 0b00010000, // break indicator: see if there is a break in data input
+ THRE = 0b00100000, // transmitter holding register empty: see if transmission buffer is empty
+ TEMT = 0b01000000, // transmitter empty: see if transmitter is not doing anything
+ ERRO = 0b10000000, // impending error: see if there is an error with a word in the input buffer
+};
+
+enum UART {
+ COM1 = 0x3f8,
+ COM2 = 0x2f8,
+ COM3 = 0x3E8,
+ COM4 = 0x2E8,
+ COM5 = 0x5F8,
+ COM6 = 0x4F8,
+ COM7 = 0x5E8,
+ COM8 = 0x4E8,
+};
+
+int uart_init(enum UART port);
+int uart_puts(enum UART port, const char *string, int length);