The unified diff between revisions [253c6510..] 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 [253c65100e2208e0b8c93178896f5aab89e4ec0b]
# new_revision [9142f3330490a5aa00c1686475633b620c2ef5e7]
#
# patch "uart.c"
#  from [601012b857324c934c9bc318a55df1029187a16b]
#    to [2ed02bb0e471483e0e77958a43e2e05516d3c127]
#
============================================================
--- uart.c	601012b857324c934c9bc318a55df1029187a16b
+++ uart.c	2ed02bb0e471483e0e77958a43e2e05516d3c127
@@ -1,6 +1,9 @@
 #include "uart.h"
 #include "types.h"
 #include "interrupt.h"
+#include "event.h"
+#include "led.h"
+#include "panic.h"
 
 #define UARTBASE 0xE000C000
 
@@ -29,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;
 
@@ -58,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;
 		}
 	}
@@ -79,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;
@@ -90,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) {
@@ -112,6 +155,7 @@ void __attribute__((interrupt("IRQ"))) u
 			}
 		}
 		uart_rxwrite = local_rxwrite;
+		event_set(EVENT_UART_INPUT);
 		break;
 
 	case 0x2: /* THRE interrupt */
@@ -132,6 +176,8 @@ void __attribute__((interrupt("IRQ"))) u
 		break;
 	}
 
+	CHECKPOINT((checkpoint & 0x00ff) | 0x0200);
+
 	interrupt_clear();
 }
 
@@ -153,6 +199,31 @@ void putint(unsigned int n) {
 	putstr(s+i);
 }
 
+void putint_s(int n) {
+	char s[12];
+	int i;
+	int neg;
+
+	/* OK, technically, this might not work properly for the most
+	 * negative possible number. Oh well.
+	 */
+	neg = (n < 0);
+	if (neg)
+		n = -n;
+
+	i = 11;
+	s[i] = '\0';
+
+	do {
+		s[--i] = n % 10 + '0';
+	} while ((n /= 10) > 0);
+
+	if (neg)
+		s[--i] = '-';
+
+	putstr(s+i);
+}
+
 void puthex(unsigned int n) {
 	char s[9];
 	int i;
@@ -178,3 +249,4 @@ bool getch(char *c) {
 	uart_rxread = (uart_rxread + 1) % UART_RXBUFSIZE;
 	return TRUE;
 }
+#endif