The unified diff between revisions [23a3e9a5..] and [9142f333..] 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 [23a3e9a50b4034343e3bd217d2c225dcaec064dd]
# new_revision [9142f3330490a5aa00c1686475633b620c2ef5e7]
#
# patch "uart.c"
#  from [37a2e0459886f7f9c4e4a5361e21d50902dbe3f7]
#    to [2ed02bb0e471483e0e77958a43e2e05516d3c127]
#
============================================================
--- uart.c	37a2e0459886f7f9c4e4a5361e21d50902dbe3f7
+++ 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,21 +32,23 @@ 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);
 
+#ifdef USE_UART
+
 void init_uart(void)
 {
 	UREG(FDR) = 0x10; /* DivAddVal = 0, MulVal = 1 */
 
 	UREG(LCR) = 0x80;
 	UREG(DLM) = 0x00;
-	UREG(DLL) = 0x08; /* 14745600 / (16*115200) */
+	UREG(DLL) = 0x20; /* 58982400 / (16*115200) */
 	UREG(LCR) = 0x13;
 	UREG(FCR) = 0x07;
 
@@ -59,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;
 		}
 	}
@@ -80,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;
@@ -91,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) {
@@ -134,6 +176,8 @@ void __attribute__((interrupt("IRQ"))) u
 		break;
 	}
 
+	CHECKPOINT((checkpoint & 0x00ff) | 0x0200);
+
 	interrupt_clear();
 }
 
@@ -205,3 +249,4 @@ bool getch(char *c) {
 	uart_rxread = (uart_rxread + 1) % UART_RXBUFSIZE;
 	return TRUE;
 }
+#endif