Skip to content

Commit d2ec08f

Browse files
committed
Replace UART with that from amaranth-soc RFC
Signed-off-by: gatecat <[email protected]>
1 parent 7d64c3c commit d2ec08f

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

chipflow_lib/software/drivers/uart.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
/* SPDX-License-Identifier: BSD-2-Clause */
22
#include "uart.h"
33

4+
void uart_init(volatile uart_regs_t *uart, uint32_t divisor) {
5+
uart->tx.config = 0;
6+
uart->tx.phy_config = divisor & 0x00FFFFFF;
7+
uart->tx.config = 1;
8+
uart->rx.config = 0;
9+
uart->rx.phy_config = divisor & 0x00FFFFFF;
10+
uart->rx.config = 1;
11+
};
12+
413
void uart_putc(volatile uart_regs_t *uart, char c) {
514
if (c == '\n')
615
uart_putc(uart, '\r');
7-
while (!uart->tx_ready)
16+
while (!(uart->tx.status & 0x1))
817
;
9-
uart->tx_data = c;
18+
uart->tx.data = c;
1019
}
1120

1221
void uart_puts(volatile uart_regs_t *uart, const char *s) {

chipflow_lib/software/drivers/uart.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
#include <stdint.h>
66

77
typedef struct __attribute__((packed, aligned(4))) {
8-
uint32_t tx_data;
9-
uint32_t rx_data;
10-
uint32_t tx_ready;
11-
uint32_t rx_avail;
8+
uint8_t config;
9+
uint8_t padding_0[3];
10+
uint32_t phy_config;
11+
uint8_t status;
12+
uint8_t data;
13+
uint8_t padding_1[6];
14+
} uart_mod_regs_t;
15+
16+
typedef struct __attribute__((packed, aligned(4))) {
17+
uart_mod_regs_t rx;
18+
uart_mod_regs_t tx;
1219
} uart_regs_t;
1320

21+
void uart_init(volatile uart_regs_t *uart, uint32_t divisor);
1422
void uart_putc(volatile uart_regs_t *uart, char c);
1523
void uart_puts(volatile uart_regs_t *uart, const char *s);
1624
void uart_puthex(volatile uart_regs_t *uart, uint32_t x);

0 commit comments

Comments
 (0)