From 254fe2d75d29cb4b1316f2119e2a2e295d75e8fd Mon Sep 17 00:00:00 2001 From: gatecat Date: Wed, 12 Mar 2025 12:29:36 +0100 Subject: [PATCH] Replace UART with that from amaranth-soc RFC Signed-off-by: gatecat --- chipflow_lib/software/drivers/uart.c | 13 +++++++++++-- chipflow_lib/software/drivers/uart.h | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/chipflow_lib/software/drivers/uart.c b/chipflow_lib/software/drivers/uart.c index 3c316a49..ec1422e3 100644 --- a/chipflow_lib/software/drivers/uart.c +++ b/chipflow_lib/software/drivers/uart.c @@ -1,12 +1,21 @@ /* SPDX-License-Identifier: BSD-2-Clause */ #include "uart.h" +void uart_init(volatile uart_regs_t *uart, uint32_t divisor) { + uart->tx.config = 0; + uart->tx.phy_config = divisor & 0x00FFFFFF; + uart->tx.config = 1; + uart->rx.config = 0; + uart->rx.phy_config = divisor & 0x00FFFFFF; + uart->rx.config = 1; +}; + void uart_putc(volatile uart_regs_t *uart, char c) { if (c == '\n') uart_putc(uart, '\r'); - while (!uart->tx_ready) + while (!(uart->tx.status & 0x1)) ; - uart->tx_data = c; + uart->tx.data = c; } void uart_puts(volatile uart_regs_t *uart, const char *s) { diff --git a/chipflow_lib/software/drivers/uart.h b/chipflow_lib/software/drivers/uart.h index 451335e3..90ab00e2 100644 --- a/chipflow_lib/software/drivers/uart.h +++ b/chipflow_lib/software/drivers/uart.h @@ -5,12 +5,20 @@ #include typedef struct __attribute__((packed, aligned(4))) { - uint32_t tx_data; - uint32_t rx_data; - uint32_t tx_ready; - uint32_t rx_avail; + uint8_t config; + uint8_t padding_0[3]; + uint32_t phy_config; + uint8_t status; + uint8_t data; + uint8_t padding_1[6]; +} uart_mod_regs_t; + +typedef struct __attribute__((packed, aligned(4))) { + uart_mod_regs_t rx; + uart_mod_regs_t tx; } uart_regs_t; +void uart_init(volatile uart_regs_t *uart, uint32_t divisor); void uart_putc(volatile uart_regs_t *uart, char c); void uart_puts(volatile uart_regs_t *uart, const char *s); void uart_puthex(volatile uart_regs_t *uart, uint32_t x);