diff options
author | Karl Kurbjun <kkurbjun@gmail.com> | 2009-04-14 05:17:03 +0000 |
---|---|---|
committer | Karl Kurbjun <kkurbjun@gmail.com> | 2009-04-14 05:17:03 +0000 |
commit | 5b6af5e56019eec701f81450b79ca413fbae6032 (patch) | |
tree | 6a901be8a525c7099ab55e0c726fe8f0bf31360e /firmware/target/arm/tms320dm320/uart-dm320.c | |
parent | 140c7e6f663d57f4ceae51063932bcbfe3bc0165 (diff) |
M:Robe 500 Fix a bug in the UART receive buffer - remote does not appear to stop working anymore, add support for interupt driven transmit, add very rough remote LCD support.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20706 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/tms320dm320/uart-dm320.c')
-rw-r--r-- | firmware/target/arm/tms320dm320/uart-dm320.c | 121 |
1 files changed, 83 insertions, 38 deletions
diff --git a/firmware/target/arm/tms320dm320/uart-dm320.c b/firmware/target/arm/tms320dm320/uart-dm320.c index 5e2ad5e2be..d68beb6e01 100644 --- a/firmware/target/arm/tms320dm320/uart-dm320.c +++ b/firmware/target/arm/tms320dm320/uart-dm320.c @@ -27,37 +27,48 @@ #define MAX_UART_BUFFER 31 #define SEND_RING_SIZE 256 -#define RECIEVE_RING_SIZE 20 +#define RECEIVE_RING_SIZE 20 char -// uart1_send_buffer_ring[SEND_RING_SIZE], - uart1_recieve_buffer_ring[RECIEVE_RING_SIZE]; + uart1_send_buffer_ring[SEND_RING_SIZE], + uart1_receive_buffer_ring[RECEIVE_RING_SIZE]; -//static unsigned int uart1_send_count, uart1_send_read, uart1_send_write; -static unsigned int uart1_recieve_count, uart1_recieve_read, uart1_recieve_write; +static volatile int uart1_send_count, uart1_send_read, uart1_send_write; +static volatile int uart1_receive_count, uart1_receive_read, uart1_receive_write; void uart_init(void) { // 8-N-1 - IO_UART1_MSR = 0x8000; + IO_UART1_MSR = 0xC400; IO_UART1_BRSR = 0x0057; - IO_UART1_RFCR = 0x8010; /* Trigger later */ + IO_UART1_RFCR = 0x8020; /* Trigger later */ + IO_UART1_TFCR = 0x0000; /* Trigger level */ /* gio 27 is input, uart1 rx gio 28 is output, uart1 tx */ IO_GIO_DIR1 |= (1<<11); /* gio 27 */ IO_GIO_DIR1 &= ~(1<<12); /* gio 28 */ - /* init the recieve buffer */ - uart1_recieve_count=0; - uart1_recieve_read=0; - uart1_recieve_write=0; + /* init the receive buffer */ + uart1_receive_count=0; + uart1_receive_read=0; + uart1_receive_write=0; + + /* init the send buffer */ + uart1_send_count=0; + uart1_send_read=0; + uart1_send_write=0; /* Enable the interrupt */ IO_INTC_EINT0 |= INTR_EINT0_UART1; } + +/* This function is not interrupt driven */ void uart1_putc(char ch) { + /* Wait for the interupt driven puts to finish */ + while(uart1_send_count>0); + /* Wait for room in FIFO */ while ((IO_UART1_TFCR & 0x3f) >= 0x20); @@ -67,45 +78,73 @@ void uart1_putc(char ch) void uart1_puts(const char *str, int size) { - int count=0; - while (count<size) + if(size>SEND_RING_SIZE) + panicf("Too much data passed to uart1_puts"); + + /* Wait for the previous transfer to finish */ + while(uart1_send_count>0); + + memcpy(uart1_send_buffer_ring, str, size); + + /* Disable interrupt while modifying the pointers */ + IO_INTC_EINT0 &= ~INTR_EINT0_UART1; + + uart1_send_count=size; + uart1_send_read=0; + + /* prime the hardware buffer */ + while(((IO_UART1_TFCR & 0x3f) < 0x20) && (uart1_send_count > 0)) { - uart1_putc(str[count]); - count++; + IO_UART1_DTRR=uart1_send_buffer_ring[uart1_send_read++]; + uart1_send_count--; } + + /* Enable interrupt */ + IO_INTC_EINT0 |= INTR_EINT0_UART1; +} + +void uart1_clear_queue(void) +{ + /* Disable interrupt while modifying the pointers */ + IO_INTC_EINT0 &= ~INTR_EINT0_UART1; + uart1_receive_write=0; + uart1_receive_count=0; + uart1_receive_read=0; + /* Enable interrupt */ + IO_INTC_EINT0 |= INTR_EINT0_UART1; } /* This function returns the number of bytes left in the queue after a read is done (negative if fail)*/ -int uart1_gets_queue(char *str, unsigned int size) +int uart1_gets_queue(char *str, int size) { + /* Disable the interrupt while modifying the pointers */ IO_INTC_EINT0 &= ~INTR_EINT0_UART1; int retval; - if(uart1_recieve_count<size) + if(uart1_receive_count<size) { retval= -1; } else { - if(uart1_recieve_read+size<RECIEVE_RING_SIZE) + if(uart1_receive_read+size<=RECEIVE_RING_SIZE) { - memcpy(str,uart1_recieve_buffer_ring+uart1_recieve_read,size); + memcpy(str,uart1_receive_buffer_ring+uart1_receive_read,size); + + uart1_receive_read+=size; } else { - int tempcount=(RECIEVE_RING_SIZE-uart1_recieve_read); - memcpy(str,uart1_recieve_buffer_ring+uart1_recieve_read,tempcount); - memcpy(str+tempcount,uart1_recieve_buffer_ring,size-tempcount); + int tempcount=(RECEIVE_RING_SIZE-uart1_receive_read); + memcpy(str,uart1_receive_buffer_ring+uart1_receive_read,tempcount); + memcpy(str+tempcount,uart1_receive_buffer_ring,size-tempcount); + + uart1_receive_read=size-tempcount; } - uart1_recieve_count-=size; - - if(uart1_recieve_read+size<RECIEVE_RING_SIZE) - uart1_recieve_read+=size; - else - uart1_recieve_read=size-(RECIEVE_RING_SIZE-uart1_recieve_read); - - retval=uart1_recieve_count; + uart1_receive_count-=size; + + retval=uart1_receive_count; } /* Enable the interrupt */ @@ -114,23 +153,29 @@ int uart1_gets_queue(char *str, unsigned int size) return retval; } -/* UART1 receive interupt handler */ +/* UART1 receive/transmit interupt handler */ void UART1(void) { while (IO_UART1_RFCR & 0x3f) { - if (uart1_recieve_count > RECIEVE_RING_SIZE) - panicf("UART1 buffer overflow"); + if (uart1_receive_count > RECEIVE_RING_SIZE) + panicf("UART1 receive buffer overflow"); else { - if(uart1_recieve_write>=RECIEVE_RING_SIZE) - uart1_recieve_write=0; + if(uart1_receive_write>=RECEIVE_RING_SIZE) + uart1_receive_write=0; - uart1_recieve_buffer_ring[uart1_recieve_write] = IO_UART1_DTRR & 0xff; - uart1_recieve_write++; - uart1_recieve_count++; + uart1_receive_buffer_ring[uart1_receive_write]=IO_UART1_DTRR & 0xff; + uart1_receive_write++; + uart1_receive_count++; } } + while ( ((IO_UART1_TFCR & 0x3f) < 0x20) && (uart1_send_count > 0) ) + { + IO_UART1_DTRR=uart1_send_buffer_ring[uart1_send_read++]; + uart1_send_count--; + } + IO_INTC_IRQ0 = INTR_IRQ0_UART1; } |