From f44dbec230aaa0835be8be7d4581394ed4a92435 Mon Sep 17 00:00:00 2001 From: Gerd v. Egidy Date: Sun, 6 Dec 2009 17:42:23 +0100 Subject: [PATCH] make the write chunksize (and read chunksize for syncbb) configurable --- examples/baud_test.c | 41 ++++++++++++++++++++++++++++++----------- 1 files changed, 30 insertions(+), 11 deletions(-) diff --git a/examples/baud_test.c b/examples/baud_test.c index 654bc78..f6bcac9 100644 --- a/examples/baud_test.c +++ b/examples/baud_test.c @@ -7,6 +7,7 @@ * -d * -b (divides by 16 if bitbang as taken from the ftdi datasheets) * -m r: serial a: async bitbang s:sync bitbang + * -c * * (C) 2009 by Gerd v. Egidy * @@ -44,8 +45,8 @@ int main(int argc, char **argv) { struct ftdi_context ftdic; int i, t; - char txbuf[256]; - char rxbuf[4096]; + char *txbuf; + char *rxbuf; double start, duration, plan; // default values @@ -53,9 +54,10 @@ int main(int argc, char **argv) int set_baud; int datasize=100000; int product_id=0x6001; + int txchunksize=256; enum ftdi_mpsse_mode test_mode=BITMODE_BITBANG; - while ((t = getopt (argc, argv, "b:d:p:m:")) != -1) + while ((t = getopt (argc, argv, "b:d:p:m:c:")) != -1) { switch (t) { @@ -85,9 +87,20 @@ int main(int argc, char **argv) case 'p': sscanf(optarg,"0x%x",&product_id); break; + case 'c': + txchunksize = atoi (optarg); + break; } } + txbuf=malloc(txchunksize); + rxbuf=malloc(txchunksize); + if (txbuf == NULL || rxbuf == NULL) + { + fprintf(stderr, "can't malloc\n"); + return EXIT_FAILURE; + } + if (ftdi_init(&ftdic) < 0) { fprintf(stderr, "ftdi_init failed\n"); @@ -131,7 +144,7 @@ int main(int argc, char **argv) // prepare data to send: 0 and 1 bits alternating (except for serial start/stopbit): // maybe someone wants to look at this with a scope or logic analyzer - for (i=0; i0); } - + start=get_prec_time(); i=0; while(i < datasize) { - int sendsize=sizeof(txbuf); + int sendsize=txchunksize; if (i+sendsize > datasize) sendsize=datasize-i; @@ -166,8 +185,8 @@ int main(int argc, char **argv) if(test_mode==BITMODE_SYNCBB) { - // read everything available - ftdi_read_data(&ftdic, rxbuf, sizeof(rxbuf)); + // read the same amount of data as sent + ftdi_read_data(&ftdic, rxbuf, txchunksize); } } -- 1.7.1