From 6d96721ac4086f5c53a8f59ab75056e8a76bc221 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Sat, 9 Jul 2011 12:46:30 -0400 Subject: [PATCH] mc1322x: block in uart putc if the TX buffer is full. Can also be configured to drop chars instead with UARTx_DROP_CHARS --- cpu/mc1322x/lib/uart1.c | 20 +++++++++++++++++++- cpu/mc1322x/lib/uart2.c | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/cpu/mc1322x/lib/uart1.c b/cpu/mc1322x/lib/uart1.c index 8479742b7..5d1dfb102 100644 --- a/cpu/mc1322x/lib/uart1.c +++ b/cpu/mc1322x/lib/uart1.c @@ -97,11 +97,29 @@ void uart1_putc(char c) { if (u1_tx_head >= sizeof(u1_tx_buf)) u1_tx_head = 0; if (u1_tx_head == u1_tx_tail) { /* drop chars when no room */ +#if UART1_DROP_CHARS if (u1_tx_head) { u1_tx_head -=1; } else { u1_tx_head = sizeof(u1_tx_buf); } +#else + { + uint32_t u1_tx_tail_save=u1_tx_tail; + /* Back up head to show buffer not empty, and enable tx interrupt */ + u1_tx_head--; +#if UART1_RX_BUFFERSIZE > 32 + *UART1_UCON &= ~(1 << 13); /*enable tx interrupt */ +#else + enable_irq(UART1); +#endif + /* Tail will change after one character goes out */ + while (u1_tx_tail_save == u1_tx_tail) ; + /* Restore head to character we just stuffed */ + u1_tx_head++; + return; + } +#endif /* UART1_DROP_CHARS */ } #if UART1_RX_BUFFERSIZE > 32 - *UART1_UCON &= ~(1 << 13); /*enable tx interrupt */ + *UART1_UCON &= ~(1 << 13); /*enable tx interrupt */ #else enable_irq(UART1); #endif diff --git a/cpu/mc1322x/lib/uart2.c b/cpu/mc1322x/lib/uart2.c index 420913587..cc8ca0bc1 100644 --- a/cpu/mc1322x/lib/uart2.c +++ b/cpu/mc1322x/lib/uart2.c @@ -97,11 +97,29 @@ void uart2_putc(char c) { if (u2_tx_head >= sizeof(u2_tx_buf)) u2_tx_head = 0; if (u2_tx_head == u2_tx_tail) { /* drop chars when no room */ +#if UART2_DROP_CHARS if (u2_tx_head) { u2_tx_head -=1; } else { u2_tx_head = sizeof(u2_tx_buf); } +#else + { + uint32_t u2_tx_tail_save=u2_tx_tail; + /* Back up head to show buffer not empty, and enable tx interrupt */ + u2_tx_head--; +#if UART2_RX_BUFFERSIZE > 32 + *UART2_UCON &= ~(1 << 13); /*enable tx interrupt */ +#else + enable_irq(UART2); +#endif + /* Tail will change after one character goes out */ + while (u2_tx_tail_save == u2_tx_tail) ; + /* Restore head to character we just stuffed */ + u2_tx_head++; + return; + } +#endif /* UART2_DROP_CHARS */ } #if UART2_RX_BUFFERSIZE > 32 - *UART2_UCON &= ~(1 << 13); /*enable tx interrupt */ + *UART2_UCON &= ~(1 << 13); /*enable tx interrupt */ #else enable_irq(UART2); #endif