]> git.droids-corp.org - aversive.git/commitdiff
fix uart recv in non-intr mode
authorzer0 <zer0@carbon.local>
Sat, 20 Feb 2010 16:42:40 +0000 (17:42 +0100)
committerzer0 <zer0@carbon.local>
Sat, 20 Feb 2010 16:42:40 +0000 (17:42 +0100)
modules/comm/uart/uart_recv9_nowait.c
modules/comm/uart/uart_recv_nowait.c

index 8c626a2394c00d168f41811f8b962ac5de1faacd..3cded5c8f9d6fed0189058a2ede4fc96bb979d1e 100644 (file)
@@ -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);
 }
index c4c1a0455a63f361e249efc273028d12f59ed3da..2872d21a0f5438e7f6732a36c49903b9d8a32409 100644 (file)
@@ -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);
 }