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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 #define SYNTAX_ERROR 2
25 static __data uint16_t lex_i;
26 static __data uint8_t lex_c;
27 static __data uint8_t lex_status;
28 static __data uint8_t lex_echo;
32 static __xdata uint8_t cmd_line[CMD_LEN];
33 static __data uint8_t cmd_len;
34 static __data uint8_t cmd_i;
41 ao_usb_putchar((uint8_t) c);
53 return (char) ao_usb_getchar();
74 /* backspace/delete */
75 if (c == '\010' || c == '\177') {
78 put_string("\010 \010");
86 while (cmd_len != 0) {
88 put_string("\010 \010");
104 if (cmd_len >= CMD_LEN - 2) {
109 cmd_line[cmd_len++] = c;
113 cmd_line[cmd_len++] = '\n';
114 cmd_line[cmd_len++] = '\0';
123 lex_c = cmd_line[cmd_i++];
132 putchar(v + ('a' - 10));
139 for (i = 3; i >= 0; i--)
140 putnibble((v >> (i << 2)) & 0xf);
146 putnibble((v >> 4) & 0xf);
155 static uint8_t __xdata num_buffer[NUM_LEN];
156 uint8_t __xdata *num_ptr = num_buffer + NUM_LEN;
165 *--num_ptr = '0' + i % 10;
170 while (num_ptr != num_buffer)
172 put_string(num_buffer);
179 while (lex_c == ' ' || lex_c == '\t')
186 uint8_t r = LEX_ERROR;
191 if ('0' <= lex_c && lex_c <= '9')
192 lex_i = (lex_i << 4) | (lex_c - '0');
193 else if ('a' <= lex_c && lex_c <= 'f')
194 lex_i = (lex_i << 4) | (lex_c - 'a' + 10);
195 else if ('A' <= lex_c && lex_c <= 'F')
196 lex_i = (lex_i << 4) | (lex_c - 'A' + 10);
210 uint8_t r = LEX_ERROR;
215 if ('0' <= lex_c && lex_c <= '9')
216 lex_i = (lex_i * 10 ) | (lex_c - '0');
230 while (lex_c != '\n')
237 __xdata struct ao_adc packet;
239 put_string("tick: ");
241 put_string(" accel: ");
242 puti(packet.accel >> 4);
243 put_string(" pres: ");
244 puti(packet.pres >> 4);
245 put_string(" temp: ");
246 puti(packet.temp >> 4);
247 put_string(" batt: ");
248 puti(packet.v_batt >> 4);
249 put_string(" drogue: ");
250 puti(packet.sense_d >> 4);
251 put_string(" main: ");
252 puti(packet.sense_m >> 4);
260 uint8_t __xdata *start, *end;
263 start = (uint8_t __xdata *) lex_i;
265 end = (uint8_t __xdata *) lex_i;
266 if (lex_status != SUCCESS)
269 while (start <= end) {
273 put16((uint16_t) start);
292 if (lex_status != SUCCESS)
302 ao_ee_read(((uint32_t) block << 8) | i, &b, 1);
322 addr = ((uint32_t) block << 8) | i;
325 if (lex_status != SUCCESS)
329 if (lex_status != SUCCESS)
332 ao_ee_write(addr, &b, 1);
342 lex_echo = lex_i != 0;
345 #if INCLUDE_REMOTE_DEBUG
366 if (lex_status != SUCCESS)
368 dbg_send_byte(lex_i);
379 if (lex_status != SUCCESS)
383 lex_status = SYNTAX_ERROR;
386 for (i = 0; i < count; i++) {
387 if (i && (i & 7) == 0)
389 byte = dbg_recv_byte();
402 if ('0' <= c && c <= '9')
404 if ('a' <= c && c <= 'f')
405 return c - ('a' - 10);
406 if ('A' <= c && c <= 'F')
407 return c - ('A' - 10);
408 lex_status = LEX_ERROR;
424 if (lex_status != SUCCESS)
426 dbg_start_transfer(addr);
449 if (lex_status != SUCCESS)
451 dbg_start_transfer(addr);
453 b = getnibble() << 4;
455 if (lex_status != SUCCESS)
468 for (more = ao_log_dump_first(); more; more = ao_log_dump_next()) {
469 putchar(ao_log_dump.type);
471 put16(ao_log_dump.tick);
473 put16(ao_log_dump.u.anon.d0);
475 put16(ao_log_dump.u.anon.d1);
480 static const uint8_t help_txt[] =
481 "All numbers are in hex\n"
482 "? Print this message\n"
483 "a Display current ADC values\n"
484 "d <start> <end> Dump memory\n"
485 "e <block> Dump a block of EEPROM data\n"
486 "w <block> <start> <len> <data> ... Write data to EEPROM\n"
487 "l Dump last flight log\n"
488 "E <0 off, 1 on> Set command echo mode\n"
489 #if INCLUDE_REMOTE_DEBUG
491 "Target debug commands:\n"
492 "D Enable debug mode\n"
494 "P <byte> ... Put data to debug port\n"
495 "G <count> Get data from debug port\n"
496 "O <count> <addr> Output <count> bytes to target at <addr>\n"
497 "I <count> <addr> Input <count> bytes to target at <addr>\n"
504 put_string(help_txt);
513 put_string("Syntax error\n");
520 ao_cmd(void *parameters)
554 #if INCLUDE_REMOTE_DEBUG
578 lex_status = SYNTAX_ERROR;
586 struct ao_task __xdata cmd_task;
591 ao_add_task(&cmd_task, ao_cmd);