2 * (C) Copyright 2007 Catalin Patulea <cat@vv.carleton.ca>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #define CONFIG_UART_BRSR 87
27 #define MAX_UART_BUFFER 32
28 static unsigned char uart1buffer
[MAX_UART_BUFFER
];
29 int uart1read
= 0, uart1write
= 0, uart1count
= 0;
31 void do_checksums(char *data
, int len
, char *xor, char *add
)
47 IO_UART1_BRSR
=CONFIG_UART_BRSR
;
48 IO_UART1_RFCR
= 0x8000;
49 /* gio 27 is input, uart1 rx
50 gio 28 is output, uart1 tx */
51 IO_GIO_DIR1
|= (1<<11); /* gio 27 */
52 IO_GIO_DIR1
&= ~(1<<12); /* gio 28 */
54 /* init the recieve buffer */
59 /* Enable the interrupt */
60 IO_INTC_EINT0
|= (1<<IRQ_UART1
);
63 void uartPutc(char ch
) {
64 // Wait for room in FIFO
65 while ((IO_UART1_TFCR
& 0x3f) >= 0x20);
71 // Unsigned integer to ASCII hexadecimal conversion
72 void uartPutHex(unsigned int n
) {
75 for (i
= 8; i
!= 0; i
--) {
76 unsigned int digit
= n
>> 28;
77 uartPutc(digit
>= 10 ? digit
- 10 + 'A' : digit
+ '0');
82 void uartPuts(const char *str
) {
84 while ((ch
= *str
++) != '\0') {
89 void uartGets(char *str
, unsigned int size
) {
93 // Wait for FIFO to contain something
94 while ((IO_UART1_RFCR
& 0x3f) == 0);
97 ch
= (char)IO_UART1_DTRR
;
99 // Echo character back
102 // If CR, also echo LF, null-terminate, and return
119 int uartPollch(unsigned int ticks
) {
121 if (IO_UART1_RFCR
& 0x3f) {
122 return IO_UART1_DTRR
& 0xff;
129 bool uartAvailable(void)
131 return uart1count
> 0;
134 void uart1_heartbeat(void)
136 char data
[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'};
140 void uartSendData(char* data
, int len
)
147 bool uart1_getch(char *c
)
151 *c
= uart1buffer
[uart1read
];
152 uart1read
= (uart1read
+1) % MAX_UART_BUFFER
;
159 /* UART1 receive intterupt handler */
162 if (IO_UART1_RFCR
& 0x3f)
164 if (uart1count
>= MAX_UART_BUFFER
)
165 panicf("UART1 buffer overflow");
166 uart1buffer
[uart1write
] = IO_UART1_DTRR
& 0xff;
167 uart1write
= (uart1write
+1) % MAX_UART_BUFFER
;
171 IO_INTC_IRQ0
= (1<<IRQ_UART1
);