From efc5f7b65639f3245d464ed3c21b991fe78eb932 Mon Sep 17 00:00:00 2001 From: David Cerdeira Date: Thu, 26 Sep 2024 17:16:26 +0100 Subject: [PATCH] feat(drivers/imx_uart): add driver Signed-off-by: David Cerdeira --- src/platform/drivers/imx_uart/imx_uart.c | 36 +++++++++++++++++ .../drivers/imx_uart/inc/drivers/imx_uart.h | 39 +++++++++++++++++++ src/platform/drivers/imx_uart/objects.mk | 4 ++ 3 files changed, 79 insertions(+) create mode 100644 src/platform/drivers/imx_uart/imx_uart.c create mode 100644 src/platform/drivers/imx_uart/inc/drivers/imx_uart.h create mode 100644 src/platform/drivers/imx_uart/objects.mk diff --git a/src/platform/drivers/imx_uart/imx_uart.c b/src/platform/drivers/imx_uart/imx_uart.c new file mode 100644 index 000000000..4a3c235b2 --- /dev/null +++ b/src/platform/drivers/imx_uart/imx_uart.c @@ -0,0 +1,36 @@ +/** + * SPDX-License-Identifier: Apache-2.0 + * Copyright (c) Bao Project and Contributors. All rights reserved. + */ + +#include +#include + +#define IMX_UART_STAT2_TXDC (1 << 3) +#define IMX_UART_STAT2_TXFULL (1 << 4) + +void uart_init(volatile struct imx_uart* uart) +{ + UNUSED_ARG(uart); + return; +} + +void uart_enable(volatile struct imx_uart* uart) +{ + UNUSED_ARG(uart); + return; +} + +void uart_putc(volatile struct imx_uart* uart, int8_t c) +{ + while (uart->ts & IMX_UART_STAT2_TXFULL) { } + uart->txd = (uint32_t)c; + while (!(uart->stat2 & IMX_UART_STAT2_TXDC)) { } +} + +void uart_puts(volatile struct imx_uart* uart, int8_t const* str) +{ + while (*str) { + uart_putc(uart, *str++); + } +} diff --git a/src/platform/drivers/imx_uart/inc/drivers/imx_uart.h b/src/platform/drivers/imx_uart/inc/drivers/imx_uart.h new file mode 100644 index 000000000..c019641d8 --- /dev/null +++ b/src/platform/drivers/imx_uart/inc/drivers/imx_uart.h @@ -0,0 +1,39 @@ +/** + * SPDX-License-Identifier: Apache-2.0 + * Copyright (c) Bao Project and Contributors. All rights reserved. + */ + +#ifndef IMX_UART_H +#define IMX_UART_H + +#include + +struct imx_uart { + uint32_t rxd; /* 0x0 */ + uint32_t reserved1[0xf]; /* (0x40 - 0x4) / 4 */ + uint32_t txd; /* 0x40*/ + uint32_t reserved2[0xf]; /* (0x80 - 0x44) / 4 */ + uint32_t cr1; /* 0x80 */ + uint32_t cr2; /* 0x84 */ + uint32_t cr3; /* 0x88 */ + uint32_t cr4; /* 0x8c */ + uint32_t fcr; /* 0x90 */ + uint32_t stat1; /* 0x94 */ + uint32_t stat2; /* 0x98 */ + uint32_t esc; /* 0x9c */ + uint32_t tim; /* 0xa0 */ + uint32_t bir; /* 0xa4 */ + uint32_t bmr; /* 0xa8 */ + uint32_t brc; /* 0xac */ + uint32_t onems; /* 0xb0 */ + uint32_t ts; /* 0xb4 */ +}; + +typedef volatile struct imx_uart bao_uart_t; + +void uart_enable(volatile struct imx_uart* uart); +void uart_init(volatile struct imx_uart* uart); +void uart_puts(volatile struct imx_uart* uart, const int8_t* str); +void uart_putc(volatile struct imx_uart* uart, int8_t str); + +#endif /* IMX_UART_H */ diff --git a/src/platform/drivers/imx_uart/objects.mk b/src/platform/drivers/imx_uart/objects.mk new file mode 100644 index 000000000..ec32d8041 --- /dev/null +++ b/src/platform/drivers/imx_uart/objects.mk @@ -0,0 +1,4 @@ +## SPDX-License-Identifier: Apache-2.0 +## Copyright (c) Bao Project and Contributors. All rights reserved. + +drivers-objs-y+=imx_uart/imx_uart.o