From fa813bcb6afc851cf4029b56c19ba46a3ae578f5 Mon Sep 17 00:00:00 2001 From: Tom Marble Date: Mon, 9 Feb 2015 08:35:24 -0600 Subject: Minor typo in man page --- ao-tools/ao-usbtrng/ao-usbtrng.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-usbtrng/ao-usbtrng.1 b/ao-tools/ao-usbtrng/ao-usbtrng.1 index 7a1311b9..b4a3e5ec 100644 --- a/ao-tools/ao-usbtrng/ao-usbtrng.1 +++ b/ao-tools/ao-usbtrng/ao-usbtrng.1 @@ -16,7 +16,7 @@ .\" 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. .\" .\" -.TH AO-LOAD 1 "ao-usbtrng" "" +.TH AO-USBTRNG 1 "ao-usbtrng" "" .SH NAME ao-usbtrng \- dump random numbers from USBtrng .SH SYNOPSIS -- cgit v1.2.3 From 1445725b983134d5a967dee88ef997bf15d4a422 Mon Sep 17 00:00:00 2001 From: Tom Marble Date: Wed, 11 Feb 2015 08:21:27 -0600 Subject: Added continuous output option to ao-usbtrng --- ao-tools/ao-usbtrng/ao-usbtrng.1 | 20 +++++++++--------- ao-tools/ao-usbtrng/ao-usbtrng.c | 44 ++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-usbtrng/ao-usbtrng.1 b/ao-tools/ao-usbtrng/ao-usbtrng.1 index b4a3e5ec..eabdd8a1 100644 --- a/ao-tools/ao-usbtrng/ao-usbtrng.1 +++ b/ao-tools/ao-usbtrng/ao-usbtrng.1 @@ -20,24 +20,24 @@ .SH NAME ao-usbtrng \- dump random numbers from USBtrng .SH SYNOPSIS -.B "ao-usbtrng" -[\-T \fItty-device\fP] -[\--tty \fItty-device\fP] -[\-D \fIaltos-device\fP] -[\--device \fIaltos-device\fP] -\fIkbytes\fP +.B "ao-usbtrng" [OPTION...] [KBYTES] .SH DESCRIPTION .I ao-usbtrng -dumps random numbers from a USBtrng device +dumps random numbers from a USBtrng device. If provided KBYTES specifies the number of 1024 byte blocks to produce on standard output. Without KBYTES +.I ao-usbtrng +produces random bytes continuously until killed. .SH OPTIONS .TP -\-T tty-device | --tty tty-device +\-v, --verbose +increase verbosity +.TP +\-T, -tty=TTYDEVICE 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 +\-D, --device=ALTOSDEVICE Search for a connected device. This requires an argument of one of the following forms: .IP @@ -52,7 +52,7 @@ product, leaving out the serial number will cause the tool to match one of the available devices. .SH USAGE .I ao-usbtrng -opens the target device and reads the specified number of kbytes of +opens the target device and reads the specified number of KBYTES of random data. .SH AUTHOR Keith Packard diff --git a/ao-tools/ao-usbtrng/ao-usbtrng.c b/ao-tools/ao-usbtrng/ao-usbtrng.c index 232f4e3e..456885d9 100644 --- a/ao-tools/ao-usbtrng/ao-usbtrng.c +++ b/ao-tools/ao-usbtrng/ao-usbtrng.c @@ -35,14 +35,13 @@ static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, - { .name = "raw", .has_arg = 0, .val = 'r' }, - { .name = "verbose", .has_arg = 1, .val = 'v' }, + { .name = "verbose", .has_arg = 0, .val = 'v' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--verbose=] [--device=] [-tty=] \n", program); + fprintf(stderr, "usage: %s [--verbose] [--device=] [-tty=] []\n", program); exit(1); } @@ -58,21 +57,17 @@ main (int argc, char **argv) { char *device = NULL; char *filename; - Elf *e; - unsigned int s; int i; int c; - int tries; struct cc_usb *cc = NULL; char *tty = NULL; - int success; int verbose = 0; int ret = 0; - int expected_size; - int kbytes; + int kbytes = 0; /* 0 == continuous */ + int written; uint8_t bits[1024]; - while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "vT:D:", options, NULL)) != -1) { switch (c) { case 'T': tty = optarg; @@ -89,12 +84,8 @@ main (int argc, char **argv) } } - if (!argv[optind]) - usage(argv[0]); - - kbytes = atoi(argv[optind]); - if (kbytes < 1) - kbytes = 1; + if (optind < argc) + kbytes = atoi(argv[optind]); ao_verbose = verbose; @@ -113,13 +104,22 @@ main (int argc, char **argv) if (!cc) exit(1); - cc_usb_printf(cc, "f %d\n", kbytes); + if (kbytes) { + cc_usb_printf(cc, "f %d\n", kbytes); - while (kbytes--) { - int i; - for (i = 0; i < 1024; i++) - bits[i] = cc_usb_getchar(cc); - write(1, bits, 1024); + while (kbytes--) { + for (i = 0; i < 1024; i++) + bits[i] = cc_usb_getchar(cc); + write(1, bits, 1024); + } + } else { /* 0 == continuous */ + written = 0; + while (written >= 0) { + cc_usb_printf(cc, "f 1\n"); + for (i = 0; i < 1024; i++) + bits[i] = cc_usb_getchar(cc); + written = write(1, bits, 1024); + } } done(cc, ret); -- cgit v1.2.3 From 112f528755b6c8a2f6eef3bfec21fac981ffb44f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 2 Mar 2015 21:08:44 -0800 Subject: ao-tools: Add ao-flash-stm32f0x This new script uses openocd to flash stm32f0x parts Signed-off-by: Keith Packard --- ao-tools/ao-flash/Makefile.am | 4 ++-- ao-tools/ao-flash/ao-flash-stm32f0x | 16 ++++++++++++++++ ao-tools/ao-flash/ao-flash-stm32f0x.1 | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100755 ao-tools/ao-flash/ao-flash-stm32f0x create mode 100644 ao-tools/ao-flash/ao-flash-stm32f0x.1 (limited to 'ao-tools') diff --git a/ao-tools/ao-flash/Makefile.am b/ao-tools/ao-flash/Makefile.am index 6b7ea6bb..4231dc21 100644 --- a/ao-tools/ao-flash/Makefile.am +++ b/ao-tools/ao-flash/Makefile.am @@ -1,3 +1,3 @@ -bin_SCRIPTS=ao-flash-stm ao-flash-lpc +bin_SCRIPTS=ao-flash-stm ao-flash-lpc ao-flash-stm32f0x -man_MANS = ao-flash-stm.1 ao-flash-lpc.1 \ No newline at end of file +man_MANS = ao-flash-stm.1 ao-flash-lpc.1 ao-flash-stm32f0x.1 diff --git a/ao-tools/ao-flash/ao-flash-stm32f0x b/ao-tools/ao-flash/ao-flash-stm32f0x new file mode 100755 index 00000000..45643a4f --- /dev/null +++ b/ao-tools/ao-flash/ao-flash-stm32f0x @@ -0,0 +1,16 @@ +#!/bin/sh +case "$#" in +0) + echo "usage: $0 ..." + exit 1 + ;; +esac +cmds=/tmp/flash$$ +trap "rm $cmds" 0 1 15 +file="$1" +echo "program $file verify reset" > $cmds +openocd \ + -f interface/stlink-v2.cfg \ + -f target/stm32f0x_stlink.cfg \ + -f $cmds \ + -c shutdown diff --git a/ao-tools/ao-flash/ao-flash-stm32f0x.1 b/ao-tools/ao-flash/ao-flash-stm32f0x.1 new file mode 100644 index 00000000..07ff5b59 --- /dev/null +++ b/ao-tools/ao-flash/ao-flash-stm32f0x.1 @@ -0,0 +1,36 @@ +.\" +.\" Copyright © 2013 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. +.\" +.\" +.TH AO-FLASH-LPC 1 "ao-flash-stm32f0x" "" +.SH NAME +ao-flash-stm32f0x \- flash a program to a STM32F0x-based AltOS device using openocd +.SH SYNOPSIS +.B "ao-flash-stm32f0x" +\fIfile.elf\fP +.SH DESCRIPTION +.I ao-flash-stm32f0x +loads the specified .elf file into the target device flash memory. +.SH USAGE +.I ao-flash-stm32f0x +is a simple script that passes the correct arguments to openocd to +load a file into the target device via a connected STlink +debugging dongle. +.SH "SEE ALSO" +openocd(1) +.SH AUTHOR +Keith Packard -- cgit v1.2.3 From 46f2a759dc21ebf3a7bf7e0566903fc1e7364719 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 10 Mar 2015 09:30:53 -0600 Subject: ao-tools/ao-mega: Clean up formatting of pyro status messages There was an extra newline and missing space. Signed-off-by: Keith Packard --- ao-tools/ao-mega/ao-mega.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-mega/ao-mega.c b/ao-tools/ao-mega/ao-mega.c index 523229e6..cfb58bb4 100644 --- a/ao-tools/ao-mega/ao-mega.c +++ b/ao-tools/ao-mega/ao-mega.c @@ -85,7 +85,7 @@ main (int argc, char **argv) if (cc_mega_parse(line, &log)) { if (log.is_config) { - printf ("kind %d\n", log.u.config_int.kind); + printf ("config %2d %s", log.u.config_int.kind, line); } else { printf ("tick %5d ", log.tick); switch (log.type) { @@ -126,8 +126,7 @@ main (int argc, char **argv) printf (" s%d %6d", j, log.u.volt.sense[j]); } - printf ("pyro %04x\n", log.u.volt.pyro); - printf ("\n"); + printf (" pyro %04x\n", log.u.volt.pyro); break; default: printf ("type %c\n", log.type, log.tick); -- cgit v1.2.3 From fce4e6926de7cb5ef6ea64a8db134c442b86153b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 10 Mar 2015 09:35:02 -0600 Subject: ao-tools/ao-list: Show devices that have no TTY chaoskey doesn't advertise itself as a modem, so the kernel doesn't allocate a tty device. Signed-off-by: Keith Packard --- ao-tools/ao-list/ao-list.c | 4 ++-- ao-tools/lib/cc-usbdev.c | 6 +++--- ao-tools/lib/cc.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-list/ao-list.c b/ao-tools/ao-list/ao-list.c index c4b43d8f..4c065e79 100644 --- a/ao-tools/ao-list/ao-list.c +++ b/ao-tools/ao-list/ao-list.c @@ -28,12 +28,12 @@ main (int argc, char **argv) struct cc_usbdev *dev; int i; - devs = cc_usbdevs_scan(); + devs = cc_usbdevs_scan(TRUE); if (devs) { for (i = 0; i < devs->ndev; i++) { dev = devs->dev[i]; printf ("%-20.20s %6d %s\n", - dev->product, dev->serial, dev->tty); + dev->product, dev->serial, dev->tty ? dev->tty : "(none)"); } cc_usbdevs_free(devs); } diff --git a/ao-tools/lib/cc-usbdev.c b/ao-tools/lib/cc-usbdev.c index 95bfa244..6c3ba591 100644 --- a/ao-tools/lib/cc-usbdev.c +++ b/ao-tools/lib/cc-usbdev.c @@ -219,7 +219,7 @@ is_am(int idVendor, int idProduct) { } struct cc_usbdevs * -cc_usbdevs_scan(void) +cc_usbdevs_scan(int non_tty) { int e; struct dirent **ents; @@ -241,7 +241,7 @@ cc_usbdevs_scan(void) dir = cc_fullname(USB_DEVICES, ents[e]->d_name); dev = usb_scan_device(dir); free(dir); - if (is_am(dev->idVendor, dev->idProduct) && dev->tty) { + if (is_am(dev->idVendor, dev->idProduct) && (non_tty || dev->tty)) { if (devs->dev) devs->dev = realloc(devs->dev, (devs->ndev + 1) * sizeof (struct usbdev *)); @@ -274,7 +274,7 @@ match_dev(char *product, int serial) int i; char *tty = NULL; - devs = cc_usbdevs_scan(); + devs = cc_usbdevs_scan(FALSE); if (!devs) return NULL; for (i = 0; i < devs->ndev; i++) { diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index bff4b2c9..ff95e4fc 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -50,7 +50,7 @@ void cc_usbdevs_free(struct cc_usbdevs *usbdevs); struct cc_usbdevs * -cc_usbdevs_scan(void); +cc_usbdevs_scan(int non_tty); char * cc_usbdevs_find_by_arg(char *arg, char *default_product); -- cgit v1.2.3 From b67e6ae8ce34ef119da96b442776bb3d78b4f874 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 19 May 2015 10:14:43 -0700 Subject: ao-dump-up: Add --wait option to make testing µPusb easier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The --wait option hangs around until a suitable device appears, so that you can test a pile of µPusb devices without needing to constantly interact with the command line. Signed-off-by: Keith Packard --- ao-tools/ao-dump-up/ao-dump-up.c | 28 +++++++++++++++++++++++----- ao-tools/lib/cc-usb.c | 4 +++- 2 files changed, 26 insertions(+), 6 deletions(-) (limited to 'ao-tools') diff --git a/ao-tools/ao-dump-up/ao-dump-up.c b/ao-tools/ao-dump-up/ao-dump-up.c index 6268dc8b..b1f85af6 100644 --- a/ao-tools/ao-dump-up/ao-dump-up.c +++ b/ao-tools/ao-dump-up/ao-dump-up.c @@ -29,12 +29,13 @@ static const struct option options[] = { { .name = "tty", .has_arg = 1, .val = 'T' }, { .name = "device", .has_arg = 1, .val = 'D' }, + { .name = "wait", .has_arg = 0, .val = 'w' }, { 0, 0, 0, 0}, }; static void usage(char *program) { - fprintf(stderr, "usage: %s [--tty ] [--device ]\n", program); + fprintf(stderr, "usage: %s [--tty ] [--device ] [--wait]\n", program); exit(1); } @@ -134,7 +135,7 @@ static int swap16(int i) static int find_header(struct cc_usb *cc) { for (;;) { - if (get_nonwhite(cc, 0) == 'M' && get_nonwhite(cc, 1000) == 'P') + if (get_nonwhite(cc, -1) == 'M' && get_nonwhite(cc, 1000) == 'P') return 1; } } @@ -165,9 +166,13 @@ main (int argc, char **argv) int i; int crc; int current_crc; + int wait = 0; - while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "wT:D:", options, NULL)) != -1) { switch (c) { + case 'w': + wait = 1; + break; case 'T': tty = optarg; break; @@ -179,8 +184,21 @@ main (int argc, char **argv) break; } } - if (!tty) - tty = cc_usbdevs_find_by_arg(device, "FT230X Basic UART"); + if (!tty) { + for (;;) { + tty = cc_usbdevs_find_by_arg(device, "FT230X Basic UART"); + if (tty) { + if (wait) { + printf("tty is %s\n", tty); + sleep(1); + } + break; + } + if (!wait) + break; + sleep(1); + } + } if (!tty) tty = getenv("ALTOS_TTY"); if (!tty) diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c index 1a4dc7a1..1e023c7e 100644 --- a/ao-tools/lib/cc-usb.c +++ b/ao-tools/lib/cc-usb.c @@ -207,8 +207,10 @@ _cc_usb_sync(struct cc_usb *cc, int wait_for_input, int write_timeout) write(2, cc->in_buf, cc->in_count); cc->in_count = 0; } - } else if (ret < 0) + } else if (ret <= 0) { perror("read"); + return -1; + } } if (fds.revents & POLLOUT) { ret = write(cc->fd, cc->out_buf, -- cgit v1.2.3 From b9797aa9b6ca38db79c22e4dcefc6efc8a148599 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 5 Jun 2015 22:17:02 -0700 Subject: ao-tools: Create ao-cal-freq Create C-based frequency calibration program to replace shell script which isn't reliable. Signed-off-by: Keith Packard --- ao-tools/Makefile.am | 3 +- ao-tools/ao-cal-freq/.gitignore | 1 + ao-tools/ao-cal-freq/Makefile.am | 11 ++ ao-tools/ao-cal-freq/ao-cal-freq.c | 280 +++++++++++++++++++++++++++++++++++++ configure.ac | 1 + 5 files changed, 295 insertions(+), 1 deletion(-) create mode 100644 ao-tools/ao-cal-freq/.gitignore create mode 100644 ao-tools/ao-cal-freq/Makefile.am create mode 100644 ao-tools/ao-cal-freq/ao-cal-freq.c (limited to 'ao-tools') diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 6a170cbd..66d2560e 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -2,7 +2,8 @@ SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list \ ao-load ao-telem ao-send-telem ao-sky-flash \ ao-dumpflash ao-edit-telem ao-dump-up ao-elftohex \ ao-flash ao-usbload ao-test-igniter ao-test-baro \ - ao-test-flash ao-cal-accel ao-test-gps ao-usbtrng + ao-test-flash ao-cal-accel ao-test-gps ao-usbtrng \ + ao-cal-freq if LIBSTLINK SUBDIRS += ao-stmload endif diff --git a/ao-tools/ao-cal-freq/.gitignore b/ao-tools/ao-cal-freq/.gitignore new file mode 100644 index 00000000..4fe14865 --- /dev/null +++ b/ao-tools/ao-cal-freq/.gitignore @@ -0,0 +1 @@ +ao-cal-freq diff --git a/ao-tools/ao-cal-freq/Makefile.am b/ao-tools/ao-cal-freq/Makefile.am new file mode 100644 index 00000000..e11c2b0a --- /dev/null +++ b/ao-tools/ao-cal-freq/Makefile.am @@ -0,0 +1,11 @@ +bin_PROGRAMS=ao-cal-freq + +AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS) + +ao_cal_freq_DEPENDENCIES = $(top_builddir)/ao-tools/lib/libao-tools.a + +ao_cal_freq_LDADD=$(top_builddir)/ao-tools/lib/libao-tools.a $(LIBUSB_LIBS) -lm + +ao_cal_freq_SOURCES=ao-cal-freq.c + +man_MANS = ao-cal-freq.1 diff --git a/ao-tools/ao-cal-freq/ao-cal-freq.c b/ao-tools/ao-cal-freq/ao-cal-freq.c new file mode 100644 index 00000000..464faf0f --- /dev/null +++ b/ao-tools/ao-cal-freq/ao-cal-freq.c @@ -0,0 +1,280 @@ +/* + * Copyright © 2014 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; version 2 of the License. + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ao-elf.h" +#include "ccdbg.h" +#include "cc-usb.h" +#include "cc.h" +#include "ao-verbose.h" + +static const struct option options[] = { + { .name = "tty", .has_arg = 1, .val = 'T' }, + { .name = "device", .has_arg = 1, .val = 'D' }, + { .name = "raw", .has_arg = 0, .val = 'r' }, + { .name = "verbose", .has_arg = 1, .val = 'v' }, + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s [--verbose=] [--device=] [-tty=]\n", program); + exit(1); +} + +void +done(struct cc_usb *cc, int code) +{ + cc_usb_close(cc); + exit (code); +} + +static int +ends_with(char *whole, char *suffix) +{ + int whole_len = strlen(whole); + int suffix_len = strlen(suffix); + + if (suffix_len > whole_len) + return 0; + return strcmp(whole + whole_len - suffix_len, suffix) == 0; +} + +static int +starts_with(char *whole, char *prefix) +{ + int whole_len = strlen(whole); + int prefix_len = strlen(prefix); + + if (prefix_len > whole_len) + return 0; + return strncmp(whole, prefix, prefix_len) == 0; +} + +static char ** +tok(char *line) { + char **strs = malloc (sizeof (char *)), *str; + int n = 0; + + while ((str = strtok(line, " \t"))) { + line = NULL; + strs = realloc(strs, (n + 2) * sizeof (char *)); + strs[n] = strdup(str); + n++; + } + strs[n] = '\0'; + return strs; +} + +static void +free_strs(char **strs) { + char *str; + int i; + + for (i = 0; (str = strs[i]) != NULL; i++) + free(str); + free(strs); +} + +struct flash { + struct flash *next; + char line[512]; + char **strs; +}; + +static struct flash * +flash(struct cc_usb *usb) +{ + struct flash *head = NULL, **tail = &head; + cc_usb_printf(usb, "c s\nv\n"); + for (;;) { + char line[512]; + struct flash *b; + + cc_usb_getline(usb, line, sizeof (line)); + b = malloc (sizeof (struct flash)); + strcpy(b->line, line); + b->strs = tok(line); + b->next = NULL; + *tail = b; + tail = &b->next; + if (strstr(line, "software-version")) + break; + } + return head; +} + +static void +free_flash(struct flash *b) { + struct flash *n; + + while (b) { + n = b->next; + free_strs(b->strs); + free(b); + b = n; + } +} + +char ** +find_flash(struct flash *b, char *word0) { + int i; + for (;b; b = b->next) { + if (strstr(b->line, word0)) + return b->strs; + } + return NULL; +} + +void +await_key(void) +{ + struct termios termios, termios_save; + char buf[512]; + + tcgetattr(0, &termios); + termios_save = termios; + cfmakeraw(&termios); + tcsetattr(0, TCSAFLUSH, &termios); + read(0, buf, sizeof (buf)); + tcsetattr(0, TCSAFLUSH, &termios_save); +} + +int +do_cal(struct cc_usb *usb) { + struct flash *b; + char line[1024]; + double measured_freq; + char **cur_freq_words; + char **cur_cal_words; + char *line_end; + int cur_freq; + int cur_cal; + int new_cal; + + cc_usb_printf(usb, "E 0\n"); + + for(;;) { + cc_usb_printf(usb, "C 1\n"); + cc_usb_sync(usb); + + printf("Generating RF carrier. Please enter measured frequency [enter for done]: "); + fflush(stdout); + fgets(line, sizeof (line) - 1, stdin); + cc_usb_printf(usb, "C 0\n"); + cc_usb_sync(usb); + + measured_freq = strtod(line, &line_end); + if (line_end == line) + break; + + b = flash(usb); + + cur_cal_words = find_flash(b, "Radio cal:"); + cur_freq_words = find_flash(b, "Frequency:"); + + if (!cur_cal_words || !cur_freq_words) { + printf("no response\n"); + return 0; + } + + cur_cal = atoi(cur_cal_words[2]); + cur_freq = atoi(cur_freq_words[1]); + + printf ("Current radio calibration %d\n", cur_cal); + printf ("Current radio frequency: %d\n", cur_freq); + + + new_cal = floor ((((double) cur_freq / 1000.0) / measured_freq) * cur_cal + 0.5); + + printf ("Programming flash with cal value %d\n", new_cal); + + cc_usb_printf (usb, "c f %d\nc w\n", new_cal); + cc_usb_sync(usb); + } + return 1; +} + +int +main (int argc, char **argv) +{ + char *device = NULL; + char *filename; + Elf *e; + unsigned int s; + int i; + int c; + int tries; + struct cc_usb *cc = NULL; + char *tty = NULL; + int success; + int verbose = 0; + int ret = 0; + int expected_size; + + while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) { + switch (c) { + case 'T': + tty = optarg; + break; + case 'D': + device = optarg; + break; + case 'v': + verbose++; + break; + default: + usage(argv[0]); + break; + } + } + + ao_verbose = verbose; + + if (verbose > 1) + ccdbg_add_debug(CC_DEBUG_BITBANG); + + if (!tty) + tty = cc_usbdevs_find_by_arg(device, "AltosFlash"); + if (!tty) + tty = cc_usbdevs_find_by_arg(device, "TeleMega"); + if (!tty) + tty = getenv("ALTOS_TTY"); + if (!tty) + tty="/dev/ttyACM0"; + + cc = cc_usb_open(tty); + + if (!cc) + exit(1); + + if (!do_cal(cc)) + ret = 1; + done(cc, ret); +} diff --git a/configure.ac b/configure.ac index d7a14aa8..e0d5f422 100644 --- a/configure.ac +++ b/configure.ac @@ -551,6 +551,7 @@ ao-tools/ao-test-igniter/Makefile ao-tools/ao-test-baro/Makefile ao-tools/ao-test-flash/Makefile ao-tools/ao-cal-accel/Makefile +ao-tools/ao-cal-freq/Makefile ao-tools/ao-test-gps/Makefile ao-tools/ao-usbtrng/Makefile ao-utils/Makefile -- cgit v1.2.3 From 64ca3d2e7d2b23aedfdf98ef8ebd760bd3291534 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 6 Jun 2015 06:00:43 -0700 Subject: ao-tools: Add missing ao-cal-freq man page Signed-off-by: Keith Packard --- ao-tools/ao-cal-freq/ao-cal-freq.1 | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ao-tools/ao-cal-freq/ao-cal-freq.1 (limited to 'ao-tools') diff --git a/ao-tools/ao-cal-freq/ao-cal-freq.1 b/ao-tools/ao-cal-freq/ao-cal-freq.1 new file mode 100644 index 00000000..bfc3101c --- /dev/null +++ b/ao-tools/ao-cal-freq/ao-cal-freq.1 @@ -0,0 +1,58 @@ +.\" +.\" Copyright © 2009 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. +.\" +.\" +.TH AO-LOAD 1 "ao-cal-freq" "" +.SH NAME +ao-cal-freq \- Calibrate AltOS flight computer frequency +.SH SYNOPSIS +.B "ao-cal-freq" +[\-T \fItty-device\fP] +[\--tty \fItty-device\fP] +[\-D \fIaltos-device\fP] +[\--device \fIaltos-device\fP] +.SH DESCRIPTION +.I ao-cal-freq +drives the frequency calibration process and saves the result. +.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 +TeleMega:2 +.br +TeleMega +.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-cal-freq +opens the target device, interactively calibrates the frequency, then +shows the resulting calibration values and saves them to configuration +memory. +.SH AUTHOR +Keith Packard -- cgit v1.2.3 From 6cf27ddd5e84824610d6a0bcbb81ba4626b71409 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 18 Jun 2015 17:12:41 -0700 Subject: ao-bringup: Use local versions of tools instead of /usr/bin for turnon_easymega Signed-off-by: Keith Packard --- ao-bringup/turnon_easymega | 8 ++++---- ao-tools/ao-flash/ao-flash-stm | 0 2 files changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 ao-tools/ao-flash/ao-flash-stm (limited to 'ao-tools') diff --git a/ao-bringup/turnon_easymega b/ao-bringup/turnon_easymega index 632b71e2..01546537 100755 --- a/ao-bringup/turnon_easymega +++ b/ao-bringup/turnon_easymega @@ -1,14 +1,14 @@ #!/bin/sh -if [ -x /usr/bin/ao-flash-stm ]; then - STMLOAD=/usr/bin/ao-flash-stm +if [ -x ../ao-tools/ao-flash/ao-flash-stm ]; then + STMLOAD=../ao-tools/ao-flash/ao-flash-stm else echo "Can't find ao-flash-stm! Aborting." exit 1 fi -if [ -x /usr/bin/ao-usbload ]; then - USBLOAD=/usr/bin/ao-usbload +if [ -x ../ao-tools/ao-usbload/ao-usbload ]; then + USBLOAD=../ao-tools/ao-usbload/ao-usbload else echo "Can't find ao-usbload! Aborting." exit 1 diff --git a/ao-tools/ao-flash/ao-flash-stm b/ao-tools/ao-flash/ao-flash-stm old mode 100644 new mode 100755 -- cgit v1.2.3