2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 __pdata uint16_t ao_cmd_lex_i;
22 __pdata uint32_t ao_cmd_lex_u32;
23 __pdata char ao_cmd_lex_c;
24 __pdata enum ao_cmd_status ao_cmd_status;
32 static __xdata char cmd_line[CMD_LEN];
33 static __pdata uint8_t cmd_len;
34 static __pdata uint8_t cmd_i;
37 ao_put_string(__code char *s)
47 ao_put_string ("\010 \010");
60 /* backspace/delete */
61 if (c == '\010' || c == '\177') {
72 while (cmd_len != 0) {
90 if (cmd_len >= CMD_LEN - 2)
92 cmd_line[cmd_len++] = c;
96 cmd_line[cmd_len++] = '\n';
97 cmd_line[cmd_len++] = '\0';
106 ao_cmd_lex_c = cmd_line[cmd_i++];
115 putchar(v + ('a' - 10));
124 if ('0' <= c && c <= '9')
126 if ('a' <= c && c <= 'f')
127 return c - ('a' - 10);
128 if ('A' <= c && c <= 'F')
129 return c - ('A' - 10);
130 ao_cmd_status = ao_cmd_lex_error;
135 ao_cmd_put16(uint16_t v)
142 ao_cmd_put8(uint8_t v)
144 putnibble((v >> 4) & 0xf);
149 ao_cmd_is_white(void)
151 return ao_cmd_lex_c == ' ' || ao_cmd_lex_c == '\t';
157 while (ao_cmd_is_white())
162 ao_cmd_hexchar(char c)
164 if ('0' <= c && c <= '9')
166 if ('a' <= c && c <= 'f')
167 return (c - 'a' + 10);
168 if ('A' <= c && c <= 'F')
169 return (c - 'A' + 10);
181 for (i = 0; i < 2; i++) {
182 n = ao_cmd_hexchar(ao_cmd_lex_c);
184 ao_cmd_status = ao_cmd_syntax_error;
187 ao_cmd_lex_i = (ao_cmd_lex_i << 4) | n;
195 __pdata uint8_t r = ao_cmd_lex_error;
201 n = ao_cmd_hexchar(ao_cmd_lex_c);
204 ao_cmd_lex_i = (ao_cmd_lex_i << 4) | n;
208 if (r != ao_cmd_success)
213 ao_cmd_decimal(void) __reentrant
215 uint8_t r = ao_cmd_lex_error;
220 if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9')
221 ao_cmd_lex_u32 = (ao_cmd_lex_u32 * 10) + (ao_cmd_lex_c - '0');
227 if (r != ao_cmd_success)
229 ao_cmd_lex_i = (uint16_t) ao_cmd_lex_u32;
233 ao_match_word(__code char *word)
236 if (ao_cmd_lex_c != *word) {
237 ao_cmd_status = ao_cmd_syntax_error;
250 if (ao_cmd_status == ao_cmd_success)
251 ao_stdios[ao_cur_stdio].echo = ao_cmd_lex_i != 0;
258 if (!ao_match_word("eboot"))
260 /* Delay waiting for the packet master to be turned off
261 * so that we don't end up back in idle mode because we
262 * received a packet after boot.
265 ao_delay(AO_SEC_TO_TICKS(1));
267 ao_panic(AO_PANIC_REBOOT);
271 #define HAS_VERSION 1
278 printf("manufacturer %s\n"
281 #if HAS_FLIGHT || HAS_TRACKER
282 "current-flight %u\n"
286 #if !DISABLE_LOG_SPACE
290 #if defined(AO_BOOT_APPLICATION_BASE) && defined(AO_BOOT_APPLICATION_BOUND)
299 #if HAS_FLIGHT || HAS_TRACKER
304 #if !DISABLE_LOG_SPACE
305 , (unsigned long) ao_storage_log_max
308 #if defined(AO_BOOT_APPLICATION_BASE) && defined(AO_BOOT_APPLICATION_BOUND)
309 , (uint32_t) AO_BOOT_APPLICATION_BOUND - (uint32_t) AO_BOOT_APPLICATION_BASE
312 printf("software-version %s\n", ao_version);
320 static __code struct ao_cmds *__xdata (ao_cmds[NUM_CMDS]);
321 static __pdata uint8_t ao_ncmds;
326 __pdata uint8_t cmds;
328 __code struct ao_cmds * __pdata cs;
329 __code const char *h;
332 for (cmds = 0; cmds < ao_ncmds; cmds++) {
334 for (cmd = 0; cs[cmd].func; cmd++) {
351 switch(ao_cmd_status) {
352 case ao_cmd_lex_error:
353 case ao_cmd_syntax_error:
354 puts("Syntax error");
362 ao_cmd_register(__code struct ao_cmds *cmds)
364 if (ao_ncmds >= NUM_CMDS)
365 ao_panic(AO_PANIC_CMD);
366 ao_cmds[ao_ncmds++] = cmds;
374 __code struct ao_cmds * __xdata cs;
375 void (*__xdata func)(void);
383 if (c == '\r' || c == '\n')
385 func = (void (*)(void)) NULL;
386 for (cmds = 0; cmds < ao_ncmds; cmds++) {
388 for (cmd = 0; cs[cmd].func; cmd++)
389 if (cs[cmd].help[0] == c) {
399 ao_cmd_status = ao_cmd_syntax_error;
416 __xdata struct ao_task ao_cmd_task;
418 __code struct ao_cmds ao_base_cmds[] = {
421 { ao_task_info, "T\0Tasks" },
423 { echo, "E <0 off, 1 on>\0Echo" },
424 { ao_reboot, "r eboot\0Reboot" },
426 { version, "v\0Version" },
429 { ao_loader, "X\0Switch to boot loader" },
437 ao_cmd_register(&ao_base_cmds[0]);
438 ao_add_task(&ao_cmd_task, ao_cmd, "cmd");