From d96b8c7d12fc61ec609d6138627b9d6d18139a9a Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 28 Oct 2023 00:00:21 +0300 Subject: move to monorepo + Will probably have to make some changes to dir layout to make things make more sense --- triscv/src/uart.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 triscv/src/uart.c (limited to 'triscv/src/uart.c') diff --git a/triscv/src/uart.c b/triscv/src/uart.c new file mode 100644 index 0000000..492f0dd --- /dev/null +++ b/triscv/src/uart.c @@ -0,0 +1,44 @@ +#include +#include + +struct uart { + /* guess this doesn't need much for now, at least until I add some state + * stuff to it */ +}; + +struct uart *uart_create() +{ + return calloc(1, sizeof(struct uart)); +} + +void uart_destroy(struct uart *uart) +{ + free(uart); +} + +static void uart_write1(struct cpu *cpu, struct uart *uart, pm_t addr, tri_t t) +{ + (void)cpu; + (void)uart; + (void)addr; + +#define U8_LEN 16 + uint8_t u8[U8_LEN] = {0}; + size_t u9_read = 0; + size_t l = utf9_to_utf8(u8, U8_LEN, &t, 1, &u9_read); + + for (size_t i = 0; i < l; ++i) + putchar(u8[i]); +} + +struct dev uart_dev(struct uart *uart) +{ + return (struct dev){ + .dev = uart, + .size = 1, + .write1 = (dev_write1_t)uart_write1, + .write3 = NULL, /* illegal */ + .read1 = NULL, /* not supported for now */ + .read3 = NULL + }; +} -- cgit v1.3