simple_getdata.c

Go to the documentation of this file.
00001 
00017 #include "edtinc.h"
00018 #include <stdlib.h>
00019 
00020 void
00021 usage(char *err)
00022 {
00023     printf(err);
00024     printf("usage: simple_getdata\n") ;
00025     printf("    -u <unit>     - specifies EDT board unit number\n") ;
00026     printf("    -c <channel>  - specifies EDT board channel number\n") ;
00027     printf("    -v                - verbose\n") ;
00028     printf("    -o outfile    - specifies output filename\n") ;
00029     printf("    -s <bufsize>  - ring buffer size (in bytes)\n") ;
00030     printf("    -N <numbufs>  - number of ring buffers\n") ;
00031     printf("    -l <loops>    - set loops: set number of DMA buffers\n") ;
00032     printf("    -p            - wait for CR before starting\n") ;
00033 
00034     exit(1);
00035 }
00036 
00037 int
00038 main(int argc, char **argv)
00039 {
00040     EdtDev *edt_p ;
00041     FILE   *outfile = NULL ;
00042     char   *outfile_name = NULL ;
00043     int     unit = 0, i;
00044     int     verbose = 0 ;
00045     u_char *buf ;
00046     int bufsize = 1024*1024;
00047     int loops = 100;
00048     int numbufs = 4;
00049     int channel = 0;
00050     int pause = 0;
00051     double speed;
00052     int flush = 1;
00053 
00054 
00055     while (argc > 1 && argv[1][0] == '-')
00056     {
00057         switch (argv[1][1])
00058         {
00059         case 'u':
00060             ++argv;
00061             --argc;
00062             if (argc < 2) 
00063             {
00064                 usage("Error: option 'u' requires a numeric argument\n");
00065             }
00066             if ((argv[1][0] >= '0') && (argv[1][0] <= '9'))
00067             {
00068                 unit = atoi(argv[1]);
00069             }
00070             else 
00071             {
00072                 usage("Error: option 'u' requires a numeric argument\n");
00073             }
00074             break;
00075 
00076         case 'c':
00077             ++argv;
00078             --argc;
00079             if (argc < 2) 
00080             {
00081                 usage("Error: option 'c' requires a numeric argument\n");
00082             }
00083             if ((argv[1][0] >= '0') && (argv[1][0] <= '9'))
00084             {
00085                 channel = atoi(argv[1]);
00086             }
00087             else 
00088             {
00089                 usage("Error: option 'c' requires a numeric argument\n");
00090             }
00091             break;
00092 
00093         case 'v':
00094             verbose = 1 ;
00095             break ;
00096 
00097         case 'o':
00098             ++argv ;
00099             --argc ;
00100             outfile_name = argv[1] ;
00101 
00102             if ((outfile = fopen(outfile_name, "wb")) == NULL)
00103             {
00104                 perror(outfile_name) ;
00105                 exit(1) ;
00106             }
00107 
00108             break ;
00109 
00110         case 's':
00111             ++argv ;
00112             --argc ;
00113             bufsize = strtol(argv[1],0,0);
00114             break;      
00115 
00116         case 'l':
00117             ++argv ;
00118             --argc ;
00119             loops = strtol(argv[1],0,0);
00120             break;      
00121 
00122         case 'p':
00123             pause = TRUE;
00124             break;
00125 
00126         case 'N':
00127             ++argv ;
00128             --argc ;
00129             numbufs = strtol(argv[1],0,0);
00130             break;      
00131 
00132         case 'h':
00133         case 'H':
00134             usage("");
00135             break;
00136 
00137         case 'f':
00138             flush = 0;
00139             break;
00140 
00141         default:
00142             usage("unknown option") ;
00143         }
00144         --argc ;
00145         ++argv ;
00146     }
00147 
00148     if (argc > 1) { usage(""); exit(1); }
00149 
00150     if ((edt_p = edt_open_channel(EDT_INTERFACE, unit, channel)) == NULL)
00151     {
00152         edt_perror("edt_open") ;
00153         exit(1) ;
00154     }
00155 
00156     if (edt_configure_ring_buffers(edt_p, bufsize, numbufs, EDT_READ, NULL) == -1)
00157     {
00158         fprintf(stderr,"Unable to configure ring-buffers\n");
00159 
00160         exit(1) ;
00161     }
00162 
00163     if (pause)
00164     {
00165         printf("Paused ->>");
00166         fflush(stdout);
00167         getchar();
00168     }
00169 
00170     if (flush)
00171         edt_flush_fifo(edt_p) ;         /* Flush the input fifo */
00172 
00173     edt_dtime();
00174 
00175     edt_start_buffers(edt_p, numbufs) ; /* start the transfers in free running mode */
00176 
00177     for (i = 0; (i < loops || loops == 0); i++)
00178     {
00179         buf = edt_wait_for_buffers(edt_p, 1) ;
00180 
00181         if (outfile) 
00182             fwrite(buf, 1, bufsize, outfile) ;
00183 
00184         if ((loops == 0) || (i < loops - numbufs))
00185             edt_start_buffers(edt_p, 1);
00186 
00187         if (verbose)
00188             printf("buffers completed:  application %d  driver %d\n",
00189             i+1, edt_done_count(edt_p)) ;
00190         else
00191         {
00192             putchar('.') ;
00193             fflush(stdout) ;
00194         }
00195     }
00196 
00197     speed = ((double) loops * (double) bufsize)/(edt_dtime() * 1000000.0);
00198 
00199     printf("buffers completed:  %f Mbyte/s application %d  driver %d\n",
00200         speed, i, edt_done_count(edt_p)) ;
00201 
00202     edt_disable_ring_buffers(edt_p);
00203 
00204     edt_close(edt_p) ;
00205 
00206     exit(0) ;
00207 }

Generated on 19 Jun 2015 by  doxygen 1.4.7