diff options
| author | taitep <taitep@taitep.se> | 2026-01-29 21:27:36 +0100 |
|---|---|---|
| committer | taitep <taitep@taitep.se> | 2026-01-29 21:27:36 +0100 |
| commit | 4f32bbc46a48276bba949364dc44d532c19dae78 (patch) | |
| tree | 8f54108788735efff25a4a9549bedbe7967d3c7b /include | |
| parent | 25bec21f20208a9369656a337cf5325e7b3a5a8d (diff) | |
Diffstat (limited to 'include')
| -rw-r--r-- | include/uart.h | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/include/uart.h b/include/uart.h index 76f4b34..7b414ca 100644 --- a/include/uart.h +++ b/include/uart.h @@ -1,30 +1,29 @@ #pragma once +#include <stdbool.h> +#include <stdint.h> + #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; -} +#define UART_REG(offset) *(volatile uint32_t *)(UART_BASE + offset) +#define UART_TXDATA UART_REG(0x00) +#define UART_RXDATA UART_REG(0x04) +#define UART_TXCTRL UART_REG(0x08) +#define UART_RXCTRL UART_REG(0x0c) +#define UART_IE UART_REG(0x10) +#define UART_IP UART_REG(0x14) +#define UART_DIV UART_REG(0x18) + +#define UART_TXDATA_FULL 0x80000000 +#define UART_RXDATA_EMPTY 0x80000000 + +#define UART_TXCTRL_TXEN 1 +#define UART_RXCTRL_RXEN 1 + +void uart_init(void); + +bool uart_tx_ready(void); + +void uart_putc(char c); +void uart_puts(const char *s); + +char uart_getc(void); |
