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 */
24 unsigned int usa
[2] = {(unsigned int)AT91C_BASE_DBGU
, (unsigned int)AT91C_ALTERNATE_USART
};
28 void at91_init_uarts(void)
39 AT91F_US_ResetRx((AT91PS_USART
)us
);
40 AT91F_US_ResetTx((AT91PS_USART
)us
);
44 (AT91PS_USART
)us
, // DBGU base address
45 AT91C_MASTER_CLOCK
, // 60 MHz
46 AT91C_US_ASYNC_MODE
, // mode Register to be programmed
47 115200, // baudrate to be programmed
48 0 // timeguard to be programmed
52 AT91F_US_EnableTx((AT91PS_USART
)us
);
54 AT91F_US_EnableRx((AT91PS_USART
)us
);
59 int at91_serial_putc(int ch
)
62 at91_serial_putc('\r');
63 while (!AT91F_US_TxReady((AT91PS_USART
)us
));
64 AT91F_US_PutChar((AT91PS_USART
)us
, (char)ch
);
68 /* This getc is modified to be able work on more than one port. On certain
69 * boards (i.e. Figment Designs VersaLink), the debug port is not available
70 * once the unit is in it's enclosure, so, if one needs to get into dfboot
71 * for any reason it is impossible. With this getc, it scans between the debug
72 * port and another port and once it receives a character, it sets that port
73 * as the debug port. */
74 int at91_serial_getc()
85 if(AT91F_US_RxReady((AT91PS_USART
)us
)) {
87 return((int)AT91F_US_GetChar((AT91PS_USART
)us
));
92 /*-----------------------------------------------------------------------------
93 * Function Name : AT91F_ReadLine()
97 *-----------------------------------------------------------------------------
99 int AT91F_ReadLine (const char *const prompt
, char *console_buffer
)
101 char *p
= console_buffer
;
102 int n
= 0; /* buffer index */
103 int plen
= strlen (prompt
); /* prompt length */
104 int col
; /* output column cnt */
116 case '\r': /* Enter */
120 return (p
- console_buffer
);
122 case 0x03: /* ^C - break */
123 console_buffer
[0] = '\0'; /* discard input */
126 case 0x08: /* ^H - backspace */
127 case 0x7F: /* DEL - backspace */
138 * Must be a normal character then
140 if (n
< (AT91C_CB_SIZE
-2))
142 ++col
; /* echo input */
156 /*-----------------------------------------------------------------------------
157 * Function Name : AT91F_WaitKeyPressed()
161 *-----------------------------------------------------------------------------
163 void AT91F_WaitKeyPressed(void)
171 int puts(const char *str
)
174 at91_serial_putc(*str
);
182 return at91_serial_putc(c
);
192 return at91_serial_getc();
195 int strlen(const char *str
)
208 #define ZEROPAD 1 /* pad with zero */
209 #define SIGN 2 /* unsigned/signed long */
210 #define LEFT 4 /* left justified */
211 #define LARGE 8 /* use 'ABCDEF' instead of 'abcdef' */
213 #define do_div(n,base) ({ \
215 __res = ((unsigned) n) % (unsigned) base; \
216 n = ((unsigned) n) / (unsigned) base; \
220 static int number(int num
, int base
, int size
,
221 int precision
, int type
)
223 char c
, sign
, tmp
[66];
224 const char *digits
="0123456789ABCDEF";
229 if (base
< 2 || base
> 16)
231 c
= (type
& ZEROPAD
) ? '0' : ' ';
234 if(type
& SIGN
&& num
< 0)
243 tmp
[i
++] = digits
[0];
245 tmp
[i
++] = digits
[do_div(num
, base
)];
251 if(!(type
&(ZEROPAD
+LEFT
)))
262 while (i
< precision
--)
274 int hvfprintf(const char *fmt
, va_list va
)
300 precision
= precision
* 10 + (*fmt
- '0');
305 s
= va_arg(va
, char *);
313 putc(va_arg(va
, int));
317 number(va_arg(va
, int), 10, 0, precision
, type
);
322 number(va_arg(va
, int), 16, 0, precision
, type
);
335 } else if(*fmt
== '\\') {
339 } else if(*fmt
== 'n') {
351 int printf(const char *fmt
, ...)
357 i
= hvfprintf(fmt
, ap
);
This page took 0.074154 seconds and 5 git commands to generate.