Call AT91F_InitUdp to disable usb clock
[romboot.git] / com.cpp
blobd2ea5b1a68dfb7ddd334940ce0497993bbda40c1
1 #include <AT91RM9200.h>
2 #include <lib_AT91RM9200.h>
3 #include "com.h"
5 static char erase_seq[] = "\b \b"; /* erase sequence */
6 static char tab_seq[] = " "; /* used to expand TABs */
8 int at91_dbgu_putc(int ch)
10 while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_DBGU));
11 AT91F_US_PutChar((AT91PS_USART)AT91C_BASE_DBGU, (char)ch);
12 return ch;
15 int at91_dbgu_getc()
17 while(!AT91F_US_RxReady((AT91PS_USART)AT91C_BASE_DBGU));
18 return((int)AT91F_US_GetChar((AT91PS_USART)AT91C_BASE_DBGU));
22 //*-----------------------------------------------------------------------------
23 //* Function Name : AT91F_ClrScr()
24 //* Object : Send a clear screen on the USART
25 //* Input Parameters :
26 //* Return value :
27 //*-----------------------------------------------------------------------------
28 void AT91F_ClrScr(void)
30 puts(CLRSCREEN);
34 //*-----------------------------------------------------------------------------
35 //* Function Name : AT91F_DeleteChar()
36 //* Object :
37 //* Input Parameters :
38 //* Return value :
39 //*-----------------------------------------------------------------------------
40 char *AT91F_DeleteChar(char *buffer, char *p, int *colp, int *np, int plen)
42 char *s;
44 if (*np == 0) {
45 return (p);
48 if (*(--p) == '\t') { /* will retype the whole line */
49 while (*colp > plen) {
50 puts(erase_seq);
51 (*colp)--;
53 for (s=buffer; s<p; ++s) {
54 if (*s == '\t') {
55 puts(tab_seq+((*colp) & 07));
56 *colp += 8 - ((*colp) & 07);
57 } else {
58 ++(*colp);
59 putc(*s);
62 } else {
63 puts(erase_seq);
64 (*colp)--;
66 (*np)--;
67 return (p);
72 //*-----------------------------------------------------------------------------
73 //* Function Name : AT91F_ReadLine()
74 //* Object :
75 //* Input Parameters :
76 //* Return value :
77 //*-----------------------------------------------------------------------------
78 int AT91F_ReadLine (const char *const prompt, char *console_buffer)
80 char *p = console_buffer;
81 int n = 0; /* buffer index */
82 int plen = strlen (prompt); /* prompt length */
83 int col; /* output column cnt */
84 char c;
86 /* print prompt */
87 if(prompt)
88 puts(prompt);
89 col = plen;
91 for (;;)
93 c = getc();
95 switch (c)
97 case '\r': /* Enter */
98 case '\n':
99 *p = '\0';
100 puts ("\r\n");
101 return (p - console_buffer);
103 case 0x03: /* ^C - break */
104 console_buffer[0] = '\0'; /* discard input */
105 return (-1);
107 case 0x15: /* ^U - erase line */
108 while (col > plen)
110 puts(erase_seq);
111 --col;
113 p = console_buffer;
114 n = 0;
115 continue;
117 case 0x17: /* ^W - erase word */
118 p = (char *)AT91F_DeleteChar(console_buffer, p, &col, &n, plen);
119 while ((n > 0) && (*p != ' '))
120 p = (char *)AT91F_DeleteChar(console_buffer, p, &col, &n, plen);
121 continue;
123 case 0x08: /* ^H - backspace */
124 case 0x7F: /* DEL - backspace */
125 p=(char *)AT91F_DeleteChar(console_buffer, p, &col, &n, plen);
126 continue;
128 default:
130 * Must be a normal character then
132 if (n < (AT91C_CB_SIZE -2))
134 ++col; /* echo input */
135 putc(c);
136 *p++ = c;
137 ++n;
139 else /* Buffer full */
140 putc('\a');
146 //*-----------------------------------------------------------------------------
147 //* Function Name : AT91F_WaitKeyPressed()
148 //* Object :
149 //* Input Parameters :
150 //* Return value :
151 //*-----------------------------------------------------------------------------
152 void AT91F_WaitKeyPressed(void)
154 int c;
155 puts("Hit a Key!");
156 c = getc();