00001
00002
00003
00004
00005
00006
00007 #include "edtinc.h"
00008
00009 static void usage(char *progname);
00010
00011 #ifdef NO_MAIN
00012 #include "opt_util.h"
00013 char *argument ;
00014 int option ;
00015 int
00016 initcam(char *command_line)
00017 #else
00018 int
00019 main(int argc, char *argv[])
00020 #endif
00021 {
00022 int unit = 0;
00023 int verbose = 1;
00024 int no_bitload = 0;
00025 char cfgname[256];
00026 char bitdir[256];
00027 char edt_devname[256];
00028 char errstr[64];
00029 char *progname = "initcam" ;
00030 char logname[256];
00031 EdtDev *edt_p = NULL;
00032 Edtinfo edtinfo;
00033 char *unitstr = "0";
00034 int channel = 0 ;
00035 static char *debug_env = NULL;
00036 Dependent *dd_p;
00037 int pdv_debug = 0;
00038 #ifdef NO_FS
00039 int nofs_cfg = 0;
00040 #endif
00041 int level;
00042 #ifdef NO_MAIN
00043 char **argv = 0 ;
00044 int argc = 0 ;
00045 opt_create_argv("initcam",command_line,&argc,&argv);
00046 #endif
00047
00048 *cfgname = '\0';
00049 *edt_devname = '\0';
00050 *bitdir = '\0';
00051 *logname = '\0';
00052
00053
00054 --argc;
00055 ++argv;
00056 while (argc && argv[0][0] == '-')
00057 {
00058 switch (argv[0][1])
00059 {
00060 case 'u':
00061 ++argv;
00062 --argc;
00063 if (argc < 1) {
00064 fprintf(stderr, "Error: option 'u' requires argument\n");
00065 usage(progname);
00066 exit(1);
00067 }
00068 unitstr = argv[0];
00069 break;
00070
00071 case 'c':
00072 ++argv;
00073 --argc;
00074 if (argc < 1) {
00075 fprintf(stderr, "Error: option 'c' requires argument\n");
00076 usage(progname);
00077 exit(1);
00078 }
00079 channel = atoi(argv[0]);
00080 break;
00081
00082 case 'O':
00083 ++argv;
00084 --argc;
00085 if (argc < 1) {
00086 fprintf(stderr, "Error: option 'O' requires file argument\n");
00087 usage(progname);
00088 exit(1);
00089 }
00090 strcpy(logname, argv[0]);
00091 break;
00092
00093 case 'q':
00094 verbose = 0;
00095 break;
00096
00097 case 'v':
00098 verbose = 1;
00099 break;
00100
00101 case 'V':
00102 verbose = 2;
00103 break;
00104
00105 case 'f':
00106 ++argv;
00107 --argc;
00108 if (argc < 1) {
00109 fprintf(stderr, "Error: option 'f' requires argument\n");
00110 usage(progname);
00111 exit(1);
00112 }
00113 strcpy(cfgname, argv[0]);
00114 #ifdef NO_FS
00115 strcpy(bitdir, "_NOFS_");
00116 nofs_cfg = 1;
00117 #endif
00118 break;
00119
00120 case 'e':
00121 #ifdef NO_FS
00122 ++argv;
00123 --argc;
00124 if (argc < 1) {
00125 fprintf(stderr, "Error: option 'e' requires argument\n");
00126 usage(progname);
00127 exit(1);
00128 }
00129 strcpy(cfgname, argv[0]);
00130 strcpy(bitdir, "_NOFS_");
00131 nofs_cfg = 1;
00132 #else
00133 fprintf(stdout, "\n-e specified but not compiled with nofs configs.\nrecompile with -DNO_FS and try again\n\n");
00134 usage(progname);
00135 exit(1);
00136 #endif
00137 break;
00138
00139 case 'B':
00140 no_bitload = 1;
00141 break;
00142
00143 case 'b':
00144 case 'd':
00145 ++argv;
00146 --argc;
00147 if (argc < 1) {
00148 fprintf(stderr, "Error: options 'b' or 'd' require argument\n");
00149 usage(progname);
00150 exit(1);
00151 }
00152 strcpy(bitdir, argv[0]);
00153 break;
00154
00155 case 'h':
00156 usage(progname);
00157 exit(0);
00158 break;
00159
00160 case '-':
00161 if (strcmp(argv[0], "--help") == 0) {
00162 usage(progname);
00163 exit(0);
00164 } else {
00165 fprintf(stderr, "unknown option: %s\n", argv[0]);
00166 usage(progname);
00167 exit(1);
00168 }
00169 break;
00170
00171 default:
00172 fprintf(stdout, "unknown flag -'%c'\n", argv[0][1]);
00173 usage(progname);
00174 exit(1);
00175 }
00176 argc--;
00177 argv++;
00178 }
00179
00180 if (!(*cfgname))
00181 {
00182 usage(progname);
00183 exit(1);
00184 }
00185
00186
00187
00188
00189
00190 if (debug_env == NULL
00191 && ((debug_env = (char *) getenv("PDVDEBUG")) != NULL)
00192 && *debug_env != '0')
00193 pdv_debug = atoi(debug_env);
00194
00195
00196
00197
00198
00199
00200 level = edt_msg_default_level();
00201
00202 if ((verbose > 1) && (pdv_debug < verbose))
00203 pdv_debug = verbose;
00204
00205 if ((!verbose) && (!pdv_debug))
00206 level = 0;
00207 else
00208 {
00209 if (verbose > 0)
00210 {
00211 level |= EDTAPP_MSG_INFO_1;
00212 level |= PDVLIB_MSG_INFO_1;
00213 level |= PDVLIB_MSG_WARNING;
00214 level |= PDVLIB_MSG_FATAL;
00215 }
00216 if (verbose > 1)
00217 level |= EDTAPP_MSG_INFO_2;
00218 if (pdv_debug > 1)
00219 level |= PDVLIB_MSG_INFO_2;
00220 }
00221
00222 edt_msg_set_level(edt_msg_default_handle(), level);
00223 if (*logname)
00224 edt_msg_set_name(edt_msg_default_handle(), logname);
00225
00226
00227
00228
00229 if (pdv_debug)
00230 pdv_setdebug(NULL, pdv_debug);
00231
00232
00233
00234
00235
00236 if ((dd_p = pdv_alloc_dependent()) == NULL)
00237 {
00238 edt_msg(PDVLIB_MSG_FATAL, "alloc_dependent FAILED -- exiting\n");
00239 exit(1);
00240 }
00241
00242 #ifdef NO_FS
00243 if (nofs_cfg)
00244 {
00245 int ret ;
00246 ret = pdv_readcfg_emb(cfgname, dd_p, &edtinfo);
00247 }
00248 else
00249 #endif
00250 if (pdv_readcfg(cfgname, dd_p, &edtinfo) != 0)
00251 {
00252 edt_msg(PDVLIB_MSG_FATAL, "readcfg FAILED -- exiting\n");
00253 exit(1);
00254 }
00255
00256 if (no_bitload)
00257 strcpy(dd_p->rbtfile, "_SKIPPED_");
00258
00259
00260
00261
00262 unit = edt_parse_unit_channel(unitstr, edt_devname, "pdv", &channel);
00263 edt_msg(EDTAPP_MSG_INFO_1, "opening %s unit %d....\n", edt_devname, unit);
00264 if ((edt_p = edt_open_channel(edt_devname, unit, channel)) == NULL)
00265 {
00266 sprintf(errstr, "edt_open(%s%d)", edt_devname, unit);
00267 edt_perror(errstr);
00268 return (1);
00269 }
00270
00271 if (edt_p->devid == PDVFOI_ID)
00272 {
00273 #ifdef _FOI_SUPPORTED
00274 pdv_initcam_set_rci(edt_p, channel) ;
00275 #else
00276 edt_msg(EDTAPP_MSG_FATAL,"FOI not supported after pkg v4.1.5.9\n");
00277 edt_close(edt_p);
00278 exit(1);
00279 #endif
00280 }
00281
00282 if (pdv_initcam(edt_p, dd_p, unit, &edtinfo, cfgname, bitdir,
00283 pdv_debug) != 0)
00284 {
00285 edt_msg(EDTAPP_MSG_FATAL,"initcam failed. Run with '-V' to see complete debugging output\n");
00286 edt_close(edt_p);
00287 exit(1);
00288 }
00289
00290 edt_close(edt_p);
00291 edt_msg(EDTAPP_MSG_FATAL, "done\n");
00292 #ifdef NO_MAIN
00293 return(0) ;
00294 #else
00295 exit(0);
00296 #endif
00297 }
00298
00299 static void
00300 usage(char *progname)
00301 {
00302 #ifdef NO_FS
00303 printf("usage: %s [options] [-e <cfg_name> | -f <cfg_path>]\n", progname);
00304 #else
00305 printf("usage: %s [options] -f <cfg_path>\n", progname);
00306 #endif
00307 printf(" -b <bit_dir> alternate bitfiles directory\n");
00308 printf(" -B don't load the bitfile\n");
00309 printf(" -f <cfg_path> config file pathname (required)\n");
00310 printf(" -e <cfg_name> embedded config (for no-filesystem operation -- must be compiled with -DNO_FS)\n");
00311 printf(" -u <unit> pdv unit number (default 0). A full device pathname\n");
00312 printf(" or filename can be substituted \n");
00313 printf(" -c <channel> channel #, for multi-channel boards\n");
00314 #ifdef _FOI_SUPPORTED
00315 printf(" -F <foiunit> FOI (RCI) unit number, when multiple RCI units exist\n");
00316 #endif
00317 printf(" (usually -F and -c are used together, with both specifying the same #)\n");
00318 printf(" -v, -V verbose, and really verbose\n");
00319 printf(" -O logfile output log file, will redirect any console output to specified file\n");
00320 printf(" -q quiet; no output\n");
00321 printf(" -h, --help this help message\n");
00322 printf("\n");
00323 }
00324