1 /*----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support - ROUSSET -
3 *----------------------------------------------------------------------------
4 * The software is delivered "AS IS" without warranty or condition of any
5 * kind, either express, implied or statutory. This includes without
6 * limitation any warranty or condition with respect to merchantability or
7 * fitness for any particular purpose, or against the infringements of
8 * intellectual property rights of others.
9 *----------------------------------------------------------------------------
12 * Creation : HIi 03/27/2003
14 *----------------------------------------------------------------------------
16 #include "AT91RM9200.h"
17 #include "lib_AT91RM9200.h"
22 static char erase_seq[] = "\b \b"; /* erase sequence */
26 //unsigned int usa[2] = {(unsigned int)AT91C_BASE_DBGU, (unsigned int)AT91C_ALTERNATE_USART};
27 unsigned int usa[1] = {(unsigned int)AT91C_BASE_DBGU};
31 void at91_init_uarts(void)
40 for(i=0; i<MAX_UARTS; i++) {
42 AT91F_US_ResetRx((AT91PS_USART)us);
43 AT91F_US_ResetTx((AT91PS_USART)us);
47 (AT91PS_USART)us, // DBGU base address
48 AT91C_MASTER_CLOCK, // 60 MHz
49 AT91C_US_ASYNC_MODE, // mode Register to be programmed
50 115200, // baudrate to be programmed
51 0 // timeguard to be programmed
55 AT91F_US_EnableTx((AT91PS_USART)us);
57 AT91F_US_EnableRx((AT91PS_USART)us);
62 int at91_serial_putc(int ch)
65 at91_serial_putc('\r');
66 while (!AT91F_US_TxReady((AT91PS_USART)us));
67 AT91F_US_PutChar((AT91PS_USART)us, (char)ch);
71 /* This getc is modified to be able work on more than one port. On certain
72 * boards (i.e. Figment Designs VersaLink), the debug port is not available
73 * once the unit is in it's enclosure, so, if one needs to get into dfboot
74 * for any reason it is impossible. With this getc, it scans between the debug
75 * port and another port and once it receives a character, it sets that port
76 * as the debug port. */
77 int at91_serial_getc()
90 if(AT91F_US_RxReady((AT91PS_USART)us)) {
94 return((int)AT91F_US_GetChar((AT91PS_USART)us));
99 /*-----------------------------------------------------------------------------
100 * Function Name : AT91F_ReadLine()
104 *-----------------------------------------------------------------------------
106 int AT91F_ReadLine (const char *const prompt, char *console_buffer)
108 char *p = console_buffer;
109 int n = 0; /* buffer index */
110 int plen = strlen (prompt); /* prompt length */
111 int col; /* output column cnt */
123 case '\r': /* Enter */
127 return (p - console_buffer);
129 case 0x03: /* ^C - break */
130 console_buffer[0] = '\0'; /* discard input */
133 case 0x08: /* ^H - backspace */
134 case 0x7F: /* DEL - backspace */
145 * Must be a normal character then
147 if (n < (AT91C_CB_SIZE -2))
149 ++col; /* echo input */
163 /*-----------------------------------------------------------------------------
164 * Function Name : AT91F_WaitKeyPressed()
168 *-----------------------------------------------------------------------------
170 void AT91F_WaitKeyPressed(void)
178 int puts(const char *str)
181 at91_serial_putc(*str);
189 return at91_serial_putc(c);
199 return at91_serial_getc();
202 int strlen(const char *str)
215 #define ZEROPAD 1 /* pad with zero */
216 #define SIGN 2 /* unsigned/signed long */
217 #define LEFT 4 /* left justified */
218 #define LARGE 8 /* use 'ABCDEF' instead of 'abcdef' */
220 #define do_div(n,base) ({ \
222 __res = ((unsigned) n) % (unsigned) base; \
223 n = ((unsigned) n) / (unsigned) base; \
227 static int number(int num, int base, int size,
228 int precision, int type)
230 char c, sign, tmp[66];
231 const char *digits="0123456789ABCDEF";
236 if (base < 2 || base > 16)
238 c = (type & ZEROPAD) ? '0' : ' ';
241 if(type & SIGN && num < 0)
250 tmp[i++] = digits[0];
252 tmp[i++] = digits[do_div(num, base)];
258 if(!(type&(ZEROPAD+LEFT)))
269 while (i < precision--)
281 int hvfprintf(const char *fmt, va_list va)
307 precision = precision * 10 + (*fmt - '0');
312 s = va_arg(va, char *);
320 putc(va_arg(va, int));
324 number(va_arg(va, int), 10, 0, precision, type);
329 number(va_arg(va, int), 16, 0, precision, type);
342 } else if(*fmt == '\\') {
346 } else if(*fmt == 'n') {
358 int printf(const char *fmt, ...)
364 i = hvfprintf(fmt, ap);