From: zer0 Date: Sat, 20 Feb 2010 16:42:40 +0000 (+0100) Subject: fix uart recv in non-intr mode X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=commitdiff_plain;h=6d8949fd4fc3a1e65ff060cfbdb5e405efe15c6c fix uart recv in non-intr mode --- diff --git a/modules/comm/uart/uart_recv9_nowait.c b/modules/comm/uart/uart_recv9_nowait.c index 8c626a2..3cded5c 100644 --- a/modules/comm/uart/uart_recv9_nowait.c +++ b/modules/comm/uart/uart_recv9_nowait.c @@ -31,13 +31,23 @@ int uart_9bits_recv_nowait(uint8_t num) char elt = 0; uint8_t flags; - IRQ_LOCK(flags); - if( CIRBUF_GET_LEN(&g_rx_fifo[num]) >= 2) { - cirbuf_get_buf_tail(&g_rx_fifo[num], (char *)&elt, 2); - cirbuf_del_buf_tail(&g_rx_fifo[num], 2); + /* if interrupt mode is off, we have to check the status + * register */ + if (!(*uart_regs[num].ucsrb & (1 << RXCIE))) { + if ( !(*uart_regs[num].ucsra & (1 << RXC)) ) + return -1; + return uart_get_udr_9bits(num); + } + /* else check the fifo */ + else { + IRQ_LOCK(flags); + if( CIRBUF_GET_LEN(&g_rx_fifo[num]) >= 2) { + cirbuf_get_buf_tail(&g_rx_fifo[num], (char *)&elt, 2); + cirbuf_del_buf_tail(&g_rx_fifo[num], 2); + IRQ_UNLOCK(flags); + return (int)elt; + } IRQ_UNLOCK(flags); - return (int)elt; + return -1; } - IRQ_UNLOCK(flags); - return (-1); } diff --git a/modules/comm/uart/uart_recv_nowait.c b/modules/comm/uart/uart_recv_nowait.c index c4c1a04..2872d21 100644 --- a/modules/comm/uart/uart_recv_nowait.c +++ b/modules/comm/uart/uart_recv_nowait.c @@ -31,13 +31,23 @@ int uart_recv_nowait(uint8_t num) char elt = 0; uint8_t flags; - IRQ_LOCK(flags); - if( !CIRBUF_IS_EMPTY(&g_rx_fifo[num]) ) { - elt = cirbuf_get_tail(&g_rx_fifo[num]); - cirbuf_del_tail(&g_rx_fifo[num]); + /* if interrupt mode is off, we have to check the status + * register */ + if (!(*uart_regs[num].ucsrb & (1 << RXCIE))) { + if ( !(*uart_regs[num].ucsra & (1 << RXC)) ) + return -1; + return uart_get_udr(num); + } + /* else check the fifo */ + else { + IRQ_LOCK(flags); + if( !CIRBUF_IS_EMPTY(&g_rx_fifo[num]) ) { + elt = cirbuf_get_tail(&g_rx_fifo[num]); + cirbuf_del_tail(&g_rx_fifo[num]); + IRQ_UNLOCK(flags); + return (int)elt; + } IRQ_UNLOCK(flags); - return (int)elt; + return -1; } - IRQ_UNLOCK(flags); - return (-1); }