summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/uart.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/uart.h b/include/uart.h
new file mode 100644
index 0000000..76f4b34
--- /dev/null
+++ b/include/uart.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#define UART_BASE 0x10000
+#define UART_DATA *(volatile char *)(UART_BASE + 0)
+#define UART_STATUS *(volatile char *)(UART_BASE + 1)
+#define UART_TX_READY 0b01
+#define UART_RX_READY 0b10
+
+static inline int uart_rx_ready() { return (UART_STATUS & UART_RX_READY) != 0; }
+static inline int uart_tx_ready() { return (UART_STATUS & UART_TX_READY) != 0; }
+
+static inline void uart_putc(char c) {
+ while (!uart_tx_ready())
+ ;
+ UART_DATA = c;
+}
+
+static inline void uart_puts(const char *s) {
+ while (*s) {
+ uart_putc(*s++);
+ }
+}
+
+static inline char uart_getc_nonblocking() { return UART_DATA; }
+
+static inline char uart_getc() {
+ while (!uart_rx_ready())
+ ;
+ return UART_DATA;
+}