The unified diff between revisions [4f22e7ef..] and [9ca449dd..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'uart.c'
# # old_revision [4f22e7ef7d3064e3b51a5b868a4722f3f13c747b] # new_revision [9ca449dd7941ad52e33bdcb5c28b2ba35d54219a] # # patch "uart.c" # from [7a38c486dc1280695e1e62c6d3a76d6c9f849f67] # to [2ed02bb0e471483e0e77958a43e2e05516d3c127] # ============================================================ --- uart.c 7a38c486dc1280695e1e62c6d3a76d6c9f849f67 +++ uart.c 2ed02bb0e471483e0e77958a43e2e05516d3c127 @@ -2,6 +2,8 @@ #include "types.h" #include "interrupt.h" #include "event.h" +#include "led.h" +#include "panic.h" #define UARTBASE 0xE000C000 @@ -30,10 +32,10 @@ char uart_rxbuf[UART_RXBUFSIZE]; char uart_txbuf[UART_TXBUFSIZE]; char uart_rxbuf[UART_RXBUFSIZE]; -volatile int uart_txread; -volatile int uart_txwrite; -volatile int uart_rxread; -volatile int uart_rxwrite; +volatile unsigned int uart_txread; +volatile unsigned int uart_txwrite; +volatile unsigned int uart_rxread; +volatile unsigned int uart_rxwrite; volatile bool tx_running; void __attribute__((interrupt("IRQ"))) uart_interrupt_handler(void); @@ -46,7 +48,7 @@ void init_uart(void) UREG(LCR) = 0x80; UREG(DLM) = 0x00; - UREG(DLL) = 0x08; /* 14745600 / (16*115200) */ + UREG(DLL) = 0x20; /* 58982400 / (16*115200) */ UREG(LCR) = 0x13; UREG(FCR) = 0x07; @@ -61,13 +63,18 @@ void putch(char c) { } void putch(char c) { + CHECKPOINT(4); /* Wait for space in the buffer */ - while (uart_txread == ((uart_txwrite+1) % UART_TXBUFSIZE)); + while (uart_txread == ((uart_txwrite+1) % UART_TXBUFSIZE)) ; + interrupt_block(); + if (uart_txread == uart_txwrite) { if (U0THRE) { tx_running = TRUE; UREG(THR) = c; + interrupt_unblock(); + CHECKPOINT(5); return; } } @@ -82,8 +89,39 @@ void putch(char c) { UREG(THR) = c; } } + interrupt_unblock(); + CHECKPOINT(5); } +void putch_irq(char c) { + /* Hope for space in the buffer */ +// if (uart_txread == ((uart_txwrite+1) % UART_TXBUFSIZE)) +// return; + +#if 1 + if (uart_txread == uart_txwrite) { + if (U0THRE) { + tx_running = TRUE; + UREG(THR) = c; + return; + } + } + + uart_txbuf[uart_txwrite] = c; + uart_txwrite = (uart_txwrite + 1) % UART_TXBUFSIZE; + + if (!tx_running) { + if (uart_txread != uart_txwrite) { + tx_running = TRUE; + uart_txread = (uart_txread + 1) % UART_TXBUFSIZE; + UREG(THR) = c; + } + } +#else + UREG(THR) = c; +#endif +} + void __attribute__((interrupt("IRQ"))) uart_interrupt_handler(void) { bool active = FALSE; @@ -93,11 +131,13 @@ void __attribute__((interrupt("IRQ"))) u * to treat them as such in this handler, so let the compiler * have an easier time. */ - int local_txwrite; - int local_txread; - int local_rxwrite; - int local_rxread; + unsigned int local_txwrite; + unsigned int local_txread; + unsigned int local_rxwrite; + unsigned int local_rxread; + CHECKPOINT(((checkpoint & 0x00ff) | 0x0100)); + source = UREG(IIR); switch (source & 0x0e) { @@ -136,6 +176,8 @@ void __attribute__((interrupt("IRQ"))) u break; } + CHECKPOINT((checkpoint & 0x00ff) | 0x0200); + interrupt_clear(); }