FreeCalypso > hg > freecalypso-hwlab
changeset 4:02ea5dbdf84b
ee2232-prog: input parsing implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 05 Apr 2018 22:30:38 +0000 |
parents | ef43bbfa8d16 |
children | a85b6b7398bc |
files | .hgignore ee2232/Makefile ee2232/ee2232-prog.c |
diffstat | 3 files changed, 100 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Thu Apr 05 21:48:05 2018 +0000 +++ b/.hgignore Thu Apr 05 22:30:38 2018 +0000 @@ -3,4 +3,5 @@ \.[oa]$ ^ee2232/ee2232-gen$ +^ee2232/ee2232-prog$ ^ee2232/ee2232-read$
--- a/ee2232/Makefile Thu Apr 05 21:48:05 2018 +0000 +++ b/ee2232/Makefile Thu Apr 05 22:30:38 2018 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -PROGS= ee2232-gen ee2232-read +PROGS= ee2232-gen ee2232-prog ee2232-read INSTBIN=/opt/freecalypso/bin all: ${PROGS} @@ -8,6 +8,9 @@ ee2232-gen: ee2232-gen.c ${CC} ${CFLAGS} -o $@ $@.c +ee2232-prog: ee2232-prog.c + ${CC} ${CFLAGS} -o $@ $@.c -lftdi + ee2232-read: ee2232-read.c ${CC} ${CFLAGS} -o $@ $@.c -lftdi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ee2232/ee2232-prog.c Thu Apr 05 22:30:38 2018 +0000 @@ -0,0 +1,95 @@ +#include <sys/types.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <ftdi.h> + +char *device_selector = "i:0x0403:0x6010"; +unsigned eeprom_size = 64; +u_short eeprom[256]; +int erase; + +process_cmdline(argc, argv) + char **argv; +{ + int c; + extern char *optarg; + + while ((c = getopt(argc, argv, "d:et:")) != EOF) { + switch (c) { + case 'd': + device_selector = optarg; + continue; + case 'e': + erase = 1; + continue; + case 't': + if (!strcmp(optarg, "46")) + eeprom_size = 64; + else if (!strcmp(optarg, "56")) + eeprom_size = 128; + else if (!strcmp(optarg, "66")) + eeprom_size = 256; + else { + fprintf(stderr, + "error: -t option invalid value \"%s\"\n", + optarg); + exit(1); + } + continue; + default: + /* error msg already printed */ + exit(1); + } + } +} + +read_eeprom_from_stdin() +{ + unsigned n, off; + int rc; + + for (n = 0; n < eeprom_size; n += 8) { + rc = scanf("%x: %hx %hx %hx %hx %hx %hx %hx %hx", &off, + eeprom + n, eeprom + n + 1, eeprom + n + 2, + eeprom + n + 3, eeprom + n + 4, eeprom + n + 5, + eeprom + n + 6, eeprom + n + 7); + if (rc != 9 || off != n * 2) { + fprintf(stderr, + "ee2232-prog error: invalid input on stdin\n"); + exit(1); + } + } +} + +test_output() +{ + unsigned n, col; + + for (n = 0; n < eeprom_size; n++) { + col = n & 7; + if (col == 0) + printf("%02X:", n * 2); + printf(" %04X", eeprom[n]); + if (col == 7) + putchar('\n'); + } +} + +main(argc, argv) + char **argv; +{ + struct ftdi_context ftdi; + + process_cmdline(argc, argv); + if (erase) + memset(eeprom, 0xFF, eeprom_size * 2); + else + read_eeprom_from_stdin(); + test_output(); + exit(0); + +}