From: Florent Kermarrec Date: Fri, 27 Sep 2019 22:35:26 +0000 (+0200) Subject: software/libbase/uart: add polling mode X-Git-Tag: 24jan2021_ls180~982 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=49594ed7d4754ba2a670b17d94b000ecc88de563;p=litex.git software/libbase/uart: add polling mode --- diff --git a/litex/soc/software/libbase/uart.c b/litex/soc/software/libbase/uart.c index 921459fc..4fac827f 100644 --- a/litex/soc/software/libbase/uart.c +++ b/litex/soc/software/libbase/uart.c @@ -8,6 +8,10 @@ * with logical AND. */ +//#define UART_POLLING + +#ifndef UART_POLLING + #define UART_RINGBUFFER_SIZE_RX 128 #define UART_RINGBUFFER_MASK_RX (UART_RINGBUFFER_SIZE_RX-1) @@ -108,3 +112,43 @@ void uart_sync(void) { while(tx_consume != tx_produce); } + +#else + +void uart_isr(void) +{ +} + +char uart_read(void) +{ + char c; + while (uart_rxempty_read()); + c = uart_rxtx_read(); + uart_ev_pending_write(UART_EV_RX); + return c; +} + +int uart_read_nonblock(void) +{ + return (uart_rxempty_read() == 0); +} + +void uart_write(char c) +{ + while (uart_txfull_read()); + uart_rxtx_write(c); + uart_ev_pending_write(UART_EV_TX); +} + +void uart_init(void) +{ + uart_ev_pending_write(uart_ev_pending_read()); + uart_ev_enable_write(UART_EV_TX | UART_EV_RX); +} + +void uart_sync(void) +{ + while (uart_txfull_read()); +} + +#endif \ No newline at end of file