tmp commit

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/4/head
liangkangnan 2021-08-10 11:09:53 +08:00
parent c4fe45ffaf
commit ad5adcb843
4 changed files with 12 additions and 10 deletions

View File

@ -50,9 +50,11 @@ extern "C" {
#define UART_RXDATA_RXDATA_FIELD \
((bitfield_field32_t) { .mask = UART_RXDATA_RXDATA_MASK, .index = UART_RXDATA_RXDATA_OFFSET })
void uart_init();
uint8_t uart_getc();
void uart_putc(uint8_t c);
typedef void (*putc)(uint8_t);
void uart0_init(putc put);
uint8_t uart0_getc();
void uart0_putc(uint8_t c);
#ifdef __cplusplus
} // extern "C"

View File

@ -5,7 +5,7 @@
// send one char to uart
void uart_putc(uint8_t c)
void uart0_putc(uint8_t c)
{
while (UART0_REG(UART_STATUS_REG_OFFSET) & (1 << UART_STATUS_TXFULL_BIT));
@ -13,7 +13,7 @@ void uart_putc(uint8_t c)
}
// Block, get one char from uart.
uint8_t uart_getc()
uint8_t uart0_getc()
{
while ((UART0_REG(UART_STATUS_REG_OFFSET) & (1 << UART_STATUS_RXEMPTY_BIT)));
@ -21,10 +21,10 @@ uint8_t uart_getc()
}
// 115200bps, 8 N 1
void uart_init()
void uart0_init(putc put)
{
// enable tx and rx
UART0_REG(UART_CTRL_REG_OFFSET) |= 0x3;
xdev_out(uart_putc);
xdev_out(put);
}

View File

@ -11,7 +11,7 @@ int main()
#ifdef SIMULATION
sim_ctrl_init();
#else
uart_init();
uart0_init(uart0_putc);
#endif
xprintf("hello world\n");

View File

@ -7,10 +7,10 @@
int main()
{
uart_init();
uart0_init(uart0_putc);
while (1) {
// loopback
xprintf("%c", uart_getc());
xprintf("%c", uart0_getc());
}
}