fixup the uart tx isr.

This commit is contained in:
Mariano Alvira 2010-05-12 16:41:24 -04:00
parent 1460eac9cd
commit e278ec0242
2 changed files with 23 additions and 14 deletions

View File

@ -36,7 +36,7 @@
#include <mc1322x.h>
#include <types.h>
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) {

View File

@ -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);
}