Add --device/-D support to the command line tools and manuals
authorKeith Packard <keithp@keithp.com>
Fri, 4 Sep 2009 22:30:22 +0000 (15:30 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 4 Sep 2009 22:30:22 +0000 (15:30 -0700)
Use the new cc_usbdevs_find_by_arg function to locate suitable target
devices connected via USB.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-dbg/ao-dbg-main.c
ao-tools/ao-dbg/ao-dbg-parse.c
ao-tools/ao-dbg/ao-dbg.1
ao-tools/ao-dbg/ao-dbg.h
ao-tools/ao-eeprom/ao-eeprom.1
ao-tools/ao-load/ao-load.1
ao-tools/ao-load/ao-load.c
ao-tools/ao-rawload/ao-rawload.1
ao-tools/ao-rawload/ao-rawload.c

index f1e2c11199122a5ca4b1ca5b19a5c59fb7f839b7..21b83a3dbc2b6c01327f05fe1e72ae59111b400a 100644 (file)
@@ -34,6 +34,7 @@ struct ccdbg *s51_dbg;
 int s51_interrupted = 0;
 int s51_monitor = 0;
 char *s51_tty = NULL;
+char *s51_device = NULL;
 
 static FILE *s51_input;
 static FILE *s51_output;
@@ -52,6 +53,7 @@ void s51_sigint()
 
 static const struct option options[] = {
        { .name = "tty", .has_arg = 1, .val = 'T' },
+       { .name = "device", .has_arg = 1, .val = 'D' },
        { 0, 0, 0, 0 },
 };
 
@@ -114,6 +116,9 @@ main(int argc, char **argv)
                case 'T':
                        s51_tty = optarg;
                        break;
+               case 'D':
+                       s51_device = optarg;
+                       break;
                }
        }
        if (s51_port) {
index 825d0e9c74972d72bf809ed69c0d42e0624af89f..dcb9099df8cbe8d1742a2f877b9584bc5fa9c3a8 100644 (file)
@@ -195,6 +195,11 @@ command_read (void)
        enum command_result result;
        struct command_function *func;
 
+       if (!s51_tty) {
+               if (!s51_device)
+                       s51_device = getenv("AO_DBG_DEVICE");
+               s51_tty = cc_usbdevs_find_by_arg(s51_device, "TIDongle");
+       }
        s51_dbg = ccdbg_open (s51_tty);
        if (!s51_dbg)
                exit(1);
index a850c45407ed76b7e845c92ac2ea109bc1cee84f..00d3ac86318e24c83c21fc76e0a5c691cfab9dc6 100644 (file)
@@ -35,6 +35,9 @@ ao-dbg \- hex debugger for cc1111 processors
 [\-h]
 [\-m]
 [\-T \fItty-device\fP]
+[\--tty \fItty-device\fP]
+[\-D \fIaltos-device\fP]
+[\--device \fIaltos-device\fP]
 .SH DESCRIPTION
 .I ao-dbg
 connects to a cc1111 processor through either a suitable cc1111 board
@@ -80,11 +83,26 @@ 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 ao-dbg to
 dump all commands and replies that are received from and sent to sdcdb.
-.IP "\-T"
+.TP
+\-T tty-device | --tty tty-device
 This selects which tty device the debugger uses to communicate with
 the target device. The special name 'BITBANG' directs ao-dbg to use
 the cp2103 connection, otherwise this should be a usb serial port
 connected to a suitable cc1111 debug node.
+.TP
+\-D AltOS-device | --device AltOS-device
+Search for a connected device. This requires an argument of one of the
+following forms:
+.IP
+TeleMetrum:2
+.br
+TeleMetrum
+.br
+2
+.IP
+Leaving out the product name will cause the tool to select a suitable
+product, leaving out the serial number will cause the tool to match
+one of the available devices.
 .SH COMMANDS
 Once started, ao-dbg connects to the cc1111 and then reads and
 executes commands, either from stdin, or the nework connection to
index c1789d10e30cfb930f380c7089763b05b51fecce..edc650a506c8d99c2c2a20de7ba43443a0726b3e 100644 (file)
  */
 
 #include <ccdbg.h>
+#include <cc.h>
 
 extern char *s51_prompt;
 extern struct ccdbg *s51_dbg;
 extern int s51_interrupted;
 extern int s51_monitor;
 extern char *s51_tty;
+extern char *s51_device;
 
 enum command_result {
        command_success, command_debug, command_syntax, command_interrupt, command_error,
index 8caff9d1a1510efd51edc1fb24d8b48cf45dd3c2..ed498147fed27a007dadf0f23842539449db85e3 100644 (file)
 ao-eeprom \- Fetch eeprom contents from TeleMetrum device
 .SH SYNOPSIS
 .B "ao-eeprom"
-[\-tty \fItty-device\fP]
+[\-T \fItty-device\fP]
+[\--tty \fItty-device\fP]
+[\-D \fIaltos-device\fP]
+[\--device \fIaltos-device\fP]
+.SH OPTIONS
+.TP
+\-T tty-device | --tty tty-device
+This selects which tty device the debugger uses to communicate with
+the target device. The special name 'BITBANG' directs ao-dbg to use
+the cp2103 connection, otherwise this should be a usb serial port
+connected to a suitable cc1111 debug node.
+.TP
+\-D AltOS-device | --device AltOS-device
+Search for a connected device. This requires an argument of one of the
+following forms:
+.IP
+TeleMetrum:2
+.br
+TeleMetrum
+.br
+2
+.IP
+Leaving out the product name will cause the tool to select a suitable
+product, leaving out the serial number will cause the tool to match
+one of the available devices.
 .SH DESCRIPTION
 .I ao-eeprom
 downloads the eeprom contents from a connected TeleMetrum device.
index 10484f3bc4eb47d6d30aa1c455e3e35a445590e5..eb2bc0d8bdd5d3748d0596cc831520a182b88daa 100644 (file)
 ao-load \- flash a program to a AltOS device
 .SH SYNOPSIS
 .B "ao-load"
-[\-tty \fItty-device\fP]
+[\-T \fItty-device\fP]
+[\--tty \fItty-device\fP]
+[\-D \fIaltos-device\fP]
+[\--device \fIaltos-device\fP]
 \fIfile.ihx\fP
 \fIdevice serial number\fP
 .SH DESCRIPTION
 .I ao-load
 loads the specified .ihx file into the target device flash memory,
 customizing the AltOS image with the specified serial number.
+.SH OPTIONS
+.TP
+\-T tty-device | --tty tty-device
+This selects which tty device the debugger uses to communicate with
+the target device. The special name 'BITBANG' directs ao-dbg to use
+the cp2103 connection, otherwise this should be a usb serial port
+connected to a suitable cc1111 debug node.
+.TP
+\-D AltOS-device | --device AltOS-device
+Search for a connected device. This requires an argument of one of the
+following forms:
+.IP
+TeleMetrum:2
+.br
+TeleMetrum
+.br
+2
+.IP
+Leaving out the product name will cause the tool to select a suitable
+product, leaving out the serial number will cause the tool to match
+one of the available devices.
 .SH USAGE
 .I ao-load
 reads the specified .ihx file into memory, locates the matching .map
index c27fcbe9c4d191bcb3005f9e7d2964e2eaba3c00..f5466612c20b9a12b4def5c374008ad543b81a36 100644 (file)
@@ -22,6 +22,7 @@
 #include <unistd.h>
 #include <getopt.h>
 #include "ccdbg.h"
+#include "cc.h"
 
 #define AO_USB_DESC_STRING             3
 
@@ -91,12 +92,13 @@ rewrite(struct hex_image *image, unsigned addr, char *data, int len)
 
 static const struct option options[] = {
        { .name = "tty", .has_arg = 1, .val = 'T' },
+       { .name = "device", .has_arg = 1, .val = 'D' },
        { 0, 0, 0, 0},
 };
 
 static void usage(char *program)
 {
-       fprintf(stderr, "usage: %s [--tty <tty-name>] file.ihx serial-number\n", program);
+       fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>] file.ihx serial-number\n", program);
        exit(1);
 }
 
@@ -122,13 +124,17 @@ main (int argc, char **argv)
        unsigned        usb_descriptors;
        int             string_num;
        char            *tty = NULL;
+       char            *device = NULL;
        int             c;
 
-       while ((c = getopt_long(argc, argv, "T:", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) {
                switch (c) {
                case 'T':
                        tty = optarg;
                        break;
+               case 'D':
+                       device = optarg;
+                       break;
                default:
                        usage(argv[0]);
                        break;
@@ -219,6 +225,8 @@ main (int argc, char **argv)
        if (!rewrite(image, usb_descriptors + 2 + image->address, serial_ucs2, serial_ucs2_len))
                usage(argv[0]);
 
+       if (!tty)
+               tty = cc_usbdevs_find_by_arg(device, "TIDongle");
        dbg = ccdbg_open(tty);
        if (!dbg)
                exit (1);
index e79645f19a982653f633067474c412fadcad6ae5..6b6a6e2c7097bd9faac5e8e36ae0056a993eabfa 100644 (file)
 ao-rawload \- flash a program to a AltOS device
 .SH SYNOPSIS
 .B "ao-rawload"
-[\-tty \fItty-device\fP]
+[\-T \fItty-device\fP]
+[\--tty \fItty-device\fP]
+[\-D \fIaltos-device\fP]
+[\--device \fIaltos-device\fP]
 \fIfile.ihx\fP
 .SH DESCRIPTION
 .I ao-rawload
 loads the specified .ihx file, without modification, into the target
 device flash memory.
+.SH OPTIONS
+.TP
+\-T tty-device | --tty tty-device
+This selects which tty device the debugger uses to communicate with
+the target device. The special name 'BITBANG' directs ao-dbg to use
+the cp2103 connection, otherwise this should be a usb serial port
+connected to a suitable cc1111 debug node.
+.TP
+\-D AltOS-device | --device AltOS-device
+Search for a connected device. This requires an argument of one of the
+following forms:
+.IP
+TeleMetrum:2
+.br
+TeleMetrum
+.br
+2
+.IP
+Leaving out the product name will cause the tool to select a suitable
+product, leaving out the serial number will cause the tool to match
+one of the available devices.
 .SH USAGE
 .I ao-rawload
 reads the specified .ihx file into memory. It then connects to the
index 1f1537b9f12d59eb49f6de87c7e96ed39e7e1e1f..255f63eca2f7c99563cbd629c0bd14b969e63e1e 100644 (file)
 
 static const struct option options[] = {
        { .name = "tty", .has_arg = 1, .val = 'T' },
+       { .name = "device", .has_arg = 1, .val = 'D' },
        { 0, 0, 0, 0},
 };
 
 static void usage(char *program)
 {
-       fprintf(stderr, "usage: %s [--tty <tty-name>] file.ihx\n", program);
+       fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>] file.ihx\n", program);
        exit(1);
 }
 
@@ -42,13 +43,17 @@ main (int argc, char **argv)
        char            *filename;
        FILE            *file;
        char            *tty = NULL;
+       char            *device = NULL;
        int             c;
 
-       while ((c = getopt_long(argc, argv, "T:", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) {
                switch (c) {
                case 'T':
                        tty = optarg;
                        break;
+               case 'D':
+                       device = optarg;
+                       break;
                default:
                        usage(argv[0]);
                        break;
@@ -75,6 +80,8 @@ main (int argc, char **argv)
        }
 
        ccdbg_hex_file_free(hex);
+       if (!tty)
+               tty = cc_usbdevs_find_by_arg(device, "TIDongle");
        dbg = ccdbg_open(tty);
        if (!dbg)
                exit (1);