The unified diff between revisions [1dfe3b7e..] and [24d5b9f4..] 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 [1dfe3b7eee76f3c8aea3b33932857682ee17701c] # new_revision [24d5b9f4dff9135787b198fe1127d9c1e3326b9c] # # patch "uart.c" # from [07a014210246046a28c0b690de8dd6dd8af95e2d] # to [7a38c486dc1280695e1e62c6d3a76d6c9f849f67] # ============================================================ --- uart.c 07a014210246046a28c0b690de8dd6dd8af95e2d +++ uart.c 7a38c486dc1280695e1e62c6d3a76d6c9f849f67 @@ -1,11 +1,10 @@ #include "uart.h" #include "types.h" #include "interrupt.h" +#include "event.h" #define UARTBASE 0xE000C000 -#define FP0XVAL (*((volatile unsigned int *) 0x3FFFC014)) - #define RBR 0x00 #define THR 0x00 #define DLL 0x00 @@ -39,6 +38,8 @@ void __attribute__((interrupt("IRQ"))) u void __attribute__((interrupt("IRQ"))) uart_interrupt_handler(void); +#ifdef USE_UART + void init_uart(void) { UREG(FDR) = 0x10; /* DivAddVal = 0, MulVal = 1 */ @@ -114,6 +115,7 @@ void __attribute__((interrupt("IRQ"))) u } } uart_rxwrite = local_rxwrite; + event_set(EVENT_UART_INPUT); break; case 0x2: /* THRE interrupt */ @@ -155,6 +157,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; @@ -172,14 +199,12 @@ void puthex(unsigned int n) { putstr(s+i); } -char getch(void) { - char c; +bool getch(char *c) { + if (uart_rxread == uart_rxwrite) + return FALSE; - while (uart_rxread == uart_rxwrite) { - FP0XVAL ^= 0x04000000; - } - - c = uart_rxbuf[uart_rxread]; + *c = uart_rxbuf[uart_rxread]; uart_rxread = (uart_rxread + 1) % UART_RXBUFSIZE; - return c; + return TRUE; } +#endif