From e278ec024277039ed6566ba4932283edeec4c823 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Wed, 12 May 2010 16:41:24 -0400 Subject: [PATCH] fixup the uart tx isr. --- lib/uart1.c | 27 ++++++++++++++++----------- src/default_lowlevel.c | 10 +++++++--- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/uart1.c b/lib/uart1.c index 33e511883..672c795e4 100644 --- a/lib/uart1.c +++ b/lib/uart1.c @@ -36,7 +36,7 @@ #include #include -volatile char u1_tx_buf[1024]; +volatile char u1_tx_buf[64]; volatile uint32_t u1_head, u1_tail; void uart1_isr(void) { @@ -50,20 +50,25 @@ void uart1_isr(void) { if (u1_tail >= sizeof(u1_tx_buf)) u1_tail = 0; } - enable_irq(UART1); } void uart1_putc(char c) { - uint32_t h = u1_head; - h = u1_head + 1; - if (h >= sizeof(u1_tx_buf)) - h = 0; - if (h == u1_tail) /* drop chars when no room */ - return; - u1_tx_buf[u1_head] = c; - u1_head = h; + /* disable UART1 since */ + /* UART1 isr modifies u1_head and u1_tail */ + disable_irq(UART1); - uart1_isr(); + if( (u1_head == u1_tail) && + (*UART1_UTXCON != 0)) { + *UART1_UDATA = c; + } else { + u1_tx_buf[u1_head] = c; + u1_head += 1; + if (u1_head >= sizeof(u1_tx_buf)) + u1_head = 0; + if (u1_head == u1_tail) /* drop chars when no room */ + return; + enable_irq(UART1); + } } uint8_t uart1_getc(void) { diff --git a/src/default_lowlevel.c b/src/default_lowlevel.c index 5cabde2d7..dcf0d8b64 100644 --- a/src/default_lowlevel.c +++ b/src/default_lowlevel.c @@ -59,10 +59,14 @@ void uart1_init(uint16_t inc, uint16_t mod, uint8_t samp) { if(samp == UCON_SAMP_16X) set_bit(*UART1_UCON,UCON_SAMP); *GPIO_FUNC_SEL0 = ( (0x01 << (14*2)) | (0x01 << (15*2)) ); /* set GPIO15-14 to UART (UART1 TX and RX)*/ - - /* interrupt when 28 bytes are free */ - *UART1_UTXCON = 28; + + /* interrupt when there are this number or more bytes free in the TX buffer*/ + *UART1_UTXCON = 16; u1_head = 0; u1_tail = 0; + + /* tx and rx interrupts are enabled in the UART by default */ + /* see status register bits 13 and 14 */ + /* enable UART1 interrupts in the interrupt controller */ enable_irq(UART1); }