clsiminit.c

00001 /* "@(#)clsiminit.c     1.20 06/18/07 EDT" */
00002 #include "edtinc.h"
00003 #include <stdlib.h>
00004 
00005 #include "clsim_lib.h"
00006 
00007 #define ABOUT_TEXT "program to initialize camera link simulator board"
00008 
00009     static void
00010 usage(char *progname)
00011 {
00012     printf("%s: %s\n", progname, ABOUT_TEXT);
00013     printf("usage: %s [-u unit] [-F freq] [-f <config file>] [other OPTIONS...]\n", 
00014             progname);
00015     puts("OPTIONS: \n");
00016     puts("-u unit - sets device number (default 0)");
00017     puts("-c chan - sets device channel (MDR connector, 0 [default] or 1)");
00018     puts("-B - do NOT load bitfile");
00019     puts("-B bitfile - load user specified bitfile");
00020     puts("-l - enable uartloop (simulator will loop back any serial sent to it");
00021     puts("-q - disables program output (quiet mode)");
00022     puts("-s - sets simulator so data comes from internal counter instead of DMA");
00023     puts("-C - sets first word of frame to be framecount");
00024     printf("-F freq - sets pixel clock in MHz, takes a floating point arg (default %2.1f)\n",
00025             PDV_CLS_DEFAULT_FREQ);
00026     puts("-n nominal - overrides the default nominal frequency for si570 oscillator (usually 100 or 125)");
00027     puts("-t #taps - sets number of taps to #taps.");
00028 
00029     puts("");
00030 
00031     puts("-w width (default 1024) \n");
00032     puts("-h height (default 1024) \n");
00033     puts("-d depth (default 8) \n");
00034     puts("-f <config file> Use camera config for parameters\n");
00035 
00036     printf("-v vblank - sets interval between frames in lines (default %d)\n", 
00037             PDV_CLS_DEFAULT_VGAP);
00038     printf("-V VcntMax - sets total # of lines in frame ");
00039     printf("(ignored if vblank specified instead)\n");
00040 
00041     puts("");
00042 
00043     printf("-g hblank - sets # of pixel clocks of horizontal blanking (default %d)\n", 
00044             PDV_CLS_DEFAULT_HGAP);
00045     printf("-H HcntMax - sets total # of pixel clocks per line including blanking \n\
00046             (ignored if hblank specified instead)\n");
00047 
00048     puts("");
00049 
00050     printf("-r - \"reset\" board - You probably DO NOT want to do this: \n");
00051     printf("\tall settings (width, height, etc) are zero'd.\n");
00052     printf("--verbose - prints more information");
00053 }
00054 
00055 /*
00056  * Main module. NO_MAIN is typically only defined when compiling for vxworks; if you
00057  * want to use this code outside of a main module in any other OS, just copy the code
00058  * and modify it to work as a standalone subroutine, including adding parameters in
00059  * place of the command line arguments
00060  */
00061 #ifdef NO_MAIN
00062 #include "opt_util.h"
00063 char *argument ;
00064 int option ;
00065     int
00066 clsiminit(char *command_line)
00067 #else
00068     int
00069 main(argc, argv)
00070     int     argc;
00071     char  **argv;
00072 #endif
00073 {
00074     EdtDev *pdv_p;
00075 
00076     char *progname = NULL;
00077     int     unit = 0;
00078     int     chan = 0;
00079     int setup = 0;
00080     int no_bitload = 0;
00081     char bitfile_name[256];
00082     char *camera = NULL;
00083     PdvDependent *dd_p;
00084     Edtinfo ei;
00085     int i;
00086     int reset = 0;
00087     int uartloop = 0;
00088     int quiet = 0;
00089     int verbose = 0;
00090     int level; /* output message level */
00091 
00092 #ifdef NO_MAIN
00093     char **argv  = 0 ;
00094     int argc = 0 ;
00095     opt_create_argv("clsiminit",command_line,&argc,&argv);
00096 #endif
00097 
00098     progname = argv[0];
00099 
00100     strcpy(bitfile_name, "clsim.bit");
00101 
00102     if ((dd_p = pdv_alloc_dependent()) == NULL)
00103     {
00104         printf("alloc_dependent FAILED -- exiting\n");
00105         exit(1);
00106     }
00107 
00108     /* first find unit and channel - so we can open board to get dd */
00109 
00110     for (i=1;i<argc;i++)
00111     {
00112         if (argv[i][0] == '-')
00113         {
00114             if (argv[i][1] == 'u')
00115             {
00116                 if (i+1 >= argc) {
00117                     fprintf(stderr, "Error: option 'u' requires argument\n");
00118                     usage(progname);
00119                     exit(1);
00120                 }
00121                 unit = atoi(argv[i+1]);
00122             } 
00123             else if (argv[i][1] == 'c')
00124             {
00125                 if (i+1 >= argc) {
00126                     fprintf(stderr, "Error: option 'c' requires argument\n");
00127                     usage(progname);
00128                     exit(1);
00129                 }
00130                 chan = atoi(argv[i+1]);
00131             } 
00132             else if (argv[i][1] == 'r')
00133             {
00134                 reset = 1;
00135             } 
00136             else if (argv[i][1] == 'f')
00137             {
00138                 if (i+1 >= argc) {
00139                     fprintf(stderr, "Error: option 'f' requires argument\n");
00140                     usage(progname);
00141                     exit(1);
00142                 }
00143                 camera = argv[i+1];
00144                 setup = 1;
00145             }
00146             else if (argv[i][1] == '-') {
00147                 if (strncmp(argv[i], "--help", 3) == 0) { /* only need check the first few chars */
00148                     usage(progname);
00149                     exit(0);
00150                 } else if (strncmp(argv[i], "--verbose", 4) == 0) {
00151                     ++verbose;
00152                 } else {
00153                     fprintf(stderr, "Unknown option \"%s\"\n", argv[i]);
00154                     usage(progname);
00155                     exit(1);
00156                 }
00157             }
00158         }
00159     }
00160 
00161     pdv_p = pdv_open_channel("pdv", unit, chan);
00162 
00163     if (pdv_p == NULL)
00164     {
00165         fprintf(stderr, "Could not open EDT device for writes\n");
00166         exit(1);
00167     }
00168 
00169     if (!pdv_is_simulator(pdv_p))
00170     {
00171         fprintf(stderr, "\nclsiminit is for simulators. To initialize an EDT framegrabber board, use initcam.\n");
00172         pdv_close(pdv_p);
00173         exit(1);
00174     }
00175 
00176 
00177     dd_p = pdv_p->dd_p;
00178 
00179     if (reset)
00180         memset(dd_p, 0, sizeof(PdvDependent));
00181 
00182 
00183     /* Read this here so arguments can override values in config file */
00184 
00185     if (camera)
00186     {
00187         int retval = pdv_readcfg(camera, dd_p, &ei);
00188 
00189         if (retval == -1)
00190         {
00191             fprintf(stderr, "Error reading config file '%s'\n",
00192                     camera);
00193             pdv_close(pdv_p);
00194             exit(1);
00195         }
00196     }
00197 
00198     --argc;
00199     ++argv;
00200     while (argc && argv[0][0] == '-')
00201     {
00202         switch (argv[0][1])
00203         {
00204             /* skip options parsed earlier */
00205             case 'u':
00206             case 'f':
00207             case 'c':
00208                 ++argv;
00209                 --argc;
00210             case 'r':
00211                 break;
00212 
00213             case 's':
00214                 /* do dma */
00215                 dd_p->cls.flags.Cfg.datacnt = 1;
00216                 setup = 1;
00217                 break;
00218 
00219             case 'C':
00220                 dd_p->cls.flags.Cfg.firstfc = 1;
00221                 setup = 1;
00222                 break;
00223 
00224             case 'F':    /* Set PLL for desired pixel clock freq in MHz */
00225                 ++argv;
00226                 --argc;
00227                 if (argc < 1) {
00228                     fprintf(stderr, "Error: option 'F' requires argument\n");
00229                     usage(progname);
00230                     exit(1);
00231                 }
00232                 setup=1;
00233                 dd_p->cls.pixel_clock = (float)atof(argv[0]);    /* Convert arg to float */
00234                 dd_p->pclock_speed = (int)(dd_p->cls.pixel_clock + 0.5); /* redundant dd_p var */
00235                 break;
00236 
00237             case 'v':
00238                 ++argv;
00239                 --argc;
00240                 if (argc < 1) {
00241                     fprintf(stderr, "Error: option 'v' requires argument\n");
00242                     usage(progname);
00243                     exit(1);
00244                 }
00245                 dd_p->cls.vblank = atoi(argv[0]);
00246                 setup=1;
00247 
00248                 break;
00249 
00250             case 'V':
00251                 ++argv;
00252                 --argc;
00253                 dd_p->cls.Vcntmax = atoi(argv[0]);
00254                 setup=1;
00255                 break;
00256 
00257             case 'B':
00258                 if (argc < 2)
00259                     no_bitload = 1;
00260                 else
00261                 {
00262                     if (argv[1][0] != '-')
00263                     {
00264                         /* set bitfile name */
00265                         ++argv;
00266                         --argc;
00267                         strcpy(bitfile_name,argv[0]);
00268                     }
00269                     else
00270                         no_bitload = 1;
00271                 }
00272                 break;
00273 
00274             case 'n':
00275                 ++argv;
00276                 --argc;
00277                 dd_p->cls.si570_nominal = atof(argv[1]);
00278                 if (dd_p->cls.si570_nominal < 2000.0)
00279                     dd_p->cls.si570_nominal *= 1000000.0;
00280                 break;
00281 
00282             case 'q':
00283                 quiet = 1;
00284                 break;
00285 
00286             case 'l':
00287                 dd_p->cls.flags.Cfg.uartloop = 1;
00288                 break;
00289 
00290             case 'w':
00291                 ++argv;
00292                 --argc;
00293                 if (argc < 1) {
00294                     fprintf(stderr, "Error: option 'w' requires argument\n");
00295                     usage(progname);
00296                     exit(1);
00297                 }
00298                 setup=1;
00299                 dd_p->width = atoi(argv[0]);
00300                 break;
00301 
00302             case 'H':
00303                 ++argv;
00304                 --argc;
00305                 if (argc < 1) {
00306                     fprintf(stderr, "Error: option 'H' requires argument\n");
00307                     usage(progname);
00308                     exit(1);
00309                 }
00310                 dd_p->cls.Hcntmax = atoi(argv[0]);
00311                 setup=1;
00312                 break;
00313 
00314             case 'g':
00315                 ++argv;
00316                 --argc;
00317                 if (argc < 1) {
00318                     fprintf(stderr, "Error: option 'G' requires argument\n");
00319                     usage(progname);
00320                     exit(1);
00321                 }
00322                 dd_p->cls.hblank = atoi(argv[0]);
00323                 setup=1;
00324                 break;
00325 
00326             case 'h':
00327                 ++argv;
00328                 --argc;
00329                 if (argc < 1) {
00330                     fprintf(stderr, "Error: option 'h' requires argument\n");
00331                     usage(progname);
00332                     exit(1);
00333                 }
00334                 dd_p->height = atoi(argv[0]);
00335                 setup=1;
00336                 break;
00337 
00338             case 'd':
00339                 ++argv;
00340                 --argc;
00341                 if (argc < 1) {
00342                     fprintf(stderr, "Error: option 'd' requires argument\n");
00343                     usage(progname);
00344                     exit(1);
00345                 }
00346                 dd_p->depth = atoi(argv[0]);
00347                 setup=1;
00348                 break;
00349 
00350             case 't':
00351                 ++argv;
00352                 --argc;
00353                 if (argc < 1) {
00354                     fprintf(stderr, "Error: option 't' requires argument\n");
00355                     usage(progname);
00356                     exit(1);
00357                 }
00358                 dd_p->cls.taps = atoi(argv[0]);
00359                 setup=1;
00360                 break;
00361 
00362 
00363             case '-': /* these already parsed above; nothing to do here */
00364                 break;
00365 
00366             default:
00367                 usage(progname);
00368                 exit(0);
00369         }
00370         argc--;
00371         argv++;
00372     }
00373 
00374     /* setup output message level */
00375     level = edt_msg_default_level();
00376     if (verbose) 
00377     {
00378         level |= EDTAPP_MSG_INFO_1;
00379         level |= EDTLIB_MSG_INFO_1;
00380     } 
00381     if (verbose > 1) 
00382     {
00383         level |= EDTAPP_MSG_INFO_1 
00384             | EDTAPP_MSG_INFO_2 
00385             | EDTLIB_MSG_INFO_1 
00386             | EDTLIB_MSG_INFO_2;
00387     }
00388     edt_msg_set_level(edt_msg_default_handle(), level);
00389 
00390 
00391     /* pci express dv clsim doesn't have interface xilinx to load */
00392     if (pdv_p->devid != PDVCLS_ID)
00393     {
00394         no_bitload = 1; 
00395     }
00396 
00397     if (setup || reset)
00398     {
00399         if (!no_bitload)
00400         {
00401             int flags = 0;
00402 #ifdef NO_FS
00403             flags |= BITLOAD_FLAGS_NOFS;
00404 #endif
00405             edt_bitload(pdv_p, "camera_config" /* basedir */,  bitfile_name, flags, 0 /* skip_load */);
00406         }
00407         if (pdv_cls_dep_sanity_check(pdv_p) == 0)
00408             pdv_cls_set_dep(pdv_p);
00409     }
00410 
00411     if (!quiet)
00412     {
00413         edt_msleep(500);
00414         pdv_cls_dump_state(pdv_p);
00415     }
00416     return(0) ;
00417 }
00418 

Generated on 19 Jun 2015 by  doxygen 1.4.7