The branch, eeprom-new has been updated
via 05c2e40a3c720c63a75d36a33d0d5de0677f8f57 (commit)
from 56ac0383edadfa388c3af9df52f3b4c140560527 (commit)
- Log -----------------------------------------------------------------
commit 05c2e40a3c720c63a75d36a33d0d5de0677f8f57
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date: Mon Oct 4 17:49:14 2010 +0200
Reformat example code to match libftdi style:
/usr/bin/astyle --indent=spaces=4 --indent-switches --brackets=break \
--convert-tabs --one-line=keep-statements
--one-line=keep-blocks \
$*
-----------------------------------------------------------------------
Summary of changes:
examples/baud_test.c | 18 +-
examples/eeprom.c | 178 +++++++++---------
examples/serial_read.c | 41 ++--
examples/stream_test.c | 493 ++++++++++++++++++++++++------------------------
4 files changed, 366 insertions(+), 364 deletions(-)
diff --git a/examples/baud_test.c b/examples/baud_test.c
index b53031b..d8d4886 100644
--- a/examples/baud_test.c
+++ b/examples/baud_test.c
@@ -12,7 +12,7 @@
* s:<vendor>:<product>:<serial> first device with given vendor id,
product id and serial string
* -d <datasize to send in bytes>
* -b <baudrate> (divides by 16 if bitbang as taken from the ftdi datasheets)
- * -m <mode to use> r: serial a: async bitbang s:sync bitbang
+ * -m <mode to use> r: serial a: async bitbang s:sync bitbang
* -c <chunksize>
*
* (C) 2009 by Gerd v. Egidy <gerd.von.egidy@xxxxxxxxxxxxx>
@@ -39,7 +39,7 @@ double get_prec_time()
{
struct timeval tv;
double res;
-
+
gettimeofday(&tv,NULL);
res=tv.tv_sec;
@@ -65,7 +65,7 @@ int main(int argc, char **argv)
char *devicedesc=default_devicedesc;
int txchunksize=256;
enum ftdi_mpsse_mode test_mode=BITMODE_BITBANG;
-
+
while ((t = getopt (argc, argv, "b:d:p:m:c:")) != -1)
{
switch (t)
@@ -74,7 +74,7 @@ int main(int argc, char **argv)
datasize = atoi (optarg);
break;
case 'm':
- switch(*optarg)
+ switch (*optarg)
{
case 'r':
// serial
@@ -162,16 +162,16 @@ int main(int argc, char **argv)
}
if (ftdi_write_data_set_chunksize(&ftdic, txchunksize) < 0 ||
- ftdi_read_data_set_chunksize(&ftdic, txchunksize) < 0)
+ ftdi_read_data_set_chunksize(&ftdic, txchunksize) < 0)
{
fprintf(stderr,"Can't set chunksize:
%s\n",ftdi_get_error_string(&ftdic));
return EXIT_FAILURE;
}
- if(test_mode==BITMODE_SYNCBB)
+ if (test_mode==BITMODE_SYNCBB)
{
// completely clear the receive buffer before beginning
- while(ftdi_read_data(&ftdic, rxbuf, txchunksize)>0);
+ while (ftdi_read_data(&ftdic, rxbuf, txchunksize)>0);
}
start=get_prec_time();
@@ -181,7 +181,7 @@ int main(int argc, char **argv)
ftdic.usb_read_timeout=1;
i=0;
- while(i < datasize)
+ while (i < datasize)
{
int sendsize=txchunksize;
if (i+sendsize > datasize)
@@ -196,7 +196,7 @@ int main(int argc, char **argv)
i+=sendsize;
- if(test_mode==BITMODE_SYNCBB)
+ if (test_mode==BITMODE_SYNCBB)
{
// read the same amount of data as sent
ftdi_read_data(&ftdic, rxbuf, sendsize);
diff --git a/examples/eeprom.c b/examples/eeprom.c
index 3350fa3..e2c8052 100644
--- a/examples/eeprom.c
+++ b/examples/eeprom.c
@@ -29,8 +29,8 @@ int main(int argc, char **argv)
if ((ftdi = ftdi_new()) == 0)
{
- fprintf(stderr, "Failed to allocate ftdi structure :%s \n",
- ftdi_get_error_string(ftdi));
+ fprintf(stderr, "Failed to allocate ftdi structure :%s \n",
+ ftdi_get_error_string(ftdi));
return EXIT_FAILURE;
}
@@ -38,43 +38,43 @@ int main(int argc, char **argv)
{
switch (i)
{
- case 'd':
- use_defaults = 1;
- if(optarg)
- large_chip = 0x66;
- break;
- case 'e':
- erase = 1;
- break;
- case 'v':
- vid = strtoul(optarg, NULL, 0);
- break;
- case 'p':
- pid = strtoul(optarg, NULL, 0);
- break;
- case 'P':
+ case 'd':
+ use_defaults = 1;
+ if (optarg)
+ large_chip = 0x66;
+ break;
+ case 'e':
+ erase = 1;
+ break;
+ case 'v':
+ vid = strtoul(optarg, NULL, 0);
+ break;
+ case 'p':
+ pid = strtoul(optarg, NULL, 0);
+ break;
+ case 'P':
desc = optarg;
- break;
- case 'S':
- serial = optarg;
- break;
- case 'w':
- do_write = 1;
- break;
- default:
- fprintf(stderr, "usage: %s [options]\n", *argv);
- fprintf(stderr, "\t-d[num] Work with default valuesfor 128 Byte
"
+ break;
+ case 'S':
+ serial = optarg;
+ break;
+ case 'w':
+ do_write = 1;
+ break;
+ default:
+ fprintf(stderr, "usage: %s [options]\n", *argv);
+ fprintf(stderr, "\t-d[num] Work with default valuesfor 128
Byte "
"EEPROM or for 256 Byte EEPROM if some [num] is
given\n");
- fprintf(stderr, "\t-w write\n");
- fprintf(stderr, "\t-e erase\n");
- fprintf(stderr, "\t-v verbose decoding\n");
- fprintf(stderr, "\t-p <number> Search for device with PID ==
number\n");
- fprintf(stderr, "\t-v <number> Search for device with VID ==
number\n");
- fprintf(stderr, "\t-P <string? Search for device with given "
+ fprintf(stderr, "\t-w write\n");
+ fprintf(stderr, "\t-e erase\n");
+ fprintf(stderr, "\t-v verbose decoding\n");
+ fprintf(stderr, "\t-p <number> Search for device with PID ==
number\n");
+ fprintf(stderr, "\t-v <number> Search for device with VID ==
number\n");
+ fprintf(stderr, "\t-P <string? Search for device with given "
"product description\n");
- fprintf(stderr, "\t-S <string? Search for device with given "
+ fprintf(stderr, "\t-S <string? Search for device with given "
"serial number\n");
- exit(-1);
+ exit(-1);
}
}
@@ -86,13 +86,13 @@ int main(int argc, char **argv)
if (f < 0)
{
fprintf(stderr, "Device VID 0x%04x PID 0x%04x", vid, pid);
- if(desc)
+ if (desc)
fprintf(stderr, " Desc %s", desc);
- if(serial)
+ if (serial)
fprintf(stderr, " Serial %s", serial);
fprintf(stderr, "\n");
- fprintf(stderr, "unable to open ftdi device: %d (%s)\n",
- f, ftdi_get_error_string(ftdi));
+ fprintf(stderr, "unable to open ftdi device: %d (%s)\n",
+ f, ftdi_get_error_string(ftdi));
exit(-1);
}
@@ -102,15 +102,15 @@ int main(int argc, char **argv)
f = ftdi_erase_eeprom(ftdi); /* needed to determine EEPROM chip type */
if (f < 0)
{
- fprintf(stderr, "Erase failed: %s",
+ fprintf(stderr, "Erase failed: %s",
ftdi_get_error_string(ftdi));
return -2;
}
- if (ftdi_get_eeprom_value(ftdi, CHIP_TYPE, & value) <0)
- {
- fprintf(stderr, "ftdi_get_eeprom_value: %d (%s)\n",
+ if (ftdi_get_eeprom_value(ftdi, CHIP_TYPE, & value) <0)
+ {
+ fprintf(stderr, "ftdi_get_eeprom_value: %d (%s)\n",
f, ftdi_get_error_string(ftdi));
- }
+ }
if (value == -1)
fprintf(stderr, "No EEPROM\n");
else if (value == 0)
@@ -118,46 +118,46 @@ int main(int argc, char **argv)
else
fprintf(stderr, "Found 93x%02x\n", value);
return 0;
- }
+ }
- if(use_defaults)
+ if (use_defaults)
{
ftdi_eeprom_initdefaults(ftdi, "IKDA", "FTDIJTAG", "0001");
ftdi_eeprom_initdefaults(ftdi, "IKDA", "FTDIJTAG", "0001");
- if (ftdi_set_eeprom_value(ftdi, MAX_POWER, 500) <0)
- {
- fprintf(stderr, "ftdi_set_eeprom_value: %d (%s)\n",
+ if (ftdi_set_eeprom_value(ftdi, MAX_POWER, 500) <0)
+ {
+ fprintf(stderr, "ftdi_set_eeprom_value: %d (%s)\n",
f, ftdi_get_error_string(ftdi));
- }
- if (large_chip)
- if (ftdi_set_eeprom_value(ftdi, CHIP_TYPE, 0x66) <0)
- {
- fprintf(stderr, "ftdi_set_eeprom_value: %d (%s)\n",
- f, ftdi_get_error_string(ftdi));
- }
+ }
+ if (large_chip)
+ if (ftdi_set_eeprom_value(ftdi, CHIP_TYPE, 0x66) <0)
+ {
+ fprintf(stderr, "ftdi_set_eeprom_value: %d (%s)\n",
+ f, ftdi_get_error_string(ftdi));
+ }
f=(ftdi_eeprom_build(ftdi));
if (f < 0)
{
- fprintf(stderr, "ftdi_eeprom_build: %d (%s)\n",
+ fprintf(stderr, "ftdi_eeprom_build: %d (%s)\n",
f, ftdi_get_error_string(ftdi));
exit(-1);
}
}
- else if(do_write)
+ else if (do_write)
{
ftdi_eeprom_initdefaults(ftdi, "IKDA", "FTDIJTAG", "0001");
- f = ftdi_erase_eeprom(ftdi);
- if (ftdi_set_eeprom_value(ftdi, MAX_POWER, 500) <0)
- {
- fprintf(stderr, "ftdi_set_eeprom_value: %d (%s)\n",
+ f = ftdi_erase_eeprom(ftdi);
+ if (ftdi_set_eeprom_value(ftdi, MAX_POWER, 500) <0)
+ {
+ fprintf(stderr, "ftdi_set_eeprom_value: %d (%s)\n",
f, ftdi_get_error_string(ftdi));
- }
+ }
f = ftdi_erase_eeprom(ftdi);/* needed to determine EEPROM chip type */
- if (ftdi_get_eeprom_value(ftdi, CHIP_TYPE, & value) <0)
- {
- fprintf(stderr, "ftdi_get_eeprom_value: %d (%s)\n",
+ if (ftdi_get_eeprom_value(ftdi, CHIP_TYPE, & value) <0)
+ {
+ fprintf(stderr, "ftdi_get_eeprom_value: %d (%s)\n",
f, ftdi_get_error_string(ftdi));
- }
+ }
if (value == -1)
fprintf(stderr, "No EEPROM\n");
else if (value == 0)
@@ -167,30 +167,30 @@ int main(int argc, char **argv)
f=(ftdi_eeprom_build(ftdi));
if (f < 0)
{
- fprintf(stderr, "Erase failed: %s",
+ fprintf(stderr, "Erase failed: %s",
ftdi_get_error_string(ftdi));
return -2;
}
f = ftdi_write_eeprom(ftdi);
{
- fprintf(stderr, "ftdi_eeprom_decode: %d (%s)\n",
+ fprintf(stderr, "ftdi_eeprom_decode: %d (%s)\n",
f, ftdi_get_error_string(ftdi));
exit(-1);
}
f = ftdi_read_eeprom(ftdi);
if (f < 0)
{
- fprintf(stderr, "ftdi_read_eeprom: %d (%s)\n",
+ fprintf(stderr, "ftdi_read_eeprom: %d (%s)\n",
f, ftdi_get_error_string(ftdi));
exit(-1);
}
- }
+ }
else
{
f = ftdi_read_eeprom(ftdi);
if (f < 0)
{
- fprintf(stderr, "ftdi_read_eeprom: %d (%s)\n",
+ fprintf(stderr, "ftdi_read_eeprom: %d (%s)\n",
f, ftdi_get_error_string(ftdi));
exit(-1);
}
@@ -204,29 +204,29 @@ int main(int argc, char **argv)
else
size = value;
ftdi_get_eeprom_buf(ftdi, buf, size);
- for(i=0; i < size; i += 16)
+ for (i=0; i < size; i += 16)
{
- fprintf(stdout,"0x%03x:", i);
-
- for (j = 0; j< 8; j++)
- fprintf(stdout," %02x", buf[i+j]);
- fprintf(stdout," ");
- for (; j< 16; j++)
- fprintf(stdout," %02x", buf[i+j]);
- fprintf(stdout," ");
- for (j = 0; j< 8; j++)
- fprintf(stdout,"%c", isprint(buf[i+j])?buf[i+j]:'.');
- fprintf(stdout," ");
- for (; j< 16; j++)
- fprintf(stdout,"%c", isprint(buf[i+j])?buf[i+j]:'.');
- fprintf(stdout,"\n");
+ fprintf(stdout,"0x%03x:", i);
+
+ for (j = 0; j< 8; j++)
+ fprintf(stdout," %02x", buf[i+j]);
+ fprintf(stdout," ");
+ for (; j< 16; j++)
+ fprintf(stdout," %02x", buf[i+j]);
+ fprintf(stdout," ");
+ for (j = 0; j< 8; j++)
+ fprintf(stdout,"%c", isprint(buf[i+j])?buf[i+j]:'.');
+ fprintf(stdout," ");
+ for (; j< 16; j++)
+ fprintf(stdout,"%c", isprint(buf[i+j])?buf[i+j]:'.');
+ fprintf(stdout,"\n");
}
f = ftdi_eeprom_decode(ftdi, 1);
if (f < 0)
{
- fprintf(stderr, "ftdi_eeprom_decode: %d (%s)\n",
- f, ftdi_get_error_string(ftdi));
+ fprintf(stderr, "ftdi_eeprom_decode: %d (%s)\n",
+ f, ftdi_get_error_string(ftdi));
exit(-1);
}
diff --git a/examples/serial_read.c b/examples/serial_read.c
index 5d05d66..aec18d0 100644
--- a/examples/serial_read.c
+++ b/examples/serial_read.c
@@ -25,21 +25,21 @@ int main(int argc, char **argv)
{
switch (i)
{
- case 'i': // 0=ANY, 1=A, 2=B, 3=C, 4=D
- interface = strtoul(optarg, NULL, 0);
- break;
- case 'v':
- vid = strtoul(optarg, NULL, 0);
- break;
- case 'p':
- pid = strtoul(optarg, NULL, 0);
- break;
- case 'b':
- baudrate = strtoul(optarg, NULL, 0);
- break;
- default:
- fprintf(stderr, "usage: %s [-i interface] [-v vid] [-p pid] [-b
baudrate]\n", *argv);
- exit(-1);
+ case 'i': // 0=ANY, 1=A, 2=B, 3=C, 4=D
+ interface = strtoul(optarg, NULL, 0);
+ break;
+ case 'v':
+ vid = strtoul(optarg, NULL, 0);
+ break;
+ case 'p':
+ pid = strtoul(optarg, NULL, 0);
+ break;
+ case 'b':
+ baudrate = strtoul(optarg, NULL, 0);
+ break;
+ default:
+ fprintf(stderr, "usage: %s [-i interface] [-v vid] [-p pid]
[-b baudrate]\n", *argv);
+ exit(-1);
}
}
@@ -70,11 +70,12 @@ int main(int argc, char **argv)
}
// Read data forever
- while ((f = ftdi_read_data(&ftdic, buf, sizeof(buf))) >= 0) {
- fprintf(stderr, "read %d bytes\n", f);
- fwrite(buf, f, 1, stdout);
- fflush(stderr);
- fflush(stdout);
+ while ((f = ftdi_read_data(&ftdic, buf, sizeof(buf))) >= 0)
+ {
+ fprintf(stderr, "read %d bytes\n", f);
+ fwrite(buf, f, 1, stdout);
+ fflush(stderr);
+ fflush(stdout);
}
ftdi_usb_close(&ftdic);
diff --git a/examples/stream_test.c b/examples/stream_test.c
index f8d024e..47f2f39 100644
--- a/examples/stream_test.c
+++ b/examples/stream_test.c
@@ -4,7 +4,7 @@
*
* The FT2232H must supply data due to an appropriate circuit
*
- * To check for skipped block with appended code,
+ * To check for skipped block with appended code,
* a structure as follows is assumed
* 1* uint32_t num (incremented in 0x4000 steps)
* 3* uint32_t dont_care
@@ -39,28 +39,28 @@ static int exitRequested = 0;
static void
sigintHandler(int signum)
{
- exitRequested = 1;
+ exitRequested = 1;
}
static void
usage(const char *argv0)
{
- fprintf(stderr,
- "Usage: %s [options...] \n"
- "Test streaming read from FT2232H\n"
- "[-P string] only look for product with given string\n"
- "[-n] don't check for special block structure\n"
- "\n"
- "If some filename is given, write data read to that file\n"
- "Progess information is printed each second\n"
- "Abort with ^C\n"
- "\n"
- "Options:\n"
- "\n"
- "Copyright (C) 2009 Micah Dowty <micah@xxxxxxx>\n"
- "Adapted for use with libftdi (C) 2010 Uwe Bonnes
<bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>\n",
- argv0);
- exit(1);
+ fprintf(stderr,
+ "Usage: %s [options...] \n"
+ "Test streaming read from FT2232H\n"
+ "[-P string] only look for product with given string\n"
+ "[-n] don't check for special block structure\n"
+ "\n"
+ "If some filename is given, write data read to that file\n"
+ "Progess information is printed each second\n"
+ "Abort with ^C\n"
+ "\n"
+ "Options:\n"
+ "\n"
+ "Copyright (C) 2009 Micah Dowty <micah@xxxxxxx>\n"
+ "Adapted for use with libftdi (C) 2010 Uwe Bonnes
<bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>\n",
+ argv0);
+ exit(1);
}
static uint32_t start = 0;
@@ -71,241 +71,242 @@ static uint32_t n_err = 0;
static int
readCallback(uint8_t *buffer, int length, FTDIProgressInfo *progress, void
*userdata)
{
- if (length)
- {
- if (check)
- {
- int i,rem;
- uint32_t num;
- for (i= offset; i<length-16; i+=16)
- {
- num = *(uint32_t*) (buffer+i);
- if (start && (num != start +0x4000))
- {
- uint32_t delta = ((num-start)/0x4000)-1;
- fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at
blocks %10llu\n",
- delta, start -0x4000, num, (unsigned long
long)blocks);
- n_err++;
- skips += delta;
- }
- blocks ++;
- start = num;
- }
- rem = length -i;
- if (rem >3)
- {
- num = *(uint32_t*) (buffer+i);
- if (start && (num != start +0x4000))
- {
- uint32_t delta = ((num-start)/0x4000)-1;
- fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at
blocks %10llu\n",
- delta, start -0x4000, num, (unsigned long long)
blocks);
- n_err++;
- skips += delta;
- }
- start = num;
- }
- else if (rem)
- start += 0x4000;
- if (rem != 0);
- {
- blocks ++;
- offset = 16-rem;
- }
- }
- if (outputFile)
- {
- if (fwrite(buffer, length, 1, outputFile) != 1)
- {
- perror("Write error");
- return 1;
- }
- }
- }
- if (progress)
- {
- fprintf(stderr, "%10.02fs total time %9.3f MiB captured %7.1f kB/s curr
rate %7.1f kB/s totalrate %d dropouts\n",
- progress->totalTime,
- progress->current.totalBytes / (1024.0 * 1024.0),
- progress->currentRate / 1024.0,
- progress->totalRate / 1024.0,
- n_err);
- }
- return exitRequested ? 1 : 0;
+ if (length)
+ {
+ if (check)
+ {
+ int i,rem;
+ uint32_t num;
+ for (i= offset; i<length-16; i+=16)
+ {
+ num = *(uint32_t*) (buffer+i);
+ if (start && (num != start +0x4000))
+ {
+ uint32_t delta = ((num-start)/0x4000)-1;
+ fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at
blocks %10llu\n",
+ delta, start -0x4000, num, (unsigned long
long)blocks);
+ n_err++;
+ skips += delta;
+ }
+ blocks ++;
+ start = num;
+ }
+ rem = length -i;
+ if (rem >3)
+ {
+ num = *(uint32_t*) (buffer+i);
+ if (start && (num != start +0x4000))
+ {
+ uint32_t delta = ((num-start)/0x4000)-1;
+ fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at
blocks %10llu\n",
+ delta, start -0x4000, num, (unsigned long long)
blocks);
+ n_err++;
+ skips += delta;
+ }
+ start = num;
+ }
+ else if (rem)
+ start += 0x4000;
+ if (rem != 0);
+ {
+ blocks ++;
+ offset = 16-rem;
+ }
+ }
+ if (outputFile)
+ {
+ if (fwrite(buffer, length, 1, outputFile) != 1)
+ {
+ perror("Write error");
+ return 1;
+ }
+ }
+ }
+ if (progress)
+ {
+ fprintf(stderr, "%10.02fs total time %9.3f MiB captured %7.1f kB/s
curr rate %7.1f kB/s totalrate %d dropouts\n",
+ progress->totalTime,
+ progress->current.totalBytes / (1024.0 * 1024.0),
+ progress->currentRate / 1024.0,
+ progress->totalRate / 1024.0,
+ n_err);
+ }
+ return exitRequested ? 1 : 0;
}
int main(int argc, char **argv)
{
- struct ftdi_context ftdic;
- int err, c;
- FILE *of = NULL;
- char const *outfile = 0;
- outputFile =0;
- exitRequested = 0;
- char *descstring = NULL;
- int option_index;
- static struct option long_options[] = {{NULL},};
+ struct ftdi_context ftdic;
+ int err, c;
+ FILE *of = NULL;
+ char const *outfile = 0;
+ outputFile =0;
+ exitRequested = 0;
+ char *descstring = NULL;
+ int option_index;
+ static struct option long_options[] = {{NULL},};
- while ((c = getopt_long(argc, argv, "P:n", long_options, &option_index))
!=- 1)
- switch (c)
- {
- case -1:
- break;
- case 'P':
- descstring = optarg;
- break;
- case 'n':
- check = 0;
- break;
- default:
- usage(argv[0]);
- }
-
- if (optind == argc - 1)
- {
- // Exactly one extra argument- a dump file
- outfile = argv[optind];
- }
- else if (optind < argc)
- {
- // Too many extra args
- usage(argv[0]);
- }
-
- if (ftdi_init(&ftdic) < 0)
- {
- fprintf(stderr, "ftdi_init failed\n");
- return EXIT_FAILURE;
- }
-
- if (ftdi_set_interface(&ftdic, INTERFACE_A) < 0)
- {
- fprintf(stderr, "ftdi_set_interface failed\n");
- return EXIT_FAILURE;
- }
-
- if (ftdi_usb_open_desc(&ftdic, 0x0403, 0x6010, descstring, NULL) < 0)
- {
- fprintf(stderr,"Can't open ftdi device:
%s\n",ftdi_get_error_string(&ftdic));
- return EXIT_FAILURE;
- }
-
- /* A timeout value of 1 results in may skipped blocks */
- if(ftdi_set_latency_timer(&ftdic, 2))
- {
- fprintf(stderr,"Can't set latency, Error
%s\n",ftdi_get_error_string(&ftdic));
- return EXIT_FAILURE;
- }
-
-/* if(ftdi_usb_purge_rx_buffer(&ftdic) < 0)
- {
- fprintf(stderr,"Can't rx purge\n",ftdi_get_error_string(&ftdic));
- return EXIT_FAILURE;
- }*/
- if (outfile)
- if ((of = fopen(outfile,"w+")) == 0)
- fprintf(stderr,"Can't open logfile %s, Error %s\n", outfile,
strerror(errno));
- if (of)
- if (setvbuf(of, NULL, _IOFBF , 1<<16) == 0)
- outputFile = of;
- signal(SIGINT, sigintHandler);
-
- err = ftdi_readstream(&ftdic, readCallback, NULL, 8, 256);
- if (err < 0 && !exitRequested)
- exit(1);
-
- if (outputFile) {
- fclose(outputFile);
- outputFile = NULL;
- }
- fprintf(stderr, "Capture ended.\n");
-
- if (ftdi_set_bitmode(&ftdic, 0xff, BITMODE_RESET) < 0)
- {
- fprintf(stderr,"Can't set synchronous fifo mode, Error
%s\n",ftdi_get_error_string(&ftdic));
- return EXIT_FAILURE;
- }
- ftdi_usb_close(&ftdic);
- ftdi_deinit(&ftdic);
- signal(SIGINT, SIG_DFL);
- if (check && outfile)
- {
- if ((outputFile = fopen(outfile,"r")) == 0)
+ while ((c = getopt_long(argc, argv, "P:n", long_options, &option_index))
!=- 1)
+ switch (c)
+ {
+ case -1:
+ break;
+ case 'P':
+ descstring = optarg;
+ break;
+ case 'n':
+ check = 0;
+ break;
+ default:
+ usage(argv[0]);
+ }
+
+ if (optind == argc - 1)
+ {
+ // Exactly one extra argument- a dump file
+ outfile = argv[optind];
+ }
+ else if (optind < argc)
+ {
+ // Too many extra args
+ usage(argv[0]);
+ }
+
+ if (ftdi_init(&ftdic) < 0)
+ {
+ fprintf(stderr, "ftdi_init failed\n");
+ return EXIT_FAILURE;
+ }
+
+ if (ftdi_set_interface(&ftdic, INTERFACE_A) < 0)
+ {
+ fprintf(stderr, "ftdi_set_interface failed\n");
+ return EXIT_FAILURE;
+ }
+
+ if (ftdi_usb_open_desc(&ftdic, 0x0403, 0x6010, descstring, NULL) < 0)
+ {
+ fprintf(stderr,"Can't open ftdi device:
%s\n",ftdi_get_error_string(&ftdic));
+ return EXIT_FAILURE;
+ }
+
+ /* A timeout value of 1 results in may skipped blocks */
+ if (ftdi_set_latency_timer(&ftdic, 2))
+ {
+ fprintf(stderr,"Can't set latency, Error
%s\n",ftdi_get_error_string(&ftdic));
+ return EXIT_FAILURE;
+ }
+
+ /* if(ftdi_usb_purge_rx_buffer(&ftdic) < 0)
{
- fprintf(stderr,"Can't open logfile %s, Error %s\n", outfile,
strerror(errno));
+ fprintf(stderr,"Can't rx purge\n",ftdi_get_error_string(&ftdic));
return EXIT_FAILURE;
- }
- check_outfile(descstring);
- fclose(outputFile);
- }
- else if (check)
- fprintf(stderr,"%d errors of %llu blocks (%Le), %d (%Le) blocks
skipped\n",
- n_err, (unsigned long long) blocks, (long double)n_err/(long
double) blocks,
- skips, (long double)skips/(long double) blocks);
- exit (0);
+ }*/
+ if (outfile)
+ if ((of = fopen(outfile,"w+")) == 0)
+ fprintf(stderr,"Can't open logfile %s, Error %s\n", outfile,
strerror(errno));
+ if (of)
+ if (setvbuf(of, NULL, _IOFBF , 1<<16) == 0)
+ outputFile = of;
+ signal(SIGINT, sigintHandler);
+
+ err = ftdi_readstream(&ftdic, readCallback, NULL, 8, 256);
+ if (err < 0 && !exitRequested)
+ exit(1);
+
+ if (outputFile)
+ {
+ fclose(outputFile);
+ outputFile = NULL;
+ }
+ fprintf(stderr, "Capture ended.\n");
+
+ if (ftdi_set_bitmode(&ftdic, 0xff, BITMODE_RESET) < 0)
+ {
+ fprintf(stderr,"Can't set synchronous fifo mode, Error
%s\n",ftdi_get_error_string(&ftdic));
+ return EXIT_FAILURE;
+ }
+ ftdi_usb_close(&ftdic);
+ ftdi_deinit(&ftdic);
+ signal(SIGINT, SIG_DFL);
+ if (check && outfile)
+ {
+ if ((outputFile = fopen(outfile,"r")) == 0)
+ {
+ fprintf(stderr,"Can't open logfile %s, Error %s\n", outfile,
strerror(errno));
+ return EXIT_FAILURE;
+ }
+ check_outfile(descstring);
+ fclose(outputFile);
+ }
+ else if (check)
+ fprintf(stderr,"%d errors of %llu blocks (%Le), %d (%Le) blocks
skipped\n",
+ n_err, (unsigned long long) blocks, (long double)n_err/(long
double) blocks,
+ skips, (long double)skips/(long double) blocks);
+ exit (0);
}
void check_outfile(char *descstring)
{
- if(strcmp(descstring,"FT2232HTEST") == 0)
+ if (strcmp(descstring,"FT2232HTEST") == 0)
{
- char buf0[1024];
- char buf1[1024];
- char bufr[1024];
- char *pa, *pb, *pc;
- unsigned int num_lines = 0, line_num = 1;
- int err_count = 0;
- unsigned int num_start, num_end;
+ char buf0[1024];
+ char buf1[1024];
+ char bufr[1024];
+ char *pa, *pb, *pc;
+ unsigned int num_lines = 0, line_num = 1;
+ int err_count = 0;
+ unsigned int num_start, num_end;
- pa = buf0;
- pb = buf1;
- pc = buf0;
- if(fgets(pa, 1023, outputFile) == NULL)
- {
- fprintf(stderr,"Empty output file\n");
- return;
- }
- while(fgets(pb, 1023, outputFile) != NULL)
- {
- num_lines++;
- unsigned int num_save = num_start;
- if( sscanf(pa,"%6u%94s%6u",&num_start, bufr,&num_end) !=3)
- {
- fprintf(stdout,"Format doesn't match at line %8d \"%s",
- num_lines, pa);
- err_count++;
- line_num = num_save +2;
- }
- else
- {
- if ((num_start+1)%100000 != num_end)
- {
- if (err_count < 20)
- fprintf(stdout,"Malformed line %d \"%s\"\n",
- num_lines, pa);
- err_count++;
- }
- else if(num_start != line_num)
- {
- if (err_count < 20)
- fprintf(stdout,"Skipping from %d to %d\n",
- line_num, num_start);
- err_count++;
-
- }
- line_num = num_end;
- }
- pa = pb;
- pb = pc;
- pc = pa;
- }
- if(err_count)
- fprintf(stdout,"\n%d errors of %d data sets %f\n", err_count,
num_lines, (double) err_count/(double)num_lines);
- else
- fprintf(stdout,"No errors for %d lines\n",num_lines);
- }
- else if(strcmp(descstring,"LLBBC10") == 0)
- {
+ pa = buf0;
+ pb = buf1;
+ pc = buf0;
+ if (fgets(pa, 1023, outputFile) == NULL)
+ {
+ fprintf(stderr,"Empty output file\n");
+ return;
+ }
+ while (fgets(pb, 1023, outputFile) != NULL)
+ {
+ num_lines++;
+ unsigned int num_save = num_start;
+ if ( sscanf(pa,"%6u%94s%6u",&num_start, bufr,&num_end) !=3)
+ {
+ fprintf(stdout,"Format doesn't match at line %8d \"%s",
+ num_lines, pa);
+ err_count++;
+ line_num = num_save +2;
+ }
+ else
+ {
+ if ((num_start+1)%100000 != num_end)
+ {
+ if (err_count < 20)
+ fprintf(stdout,"Malformed line %d \"%s\"\n",
+ num_lines, pa);
+ err_count++;
+ }
+ else if (num_start != line_num)
+ {
+ if (err_count < 20)
+ fprintf(stdout,"Skipping from %d to %d\n",
+ line_num, num_start);
+ err_count++;
+
+ }
+ line_num = num_end;
+ }
+ pa = pb;
+ pb = pc;
+ pc = pa;
+ }
+ if (err_count)
+ fprintf(stdout,"\n%d errors of %d data sets %f\n", err_count,
num_lines, (double) err_count/(double)num_lines);
+ else
+ fprintf(stdout,"No errors for %d lines\n",num_lines);
+ }
+ else if (strcmp(descstring,"LLBBC10") == 0)
+ {
uint32_t block0[4];
uint32_t block1[4];
uint32_t *pa = block0;
@@ -320,13 +321,13 @@ void check_outfile(char *descstring)
fprintf(stderr,"Empty result file\n");
return;
}
- while(fread(pb, sizeof(uint32_t), 4,outputFile) != 0)
+ while (fread(pb, sizeof(uint32_t), 4,outputFile) != 0)
{
blocks++;
nread = pa[0];
- if(start>0 && (nread != start))
+ if (start>0 && (nread != start))
{
- if(n_shown < 30)
+ if (n_shown < 30)
{
fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at
blocks %10llu \n",
(nread-start)/0x4000, start -0x4000, nread,
(unsigned long long) blocks);
@@ -334,14 +335,14 @@ void check_outfile(char *descstring)
}
n_errors++;
}
- else if (n_shown >0)
- n_shown--;
+ else if (n_shown >0)
+ n_shown--;
start = nread + 0x4000;
pa = pb;
pb = pc;
pc = pa;
}
- if(n_errors)
+ if (n_errors)
fprintf(stderr, "%d blocks wrong from %llu blocks read\n",
n_errors, (unsigned long long) blocks);
else
hooks/post-receive
--
port libftdi to libusb-1.0
--
libftdi-git - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|