diff --git a/src/uart.c b/src/uart.c index f83bf2a9..3128888b 100644 --- a/src/uart.c +++ b/src/uart.c @@ -22,7 +22,7 @@ void uart_init(void) void uart_putbyte(u8 c) { - while (!(read32(UART_BASE + UTRSTAT) & 0x02)) + while (!(read32(UART_BASE + UTRSTAT) & UTRSTAT_TXBE)) ; write32(UART_BASE + UTXH, c); @@ -30,7 +30,7 @@ void uart_putbyte(u8 c) u8 uart_getbyte(void) { - while (!(read32(UART_BASE + UTRSTAT) & 0x01)) + while (!(read32(UART_BASE + UTRSTAT) & UTRSTAT_RXD)) ; return read32(UART_BASE + URXH); @@ -86,7 +86,7 @@ void uart_setbaud(int baudrate) void uart_flush(void) { - while (!(read32(UART_BASE + UTRSTAT) & 0x04)) + while (!(read32(UART_BASE + UTRSTAT) & UTRSTAT_TXE)) ; } @@ -114,7 +114,7 @@ static bool uart_iodev_can_write(void *opaque) static ssize_t uart_iodev_can_read(void *opaque) { UNUSED(opaque); - return read32(UART_BASE + UTRSTAT) & 0x01; + return read32(UART_BASE + UTRSTAT) & UTRSTAT_RXD; } static ssize_t uart_iodev_read(void *opaque, void *buf, size_t len) diff --git a/src/uart_regs.h b/src/uart_regs.h index 1b244413..bca1fe42 100644 --- a/src/uart_regs.h +++ b/src/uart_regs.h @@ -4,7 +4,29 @@ #define UCON 0x004 #define UFCON 0x008 #define UTRSTAT 0x010 +#define UFSTAT 0x018 #define UTXH 0x020 #define URXH 0x024 #define UBRDIV 0x028 #define UFRACVAL 0x02c + +#define UCON_TXTHRESH_ENA BIT(13) +#define UCON_RXTHRESH_ENA BIT(12) +#define UCON_RXTO_ENA BIT(9) +#define UCON_TXMODE GENMASK(3, 2) +#define UCON_RXMODE GENMASK(1, 0) + +#define UCON_MODE_OFF 0 +#define UCON_MODE_IRQ 1 + +#define UTRSTAT_RXTO BIT(9) +#define UTRSTAT_TXTHRESH BIT(5) +#define UTRSTAT_RXTHRESH BIT(4) +#define UTRSTAT_TXE BIT(2) +#define UTRSTAT_TXBE BIT(1) +#define UTRSTAT_RXD BIT(0) + +#define UFSTAT_TXFULL BIT(9) +#define UFSTAT_RXFULL BIT(8) +#define UFSTAT_TXCNT GENMASK(7, 4) +#define UFSTAT_RXCNT GENMASK(3, 0)