diff options
| author | taitep <taitep@taitep.se> | 2026-01-04 18:51:23 +0100 |
|---|---|---|
| committer | taitep <taitep@taitep.se> | 2026-01-04 18:51:23 +0100 |
| commit | 25bec21f20208a9369656a337cf5325e7b3a5a8d (patch) | |
| tree | 10b66b7837bd547ea08c5838a0c30b2c850618f5 /include | |
Initial commit
Diffstat (limited to 'include')
| -rw-r--r-- | include/uart.h | 30 |
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; +} |
