7 unsigned char _fill0[3];
9 unsigned char _fill1[3];
11 unsigned char _fill2[3];
13 unsigned char _fill3[3];
15 unsigned char _fill4[3];
16 unsigned char modem_control;
17 unsigned char _fill5[3+8];
18 unsigned char modem_status;
19 unsigned char _fill6[3];
23 #define SCR_MIE 0x80 // Modem interrupt enable
24 #define SCR_EIE 0x40 // Error interrupt enable
25 #define SCR_TIE 0x20 // Transmit interrupt enable
26 #define SCR_RIE 0x10 // Receive interrupt enable
27 #define SCR_FCT 0x08 // Flow type 0=>software, 1=>hardware
28 #define SCR_CLK 0x04 // Clock source 0=internal, 1=external
29 #define SCR_TEN 0x02 // Transmitter enabled
30 #define SCR_REN 0x01 // Receiver enabled
32 #define SMR_DIV(x) ((x)<<4) // Clock divisor
33 #define SMR_STOP 0x08 // Stop bits 0=>one, 1=>two
34 #define SMR_STOP_1 0x00
35 #define SMR_STOP_2 0x08
36 #define SMR_PARITY 0x04 // Parity mode 0=>even, 1=odd
37 #define SMR_PARITY_EVEN 0x00
38 #define SMR_PARITY_ODD 0x04
39 #define SMR_PARITY_ON 0x02 // Parity checked
40 #define SMR_PARITY_OFF 0x00
41 #define SMR_LENGTH 0x01 // Character length
42 #define SMR_LENGTH_8 0x00
43 #define SMR_LENGTH_7 0x01
45 #define SSR_MSS 0x80 // Modem status has changed
46 #define SSR_OE 0x40 // Overrun error
47 #define SSR_FE 0x20 // Framing error
48 #define SSR_PE 0x10 // Parity error
49 #define SSR_TxActive 0x08 // Transmitter is active
50 #define SSR_RxActive 0x04 // Receiver is active
51 #define SSR_TxEmpty 0x02 // Tx buffer is empty
52 #define SSR_RxFull 0x01 // Rx buffer contains data
54 #define SMR_CFG 0x08 // Configuration 0=>normal, 1=>null
55 #define SMR_MSU 0x04 // Modem status update 1=>enable
56 #define SMR_DTR 0x02 // Assert DTR
57 #define SMR_RTS 0x01 // Assert RTS
59 #define GP4020_UART1 0xE0018000
60 #define GP4020_UART2 0xE0019000
63 // Initialize a TTY port
66 _tty_init(volatile struct uart *uart)
68 uart->mode = SMR_STOP_1 | SMR_PARITY_OFF | SMR_LENGTH_8;
69 uart->baud = 0x15; // Magic for 57600
70 uart->modem_control = SMR_DTR | SMR_RTS;
71 uart->control = SCR_TEN | SCR_REN;
75 // Output a character to a TTY port
78 _tty_putc(volatile struct uart *uart, char c)
80 // Wait for space for character
82 } while ((uart->status & SSR_TxEmpty) == 0);
87 // Read a character from a TTY port
90 _tty_getc(volatile struct uart *uart)
94 if ((uart->status & 0xF0) != 0) {
96 tty_puthex(uart->TxRx, 2);
99 } while ((uart->status & SSR_RxFull) == 0);
104 // Initialize the TTY ports
106 volatile struct uart *uarts[] = {
107 (volatile struct uart *)GP4020_UART1,
108 (volatile struct uart *)GP4020_UART2
116 tty_puts("\nUart: ");
117 tty_puthex(uart->control, 2);
119 tty_puthex(uart->mode, 2);
121 tty_puthex(uart->baud, 2);
123 tty_puthex(uart->TxRx, 2);
125 tty_puts("\nStat at "); tty_puthex(&uart->status, 8); tty_puts("\n");
132 // Write a character to the selected TTY
135 tty_putc(int chan, char c)
137 _tty_putc(uarts[chan], c);
141 // Read a character from the selected TTY
146 return _tty_getc(uarts[chan]);
150 // Display a string on the selected TTY
153 tty_puts(int chan, char *s)
157 while ((c = *s++) != '\0') {
159 tty_putc(chan, '\r');
166 // Read characters into a buffer, terminated by a '\n' character
167 // Note: the '\n' character is not stored
170 tty_getline(int chan, char *buf)
175 while (((c = tty_getc(chan)) != '\n') && (c != '\r')) {
185 // Display a number in hex
188 tty_puthex(int chan, unsigned long val, int length)
190 char hex[] = "0123456789ABCDEF";
192 char *s = &str[length+3];
196 for (i = 0; i < length; i++) {
197 *--s = hex[(val & 0x0F)];