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 __xdata uint16_t lex_i;
26 static __xdata uint8_t lex_c;
27 static __xdata uint8_t lex_status;
28 static __xdata uint8_t lex_echo;
32 static __xdata uint8_t cmd_line[CMD_LEN];
33 static __xdata uint8_t cmd_len;
34 static __xdata 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 * __xdata num_ptr = num_buffer + NUM_LEN;
157 uint8_t __xdata neg = 0;
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 __xdata 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 __xdata 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 __xdata uint8_t * __xdata start, * __xdata 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);
287 __xdata uint16_t block;
292 if (lex_status != SUCCESS)
302 ao_ee_read(((uint32_t) block << 8) | i, &b, 1);
312 __xdata uint16_t block;
314 __xdata uint16_t len;
316 __xdata uint32_t addr;
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;
365 if (lex_status != SUCCESS)
367 ao_dbg_send_byte(lex_i);
374 __xdata uint16_t count;
376 __xdata uint8_t byte;
378 if (lex_status != SUCCESS)
382 lex_status = SYNTAX_ERROR;
385 for (i = 0; i < count; i++) {
386 if (i && (i & 7) == 0)
388 byte = ao_dbg_recv_byte();
401 if ('0' <= c && c <= '9')
403 if ('a' <= c && c <= 'f')
404 return c - ('a' - 10);
405 if ('A' <= c && c <= 'F')
406 return c - ('A' - 10);
407 lex_status = LEX_ERROR;
414 __xdata uint16_t count;
415 __xdata uint16_t addr;
423 if (lex_status != SUCCESS)
425 ao_dbg_start_transfer(addr);
430 b = ao_dbg_read_byte();
433 ao_dbg_end_transfer();
440 __xdata uint16_t count;
441 __xdata uint16_t addr;
448 if (lex_status != SUCCESS)
450 ao_dbg_start_transfer(addr);
452 b = getnibble() << 4;
454 if (lex_status != SUCCESS)
456 ao_dbg_write_byte(b);
458 ao_dbg_end_transfer();
464 __xdata uint8_t more;
466 for (more = ao_log_dump_first(); more; more = ao_log_dump_next()) {
467 putchar(ao_log_dump.type);
469 put16(ao_log_dump.tick);
471 put16(ao_log_dump.u.anon.d0);
473 put16(ao_log_dump.u.anon.d1);
482 while (lex_c != '\n') {
483 ao_serial_putchar(lex_c);
488 static const uint8_t help_txt[] =
489 "All numbers are in hex\n"
490 "? Print this message\n"
491 "a Display current ADC values\n"
492 "d <start> <end> Dump memory\n"
493 "e <block> Dump a block of EEPROM data\n"
494 "w <block> <start> <len> <data> ... Write data to EEPROM\n"
495 "l Dump last flight log\n"
496 "E <0 off, 1 on> Set command echo mode\n"
497 "S<data> Send data to serial line\n"
499 "Target debug commands:\n"
500 "D Enable debug mode\n"
502 "P <byte> ... Put data to debug port\n"
503 "G <count> Get data from debug port\n"
504 "O <count> <addr> Output <count> bytes to target at <addr>\n"
505 "I <count> <addr> Input <count> bytes to target at <addr>\n"
511 put_string(help_txt);
520 put_string("Syntax error\n");
527 ao_cmd(void *parameters)
586 lex_status = SYNTAX_ERROR;
594 __xdata struct ao_task ao_cmd_task;
599 ao_add_task(&ao_cmd_task, ao_cmd);