software/libbase/uart: add polling mode

This commit is contained in:
Florent Kermarrec 2019-09-28 00:35:26 +02:00
parent 3f95b9c0de
commit 49594ed7d4
1 changed files with 44 additions and 0 deletions

View 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