Skip to content

Commit

Permalink
feat(drivers/imx_uart): add driver
Browse files Browse the repository at this point in the history
Signed-off-by: David Cerdeira <[email protected]>
  • Loading branch information
DavidMCerdeira committed Oct 3, 2024
1 parent 43c4321 commit efc5f7b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/platform/drivers/imx_uart/imx_uart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) Bao Project and Contributors. All rights reserved.
*/

#include <drivers/imx_uart.h>
#include <fences.h>

#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++);
}
}
39 changes: 39 additions & 0 deletions src/platform/drivers/imx_uart/inc/drivers/imx_uart.h
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>

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 */
4 changes: 4 additions & 0 deletions src/platform/drivers/imx_uart/objects.mk
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit efc5f7b

Please sign in to comment.