aboutsummaryrefslogtreecommitdiff
path: root/triscv/src/uart.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-10-28 00:00:21 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2023-10-28 00:00:21 +0300
commitd96b8c7d12fc61ec609d6138627b9d6d18139a9a (patch)
tree82bc9a4c2b22de6c021097fb79a57b6d7756a127 /triscv/src/uart.c
downloadtri-d96b8c7d12fc61ec609d6138627b9d6d18139a9a.tar.gz
tri-d96b8c7d12fc61ec609d6138627b9d6d18139a9a.zip
move to monorepo
+ Will probably have to make some changes to dir layout to make things make more sense
Diffstat (limited to 'triscv/src/uart.c')
-rw-r--r--triscv/src/uart.c44
1 files changed, 44 insertions, 0 deletions
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 <triscv/uart.h>
+#include <utf9.h>
+
+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
+ };
+}