From 7c790fe859dff062692964338091ffbbcdf63257 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 18 Aug 2009 12:40:24 -0700 Subject: Rename tools to ao- Use a consistent prefix to make it easier to remember which programs belong to this package Signed-off-by: Keith Packard --- ao-tools/ao-dbg/ao-dbg-parse.c | 241 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 ao-tools/ao-dbg/ao-dbg-parse.c (limited to 'ao-tools/ao-dbg/ao-dbg-parse.c') diff --git a/ao-tools/ao-dbg/ao-dbg-parse.c b/ao-tools/ao-dbg/ao-dbg-parse.c new file mode 100644 index 00000000..5db6c01c --- /dev/null +++ b/ao-tools/ao-dbg/ao-dbg-parse.c @@ -0,0 +1,241 @@ +/* + * Copyright © 2008 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "ao-dbg.h" + +static struct command_function functions[] = { + { "help", "?", command_help, "help", "Print this list\n" }, + { "quit", "q", command_quit, "[q]uit", "Quit\n" }, + { "di", "di", command_di, "di ", + "Dump imem\n" }, + { "ds", "ds", command_ds, "ds ", + "Dump sprs\n" }, + { "dx", "dx", command_dx, "dx ", + "Dump xaddr\n" }, + { "set", "t", command_set, "se[t] mem
...", + "Set mem {xram|rom|iram|sfr}\n" + "set bit \n" }, + { "dump", "d", command_dump, "[d]ump ", + "Dump {xram|rom|iram|sfr} \n" }, + { "file", "file", command_file, "file ", + "Pretend to load executable from \n" }, + { "pc", "p", command_pc, "[p]c [addr]", + "Get or set pc value\n" }, + { "break", "b", command_break,"[b]reak ", + "Set break point\n" }, + { "clear", "c", command_clear,"[c]lear ", + "Clear break point\n" }, + { "run", "r", command_run, "[r]un [start] [stop]", + "Run with optional start and temp breakpoint addresses\n" }, + { "go", "g", command_run, "[g]o [start] [stop]", + "Run with optional start and temp breakpoint addresses\n" }, + { "next", "n", command_next, "[n]ext", + "Step over one instruction, past any call\n" }, + { "step", "s", command_step, "[s]tep", + "Single step\n" }, + { "load", "l", command_load, "[l]oad ", + "Load a hex file into memory or flash" }, + { "halt", "h", command_halt, "[h]alt", + "Halt the processor\n" }, + { "reset","res",command_reset, "[res]et", + "Reset the CPU\n" }, + { "status","status",command_status, "status", + "Display CC1111 debug status\n" }, + { "info", "i", command_info, "[i]info", + "Get information\n" }, + { "stop", "stop", command_stop, "stop", + "Ignored\n" }, + { NULL, NULL, NULL, NULL, NULL }, +}; + +#ifndef FALSE +#define FALSE 0 +#define TRUE 1 +#endif + +static int +string_to_int(char *s, int *v) +{ + char *endptr; + + if (isdigit(s[0]) || s[0] == '-' || s[0] == '+') { + *v = strtol(s, &endptr, 0); + if (endptr == s) + return FALSE; + } else if (*s == '\'') { + s++; + if (*s == '\\') { + s++; + switch (*s) { + case 'n': + *v = '\n'; + break; + case 't': + *v = '\t'; + break; + default: + *v = (int) *s; + break; + } + } else + *v = (int) *s; + s++; + if (*s != '\'') + return FALSE; + } + else + return FALSE; + return TRUE; +} + +struct command_function * +command_string_to_function(struct command_function *functions, char *name) +{ + int i; + for (i = 0; functions[i].name; i++) + if (!strcmp(name, functions[i].name) || + !strcmp(name, functions[i].alias)) + return &functions[i]; + return NULL; +} + +enum command_result +command_function_help(struct command_function *functions, int argc, char **argv) +{ + int i; + struct command_function *func; + + if (argc == 1) { + for (i = 0; functions[i].name; i++) + s51_printf("%-10s%s\n", functions[i].name, + functions[i].usage); + } else { + for (i = 1; i < argc; i++) { + func = command_string_to_function(functions, argv[i]); + if (!func) { + s51_printf("%-10s unknown command\n", argv[i]); + return command_syntax; + } + s51_printf("%-10s %s\n%s", func->name, + func->usage, func->help); + } + } + return command_debug; +} + +static int +command_split_into_words(char *line, char **argv) +{ + char quotechar; + int argc; + + argc = 0; + while (*line) { + while (isspace(*line)) + line++; + if (!*line) + break; + if (*line == '"') { + quotechar = *line++; + *argv++ = line; + argc++; + while (*line && *line != quotechar) + line++; + if (*line) + *line++ = '\0'; + } else { + *argv++ = line; + argc++; + while (*line && !isspace(*line)) + line++; + if (*line) + *line++ = '\0'; + } + } + *argv = 0; + return argc; +} + +enum command_result +command_help(int argc, char **argv) +{ + return command_function_help(functions, argc, argv); +} + +void +command_syntax_error(int argc, char **argv) +{ + s51_printf("Syntax error in:"); + while (*argv) + s51_printf(" %s", *argv++); + s51_printf("\n"); +} + +void +command_read (void) +{ + int argc; + char line[1024]; + char *argv[20]; + enum command_result result; + struct command_function *func; + + s51_dbg = ccdbg_open (); + if (!s51_dbg) { + perror("ccdbg_open"); + exit(1); + } + ccdbg_debug_mode(s51_dbg); + ccdbg_halt(s51_dbg); + s51_printf("Welcome to the non-simulated processor\n"); + for (;;) { + if (s51_read_line (line, sizeof line) == 0) + break; + s51_interrupted = 0; + argc = command_split_into_words(line, argv); + if (argc > 0) { + func = command_string_to_function(functions, argv[0]); + if (!func) + command_syntax_error(argc, argv); + else + { + result = (*func->func)(argc, argv); + if (s51_interrupted) + result = command_interrupt; + switch (result) { + case command_syntax: + command_syntax_error(argc, argv); + break; + case command_error: + s51_printf("Error\n"); + break; + case command_success: + break; + case command_interrupt: + ccdbg_halt(s51_dbg); + s51_printf("Interrupted\n"); + break; + default: + break; + } + } + } + } + ccdbg_close(s51_dbg); + s51_printf("...\n"); +} -- cgit v1.2.3 From 9b03d620722dc54630539afba40720c30de69b2d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 18 Aug 2009 12:19:31 -0700 Subject: Use --tty/-T on command line to specify target device Also, use the ALTOS_TTY environment variable in all tools. Note that the magic value of "BITBANG" switches the library to connecting through a CP2103 instead. Signed-off-by: Keith Packard --- .gitignore | 1 + ao-tools/ao-bitbang/ao-bitbang.c | 2 +- ao-tools/ao-dbg/ao-dbg-main.c | 12 ++++++++- ao-tools/ao-dbg/ao-dbg-parse.c | 6 ++--- ao-tools/ao-dbg/ao-dbg.1 | 4 +++ ao-tools/ao-dbg/ao-dbg.h | 1 + ao-tools/ao-eeprom/ao-eeprom.c | 33 ++++++++++++++++++++++-- ao-tools/ao-load/ao-load.c | 54 ++++++++++++++++++++++++++-------------- ao-tools/ao-rawload/ao-rawload.c | 33 +++++++++++++++++++++--- ao-tools/lib/ccdbg-io.c | 19 +++++++++----- ao-tools/lib/ccdbg.h | 2 +- ao-tools/lib/cp-usb-async.c | 1 + ao-view/aoview.glade | 1 - ao-view/aoview.h | 4 +++ ao-view/aoview_main.c | 16 ++++++++---- 15 files changed, 146 insertions(+), 43 deletions(-) (limited to 'ao-tools/ao-dbg/ao-dbg-parse.c') diff --git a/.gitignore b/.gitignore index 8b83dd3f..b3d2d562 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ *.rst *.sym .deps +TAGS aclocal.m4 src/ao_flight_test src/ao_gps_test diff --git a/ao-tools/ao-bitbang/ao-bitbang.c b/ao-tools/ao-bitbang/ao-bitbang.c index 7090c9a3..e8dff6bf 100644 --- a/ao-tools/ao-bitbang/ao-bitbang.c +++ b/ao-tools/ao-bitbang/ao-bitbang.c @@ -23,7 +23,7 @@ main (int argc, char **argv) { struct ccdbg *dbg; - dbg = ccdbg_open(); + dbg = ccdbg_open("BITBANG"); if (!dbg) exit (1); diff --git a/ao-tools/ao-dbg/ao-dbg-main.c b/ao-tools/ao-dbg/ao-dbg-main.c index 72249a6b..f1e2c111 100644 --- a/ao-tools/ao-dbg/ao-dbg-main.c +++ b/ao-tools/ao-dbg/ao-dbg-main.c @@ -24,6 +24,7 @@ #include #include #include +#include static int s51_port = 0; static char *cpu = "8051"; @@ -32,6 +33,7 @@ char *s51_prompt = "> "; struct ccdbg *s51_dbg; int s51_interrupted = 0; int s51_monitor = 0; +char *s51_tty = NULL; static FILE *s51_input; static FILE *s51_output; @@ -48,6 +50,11 @@ void s51_sigint() s51_interrupted = 1; } +static const struct option options[] = { + { .name = "tty", .has_arg = 1, .val = 'T' }, + { 0, 0, 0, 0 }, +}; + int main(int argc, char **argv) { @@ -55,7 +62,7 @@ main(int argc, char **argv) char *endptr; struct sigvec vec, ovec; - while ((opt = getopt(argc, argv, "PVvHhmt:X:c:r:Z:s:S:p:")) != -1) { + while ((opt = getopt_long(argc, argv, "PVvHhmt:X:c:r:Z:s:S:p:T:", options, NULL)) != -1) { switch (opt) { case 't': cpu = optarg; @@ -104,6 +111,9 @@ main(int argc, char **argv) case 'm': s51_monitor = 1; break; + case 'T': + s51_tty = optarg; + break; } } if (s51_port) { diff --git a/ao-tools/ao-dbg/ao-dbg-parse.c b/ao-tools/ao-dbg/ao-dbg-parse.c index 5db6c01c..825d0e9c 100644 --- a/ao-tools/ao-dbg/ao-dbg-parse.c +++ b/ao-tools/ao-dbg/ao-dbg-parse.c @@ -195,11 +195,9 @@ command_read (void) enum command_result result; struct command_function *func; - s51_dbg = ccdbg_open (); - if (!s51_dbg) { - perror("ccdbg_open"); + s51_dbg = ccdbg_open (s51_tty); + if (!s51_dbg) exit(1); - } ccdbg_debug_mode(s51_dbg); ccdbg_halt(s51_dbg); s51_printf("Welcome to the non-simulated processor\n"); diff --git a/ao-tools/ao-dbg/ao-dbg.1 b/ao-tools/ao-dbg/ao-dbg.1 index f2f59a52..1f544e5b 100644 --- a/ao-tools/ao-dbg/ao-dbg.1 +++ b/ao-tools/ao-dbg/ao-dbg.1 @@ -34,6 +34,7 @@ s51 \- hex debugger for cc1111 processors [\-H] [\-h] [\-m] +[\-T \fItty-device\fP] .SH DESCRIPTION .I s51 connects to a cc1111 processor through a cp1203-based USB-to-serial @@ -78,6 +79,9 @@ This should print a usage message, but does nothing useful currently. .IP "\-m" This option is not present in the original 8051 emulator, and causes s51 to dump all commands and replies that are received from and sent to sdcdb. +.IP "\-T" +This selects which tty device the debugger uses to communicate with +the target device. .SH COMMANDS Once started, s51 connects to the cc1111 via the CP2103 using libusb2 and then reads and executes commands, either from stdin, or the nework diff --git a/ao-tools/ao-dbg/ao-dbg.h b/ao-tools/ao-dbg/ao-dbg.h index f4dcce66..c1789d10 100644 --- a/ao-tools/ao-dbg/ao-dbg.h +++ b/ao-tools/ao-dbg/ao-dbg.h @@ -22,6 +22,7 @@ extern char *s51_prompt; extern struct ccdbg *s51_dbg; extern int s51_interrupted; extern int s51_monitor; +extern char *s51_tty; enum command_result { command_success, command_debug, command_syntax, command_interrupt, command_error, diff --git a/ao-tools/ao-eeprom/ao-eeprom.c b/ao-tools/ao-eeprom/ao-eeprom.c index 399732d9..726cc22c 100644 --- a/ao-tools/ao-eeprom/ao-eeprom.c +++ b/ao-tools/ao-eeprom/ao-eeprom.c @@ -18,10 +18,23 @@ #include #include +#include +#include #include "cc-usb.h" #define NUM_BLOCK 512 +static const struct option options[] = { + { .name = "tty", .has_arg = 1, .val = 'T' }, + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s [--tty ]\n", program); + exit(1); +} + int main (int argc, char **argv) { @@ -31,10 +44,26 @@ main (int argc, char **argv) uint8_t *b; int i, j; uint32_t addr; - char *tty; + char *tty = NULL; + int c; - tty = getenv("CCDBG_TTY"); + while ((c = getopt_long(argc, argv, "T:", options, NULL)) != -1) { + switch (c) { + case 'T': + tty = optarg; + break; + default: + usage(argv[0]); + break; + } + } + if (!tty) + tty = getenv("ALTOS_TTY"); + if (!tty) + tty="/dev/ttyACM0"; cc = cc_usb_open(tty); + if (!cc) + exit(1); for (block = 0; block < NUM_BLOCK; block++) { cc_queue_read(cc, bytes, sizeof (bytes)); cc_usb_printf(cc, "e %x\n", block); diff --git a/ao-tools/ao-load/ao-load.c b/ao-tools/ao-load/ao-load.c index b84a88a6..c27fcbe9 100644 --- a/ao-tools/ao-load/ao-load.c +++ b/ao-tools/ao-load/ao-load.c @@ -19,17 +19,12 @@ #include #include #include +#include +#include #include "ccdbg.h" #define AO_USB_DESC_STRING 3 -void -usage(char *program) -{ - fprintf(stderr, "usage: %s \n", program); - exit(1); -} - struct sym { unsigned addr; char *name; @@ -94,6 +89,17 @@ rewrite(struct hex_image *image, unsigned addr, char *data, int len) memcpy(image->data + addr - image->address, data, len); } +static const struct option options[] = { + { .name = "tty", .has_arg = 1, .val = 'T' }, + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s [--tty ] file.ihx serial-number\n", program); + exit(1); +} + int main (int argc, char **argv) { @@ -102,12 +108,12 @@ main (int argc, char **argv) uint16_t pc; struct hex_file *hex; struct hex_image *image; - char *filename; - FILE *file; - FILE *map; - char *serial_string; - unsigned int serial; - char *mapname, *dot; + char *filename; + FILE *file; + FILE *map; + char *serial_string; + unsigned int serial; + char *mapname, *dot; char *serial_ucs2; int serial_ucs2_len; char serial_int[2]; @@ -115,8 +121,20 @@ main (int argc, char **argv) int i; unsigned usb_descriptors; int string_num; - - filename = argv[1]; + char *tty = NULL; + int c; + + while ((c = getopt_long(argc, argv, "T:", options, NULL)) != -1) { + switch (c) { + case 'T': + tty = optarg; + break; + default: + usage(argv[0]); + break; + } + } + filename = argv[optind]; if (filename == NULL) usage(argv[0]); mapname = strdup(filename); @@ -125,7 +143,7 @@ main (int argc, char **argv) usage(argv[0]); strcpy(dot, ".map"); - serial_string = argv[2]; + serial_string = argv[optind + 1]; if (serial_string == NULL) usage(argv[0]); @@ -160,7 +178,7 @@ main (int argc, char **argv) serial = strtoul(serial_string, NULL, 0); if (!serial) - usage(argv[0]); +(argv[0]); serial_int[0] = serial & 0xff; serial_int[1] = (serial >> 8) & 0xff; @@ -201,7 +219,7 @@ main (int argc, char **argv) if (!rewrite(image, usb_descriptors + 2 + image->address, serial_ucs2, serial_ucs2_len)) usage(argv[0]); - dbg = ccdbg_open(); + dbg = ccdbg_open(tty); if (!dbg) exit (1); diff --git a/ao-tools/ao-rawload/ao-rawload.c b/ao-tools/ao-rawload/ao-rawload.c index 5f7708fd..1f1537b9 100644 --- a/ao-tools/ao-rawload/ao-rawload.c +++ b/ao-tools/ao-rawload/ao-rawload.c @@ -16,8 +16,21 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include +#include #include "ccdbg.h" +static const struct option options[] = { + { .name = "tty", .has_arg = 1, .val = 'T' }, + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s [--tty ] file.ihx\n", program); + exit(1); +} + int main (int argc, char **argv) { @@ -26,10 +39,22 @@ main (int argc, char **argv) uint16_t pc; struct hex_file *hex; struct hex_image *image; - char *filename; - FILE *file; + char *filename; + FILE *file; + char *tty = NULL; + int c; - filename = argv[1]; + while ((c = getopt_long(argc, argv, "T:", options, NULL)) != -1) { + switch (c) { + case 'T': + tty = optarg; + break; + default: + usage(argv[0]); + break; + } + } + filename = argv[optind]; if (filename == NULL) { fprintf(stderr, "usage: %s \n", argv[0]); exit(1); @@ -50,7 +75,7 @@ main (int argc, char **argv) } ccdbg_hex_file_free(hex); - dbg = ccdbg_open(); + dbg = ccdbg_open(tty); if (!dbg) exit (1); diff --git a/ao-tools/lib/ccdbg-io.c b/ao-tools/lib/ccdbg-io.c index 9c6693cd..d3f87274 100644 --- a/ao-tools/lib/ccdbg-io.c +++ b/ao-tools/lib/ccdbg-io.c @@ -22,25 +22,32 @@ #include "cc-bitbang.h" struct ccdbg * -ccdbg_open(void) +ccdbg_open(char *tty) { struct ccdbg *dbg; - char *tty; dbg = calloc(sizeof (struct ccdbg), 1); if (!dbg) { perror("calloc"); return NULL; } - tty = getenv("CCDBG_TTY"); - if (!tty || tty[0] == '/') - dbg->usb = cc_usb_open(tty); - if (!dbg->usb) { + if (!tty) + tty = getenv("ALTOS_TTY"); + if (!tty) + tty="/dev/ttyACM0"; + + if (!strcmp(tty, "BITBANG")) { dbg->bb = cc_bitbang_open(); if (!dbg->bb) { free(dbg); return NULL; } + } else { + dbg->usb = cc_usb_open(tty); + if (!dbg->usb) { + free(dbg); + return NULL; + } } return dbg; } diff --git a/ao-tools/lib/ccdbg.h b/ao-tools/lib/ccdbg.h index 4a2e3b9f..ca596143 100644 --- a/ao-tools/lib/ccdbg.h +++ b/ao-tools/lib/ccdbg.h @@ -258,7 +258,7 @@ ccdbg_hex_image_equal(struct hex_image *a, struct hex_image *b); /* ccdbg-io.c */ struct ccdbg * -ccdbg_open(void); +ccdbg_open(char *tty); void ccdbg_close(struct ccdbg *dbg); diff --git a/ao-tools/lib/cp-usb-async.c b/ao-tools/lib/cp-usb-async.c index 6539394b..3e75b507 100644 --- a/ao-tools/lib/cp-usb-async.c +++ b/ao-tools/lib/cp-usb-async.c @@ -60,6 +60,7 @@ cp_usb_async_open(void) 0x10c4, 0xea60); cp->ack = -1; if (!cp->handle) { + fprintf(stderr, "Cannot find USB device 10c4:ea60\n"); libusb_exit(cp->ctx); free(cp); return NULL; diff --git a/ao-view/aoview.glade b/ao-view/aoview.glade index df08b83c..3481a779 100644 --- a/ao-view/aoview.glade +++ b/ao-view/aoview.glade @@ -651,7 +651,6 @@ You should have received a copy of the GNU General Public License along with AoV normal True aoview - False close Saving EEPROM data as <filename> diff --git a/ao-view/aoview.h b/ao-view/aoview.h index 62d0640b..e8334e5b 100644 --- a/ao-view/aoview.h +++ b/ao-view/aoview.h @@ -308,4 +308,8 @@ aoview_flite_start(void); void aoview_flite_stop(void); +/* aoview_main.c */ + +extern char *aoview_tty; + #endif /* _AOVIEW_H_ */ diff --git a/ao-view/aoview_main.c b/ao-view/aoview_main.c index 36a82e0e..64c1c027 100644 --- a/ao-view/aoview_main.c +++ b/ao-view/aoview_main.c @@ -32,29 +32,29 @@ static void destroy_event(GtkWidget *widget, gpointer data) } extern int _Xdebug; +char *aoview_tty = NULL; int main(int argc, char **argv) { GladeXML *xml = NULL; GtkWidget *mainwindow; - char *device = NULL; GtkAboutDialog *about_dialog; static struct option long_options[] = { - { "device", 1, 0, 'd'}, + { "tty", 1, 0, 'T'}, { "sync", 0, 0, 's'}, { 0, 0, 0, 0 } }; for (;;) { int c, temp; - c = getopt_long_only(argc, argv, "sd:", long_options, &temp); + c = getopt_long_only(argc, argv, "sT:", long_options, &temp); if (c == -1) break; switch (c) { - case 'd': - device = optarg; + case 'T': + aoview_tty = optarg; break; case 's': _Xdebug = 1; @@ -102,6 +102,12 @@ int main(int argc, char **argv) aoview_label_init(xml); + if (aoview_tty) { + if (!aoview_monitor_connect(aoview_tty)) { + perror(aoview_tty); + exit(1); + } + } aoview_voice_speak("rocket flight monitor ready\n"); gtk_main(); -- cgit v1.2.3