2021-05-14 13:00:57 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "../include/uart.h"
|
|
|
|
#include "../include/xprintf.h"
|
|
|
|
|
|
|
|
|
|
|
|
// send one char to uart
|
2021-08-10 03:09:53 +00:00
|
|
|
void uart0_putc(uint8_t c)
|
2021-05-14 13:00:57 +00:00
|
|
|
{
|
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.
|
2021-08-10 03:09:53 +00:00
|
|
|
uint8_t uart0_getc()
|
2021-05-14 13:00:57 +00:00
|
|
|
{
|
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
|
2021-08-10 03:09:53 +00:00
|
|
|
void uart0_init(putc put)
|
2021-05-14 13:00:57 +00:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
2021-08-10 03:09:53 +00:00
|
|
|
xdev_out(put);
|
2021-05-14 13:00:57 +00:00
|
|
|
}
|