software/libbase/uart: add polling mode
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 27 Sep 2019 22:35:26 +0000 (00:35 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 27 Sep 2019 22:35:26 +0000 (00:35 +0200)
litex/soc/software/libbase/uart.c

index 921459fc986c71e0d50a7cd0afbdb7224a9cf115..4fac827fa0e17793a0b8fb9494a6619c591c7eba 100644 (file)
@@ -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