From ba91618324aff639287dc512b0207017ad55ef98 Mon Sep 17 00:00:00 2001 From: liangkangnan Date: Sun, 12 Apr 2020 19:36:06 +0800 Subject: [PATCH] add uart.c Signed-off-by: liangkangnan --- tests/example/common.mk | 1 + tests/example/include/uart.h | 2 ++ tests/example/lib/uart.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/example/lib/uart.c diff --git a/tests/example/common.mk b/tests/example/common.mk index 89482fe..fa660a7 100644 --- a/tests/example/common.mk +++ b/tests/example/common.mk @@ -23,6 +23,7 @@ ASM_SRCS += $(COMMON_DIR)/trap_entry.S C_SRCS += $(COMMON_DIR)/init.c C_SRCS += $(COMMON_DIR)/lib/utils.c C_SRCS += $(COMMON_DIR)/lib/xprintf.c +C_SRCS += $(COMMON_DIR)/lib/uart.c LINKER_SCRIPT := $(COMMON_DIR)/link.lds diff --git a/tests/example/include/uart.h b/tests/example/include/uart.h index f727def..9d2c582 100644 --- a/tests/example/include/uart.h +++ b/tests/example/include/uart.h @@ -9,4 +9,6 @@ #define UART0_REG(addr) (*((volatile uint32_t *)addr)) +void uart_init(); + #endif diff --git a/tests/example/lib/uart.c b/tests/example/lib/uart.c new file mode 100644 index 0000000..44c2759 --- /dev/null +++ b/tests/example/lib/uart.c @@ -0,0 +1,19 @@ +#include + +#include "../include/uart.h" +#include "../include/xprintf.h" + + +static void uart_putc(uint8_t c) +{ + while (UART0_REG(UART0_STATUS) & 0x1); + UART0_REG(UART0_TXDATA) = c; +} + +// 115200bps, 8 N 1 +void uart_init() +{ + UART0_REG(UART0_CTRL) = 0x1; + + xdev_out(uart_putc); +}