Skip to content

Replace UART with that from amaranth-soc RFC #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions chipflow_lib/software/drivers/uart.c
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
16 changes: 12 additions & 4 deletions chipflow_lib/software/drivers/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
#include <stdint.h>

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);
Expand Down
Loading