add uart.c

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/1/head
liangkangnan 2020-04-12 19:36:06 +08:00
parent 356e47b543
commit ba91618324
3 changed files with 22 additions and 0 deletions

View File

@ -23,6 +23,7 @@ ASM_SRCS += $(COMMON_DIR)/trap_entry.S
C_SRCS += $(COMMON_DIR)/init.c C_SRCS += $(COMMON_DIR)/init.c
C_SRCS += $(COMMON_DIR)/lib/utils.c C_SRCS += $(COMMON_DIR)/lib/utils.c
C_SRCS += $(COMMON_DIR)/lib/xprintf.c C_SRCS += $(COMMON_DIR)/lib/xprintf.c
C_SRCS += $(COMMON_DIR)/lib/uart.c
LINKER_SCRIPT := $(COMMON_DIR)/link.lds LINKER_SCRIPT := $(COMMON_DIR)/link.lds

View File

@ -9,4 +9,6 @@
#define UART0_REG(addr) (*((volatile uint32_t *)addr)) #define UART0_REG(addr) (*((volatile uint32_t *)addr))
void uart_init();
#endif #endif

19
tests/example/lib/uart.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdint.h>
#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);
}