2021-05-14 13:00:57 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "../include/uart.h"
|
|
|
|
#include "../include/xprintf.h"
|
|
|
|
|
|
|
|
|
|
|
|
// send one char to uart
|
|
|
|
void uart_putc(uint8_t c)
|
|
|
|
{
|
2021-08-07 06:30:29 +00:00
|
|
|
while (UART0_REG(UART_STATUS_REG_OFFSET) & (1 << UART_STATUS_TXFULL_BIT));
|
|
|
|
|
|
|
|
UART0_REG(UART_TXDATA_REG_OFFSET) = c;
|
2021-05-14 13:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Block, get one char from uart.
|
|
|
|
uint8_t uart_getc()
|
|
|
|
{
|
2021-08-07 06:30:29 +00:00
|
|
|
while ((UART0_REG(UART_STATUS_REG_OFFSET) & (1 << UART_STATUS_RXEMPTY_BIT)));
|
|
|
|
|
|
|
|
return (UART0_REG(UART_RXDATA_REG_OFFSET) & 0xff);
|
2021-05-14 13:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 115200bps, 8 N 1
|
|
|
|
void uart_init()
|
|
|
|
{
|
|
|
|
// enable tx and rx
|
2021-08-07 06:30:29 +00:00
|
|
|
UART0_REG(UART_CTRL_REG_OFFSET) |= 0x3;
|
2021-05-14 13:00:57 +00:00
|
|
|
|
|
|
|
xdev_out(uart_putc);
|
|
|
|
}
|