From 758fc37307002ab57ef8e74ea2bc9b1ecd544ee8 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Tue, 12 Jul 2011 07:05:04 -0400 Subject: [PATCH] mc1322x: flush the rx fifos when full --- cpu/mc1322x/lib/uart1.c | 26 ++++++++++++++------------ cpu/mc1322x/lib/uart2.c | 26 ++++++++++++++------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/cpu/mc1322x/lib/uart1.c b/cpu/mc1322x/lib/uart1.c index 5d1dfb102..ee570aad6 100644 --- a/cpu/mc1322x/lib/uart1.c +++ b/cpu/mc1322x/lib/uart1.c @@ -47,19 +47,21 @@ volatile uint32_t u1_rx_head, u1_rx_tail; void uart1_isr(void) { #if UART1_RX_BUFFERSIZE > 32 - if (*UART1_USTAT & ( 1 << 6)) { //receive interrupt - while( *UART1_URXCON != 0 ) { //flush the hardware fifo into the software buffer - uint32_t u1_rx_tail_next; - u1_rx_tail_next = u1_rx_tail+1; - if (u1_rx_tail_next >= sizeof(u1_rx_buf)) - u1_rx_tail_next = 0; - if (u1_rx_head != u1_rx_tail_next) { - u1_rx_buf[u1_rx_tail]= *UART1_UDATA; - u1_rx_tail = u1_rx_tail_next; - } + if (*UART1_USTAT & ( 1 << 6)) { //receive interrupt + while( *UART1_URXCON != 0 ) { //flush the hardware fifo into the software buffer + uint32_t u1_rx_tail_next; + u1_rx_tail_next = u1_rx_tail+1; + if (u1_rx_tail_next >= sizeof(u1_rx_buf)) + u1_rx_tail_next = 0; + if (u1_rx_head != u1_rx_tail_next) { + u1_rx_buf[u1_rx_tail]= *UART1_UDATA; + u1_rx_tail = u1_rx_tail_next; + } else { //buffer is full, flush the fifo + while (*UART1_URXCON !=0) if (*UART1_UDATA); + } + } + return; } - return; - } #endif while( *UART1_UTXCON != 0 ) { diff --git a/cpu/mc1322x/lib/uart2.c b/cpu/mc1322x/lib/uart2.c index cc8ca0bc1..239d010e4 100644 --- a/cpu/mc1322x/lib/uart2.c +++ b/cpu/mc1322x/lib/uart2.c @@ -47,19 +47,21 @@ volatile uint32_t u2_rx_head, u2_rx_tail; void uart2_isr(void) { #if UART2_RX_BUFFERSIZE > 32 - if (*UART2_USTAT & ( 1 << 6)) { //receive interrupt - while( *UART2_URXCON != 0 ) { //flush the hardware fifo into the software buffer - uint32_t u2_rx_tail_next; - u2_rx_tail_next = u2_rx_tail+1; - if (u2_rx_tail_next >= sizeof(u2_rx_buf)) - u2_rx_tail_next = 0; - if (u2_rx_head != u2_rx_tail_next) { - u2_rx_buf[u2_rx_tail]= *UART2_UDATA; - u2_rx_tail = u2_rx_tail_next; - } + if (*UART2_USTAT & ( 1 << 6)) { //receive interrupt + while( *UART2_URXCON != 0 ) { //flush the hardware fifo into the software buffer + uint32_t u2_rx_tail_next; + u2_rx_tail_next = u2_rx_tail+1; + if (u2_rx_tail_next >= sizeof(u2_rx_buf)) + u2_rx_tail_next = 0; + if (u2_rx_head != u2_rx_tail_next) { + u2_rx_buf[u2_rx_tail]= *UART2_UDATA; + u2_rx_tail = u2_rx_tail_next; + } else { //buffer is full, flush the fifo + while (*UART2_URXCON !=0) if (*UART2_UDATA); + } + } + return; } - return; - } #endif while( *UART2_UTXCON != 0 ) {