pdv_initcam.c

Go to the documentation of this file.
00001 
00008 #include "edtinc.h"
00009 
00010 /* shorthand debug level */
00011 #define INITCAM_MSG_ALWAYS EDT_MSG_FATAL
00012 #define DEBUG1 PDVLIB_MSG_INFO_1
00013 #define DEBUG2 PDVLIB_MSG_INFO_2
00014 
00015 
00016 /*
00017  * static prototypes
00018  */
00019 int     is_hex_byte_command(char *str);
00020 void    check_terminator(char *str);
00021 void    dir_from_path(char *dirstr, char *pathstr);
00022 void    fname_from_path(char *fname, char *pathstr);
00023 int     async_bitfile(EdtDev *edt_p);
00024 char   *grepit(char *buf, char *pat);
00025 int     is_hex_byte_command(char *str);
00026 int     findid(char *str, char *idstr);
00027 char   *strip_crlf(char *str);
00028 void    propeller_sleep(int n);
00029 char   *search_for_bitfile(char *rbtfile, char *cfgfname, char *bitpath);
00030 int     serial_init(EdtDev * edt_p, Dependent * dd_p);
00031 int     serial_init_basler_binary(EdtDev * edt_p, Dependent * dd_p);
00032 int     serial_init_duncan_binary(EdtDev * edt_p, Dependent * dd_p);
00033 int     send_xilinx_commands(EdtDev * edt_p, char *str);
00034 int     send_foi_commands(EdtDev * edt_p, char *str);
00035 int     check_roi(EdtDev * edt_p, Dependent * dd_p);
00036 void    check_camera_values(EdtDev * ed, Dependent * dd_p);
00037 int     kodak_query_serial(EdtDev * edt_p, char *cmd, int *val);
00038 int     specinst_download(EdtDev * edt_p, char *fname);
00039 int     specinst_setparams(EdtDev * edt_p, char *fname);
00040 void    setup_cl2_simulator(EdtDev *edt_p, Dependent *dd_p);
00041 int     check_register_wrap(EdtDev * edt_p);
00042 char   *serial_tx_rx(PdvDev * pdv_p, char *command, int hexin);
00043 void    do_xregwrites(EdtDev *edt_p, Dependent *dd_p);
00044 int serial_init_binary(EdtDev * edt_p, Dependent * dd_p);
00045 static int set_rci = 0;
00046 static int rci_set_unit = 0;
00047 static long    isascii_str(u_char * buf, int n);
00048 
00049 void
00050 pdv_initcam_set_rci(EdtDev * edt_p, int rci_unit)
00051 {
00052     rci_set_unit = rci_unit;
00053     set_rci = 1;
00054 }
00055 
00056 /*
00057  * initcam internal function -- assumes dependent struct has already been loaded from
00058  * pdv_readcfg() or equivalent.
00059  */
00060 
00061 int
00062 pdv_channel_initialized(int unit, int channel)
00063 
00064 {
00065         PdvDev *pdv_p;
00066 
00067         pdv_p = pdv_open_channel(EDT_INTERFACE,unit, channel);
00068 
00069         if (pdv_p && pdv_get_width(pdv_p) && pdv_get_height(pdv_p))
00070         {
00071                 return 1;
00072         }
00073 
00074         return 0;
00075 }
00076 
00129 int
00130 pdv_initcam(EdtDev * pdv_p, Dependent * dd_p, int unit, Edtinfo * edtinfo,
00131             char *cfgfname, char *bitdir, int pdv_debug)
00132 {
00133 
00134     char errmsg[256];
00135 
00136     /* make sure the device is open and valid */
00137     if ((pdv_p == NULL) || (dd_p == NULL) || (pdv_p->fd == (HANDLE) NULL))
00138     {
00139         edt_msg(EDT_MSG_FATAL, "ERROR: invalid dependent struct pointer\n");
00140         return -1;
00141     }
00142 
00143 #if 0 /* this doesn't work since is_dvcl2 includes PCIe8 and PCIe4 even if they're not configured as a simulator -- need a way to detect that!!! */
00144     if (edt_is_dvcl2(pdv_p))
00145     {
00146         edt_msg(EDT_MSG_FATAL, "ERROR: this is a simulator (output) board -- use clsimit to initialize\n");
00147         return -1;
00148     }
00149 #endif
00150 
00151     /*
00152      * reality check on some critical input variables
00153      */
00154     if ((dd_p->camera_class[0] == '\0')
00155      || (dd_p->width == 0)
00156      || (dd_p->height == 0)
00157      || (dd_p->depth < 8)
00158      || (dd_p->depth > 32)
00159      || (dd_p->extdepth < 8)
00160      || (dd_p->extdepth > 32)
00161      || (dd_p->depth & 1)
00162      || (dd_p->extdepth & 1))
00163      {
00164         edt_msg(PDVLIB_MSG_WARNING, "WARNING: one or more critical config values appear invalid\n");
00165         sprintf(errmsg, "check readcfg/dependent struct and camera_class, width, height, depth, extdepth\n");
00166         edt_msg(DEBUG2, errmsg);
00167      }
00168 
00169     /*
00170      * pdv_p->dd_p is not necessarily used here, and is normally set by
00171      * pdv_open, but initcam is a special case
00172      */
00173     if (pdv_p->dd_p == 0) /* must've been opened with edt_open (or separately freed?) */
00174         pdv_p->dd_p = dd_p;
00175     else if (pdv_p->dd_p != dd_p)
00176         memcpy(pdv_p->dd_p, dd_p, sizeof(Dependent));
00177 
00178     /* IMPORTANT: use pdv_p->dd_p not just dd_p from here on out in this function */
00179 
00180     if (pdv_p->devid == PDVFOI_ID)
00181     {
00182 #ifdef _FOI_SUPPORTED 
00183         pdv_initcam_checkfoi(pdv_p, edtinfo, unit);
00184 #else
00185         edt_msg(EDT_MSG_FATAL, "FOI not supported beyond v4.1.5.9\n");
00186         return -1;
00187 #endif
00188     }
00189     else
00190     {
00191         edt_reset_serial(pdv_p);
00192 
00193         if (pdv_p->dd_p->rbtfile[0])
00194         {
00195             if (edt_is_dvcl(pdv_p))
00196             {
00197                 edt_msg(DEBUG1, "DV C-Link, skipping xilinx load\n");
00198             }
00199             else if (strcmp(pdv_p->dd_p->rbtfile, "_SKIPPED_") == 0)
00200                 edt_msg(INITCAM_MSG_ALWAYS, "skipping bitload\n");
00201             else if (edt_is_dvfox(pdv_p) && pdv_p->channel_no > 0)
00202             {
00203                 edt_msg(DEBUG1, "DV FOX channel %d skipping bit load\n",
00204                         pdv_p->channel_no);
00205 
00206                 if (!pdv_channel_initialized(pdv_p->unit_no,
00207                                                 0))
00208                 {
00209                     edt_msg(EDT_MSG_FATAL, "You must initialize channel 0 before initializing any other channels on the DV-FOX\n");
00210                 }
00211             }
00212             else if (pdv_initcam_load_bitfile(pdv_p, pdv_p->dd_p, unit, bitdir, cfgfname))
00213                 {
00214                     edt_msg(EDT_MSG_FATAL, "ERROR: Failed bitload\n");
00215                     return -1;
00216                 }
00217         }
00218         else edt_msg(DEBUG1, "No bitfile specified, skipping xilinx load\n");
00219         if (pdv_initcam_reset_camera(pdv_p, pdv_p->dd_p, edtinfo))
00220         {
00221             edt_msg(EDT_MSG_FATAL, "ERROR: Failed camera reset\n");
00222             return -1;
00223         }
00224     }
00225 
00226     return 0;
00227 }
00228 
00229 
00230 
00238 Dependent *
00239 pdv_alloc_dependent()
00240 {
00241     int     dsize = sizeof(Dependent);
00242 
00243     /*
00244      * check dependent size, not over limit allocated for it
00245      */
00246     if (dsize > EDT_DEPSIZE)
00247     {
00248         edt_msg(EDT_MSG_FATAL, "libpdv internal error: bad dependent struct size (%d) s/b %d\n", dsize, EDT_DEPSIZE);
00249         return NULL;
00250     }
00251 
00252     return (Dependent *) calloc(EDT_DEPSIZE, 1);
00253 }
00254 
00255 
00256 #ifdef _FOI_SUPPORTED
00257 /*
00258  * the fiber optic interface has special needs
00259  */
00260 int
00261 pdv_initcam_checkfoi(EdtDev * edt_p, Edtinfo * p_edtinfo, int unit)
00262 {
00263     int     ncameras, camera;
00264     int     ret = 0;
00265 
00266     if (set_rci)
00267     {
00268         ncameras = edt_get_foicount(edt_p);
00269         edt_msg(DEBUG1, "sees %d cameras\n", ncameras);
00270         if (ncameras == 0)
00271         {
00272             edt_check_foi(edt_p);
00273         }
00274         edt_p->dd_p->serial_respcnt = 4;
00275         edt_set_foiunit(edt_p, rci_set_unit);
00276         edt_set_rci_dma(edt_p, rci_set_unit, edt_p->channel_no);
00277         ret = pdv_initcam_reset_camera(edt_p, edt_p->dd_p, p_edtinfo);
00278     }
00279     else
00280     {
00281         edt_set_foicount(edt_p, 0);     /* to force config */
00282         edt_check_foi(edt_p);
00283         edt_p->dd_p->serial_respcnt = 4;
00284         ncameras = edt_get_foicount(edt_p);
00285 
00286         for (camera = 0; (camera < ncameras) && ret == 0; camera++)
00287         {
00288             edt_msg(DEBUG1, "Initializing FOI Unit %d\n", camera);
00289             edt_set_foiunit(edt_p, camera);
00290             edt_set_rci_dma(edt_p, camera, edt_p->channel_no);
00291             ret = pdv_initcam_reset_camera(edt_p, edt_p->dd_p, p_edtinfo);
00292         }
00293     }
00294     return ret;
00295 }
00296 #endif
00297 
00298 
00299 void
00300 dep_wait(EdtDev * edt_p)
00301 {
00302     if (edt_p->devid == PDVFOI_ID)
00303     {
00304 #ifdef _FOI_SUPPORTED 
00305         char    dmy[256];
00306         int ret = pdv_serial_wait(edt_p, 200, 0);
00307         if (ret)
00308             pdv_serial_read(edt_p, dmy, ret);
00309 #endif
00310     }
00311 
00312 }
00313 
00314 /*
00315  * isapromaddress -- must be XXXXX.mmmm-YYYYY.mmmmo, where
00316  * XXXXX and YYYYY are 5-digit (or more) hex addresses, and mmmm and nnnnn
00317  * are the respective sizes in decimal  to download
00318  */
00319 int
00320 get_prom_addrs(char *str, u_int *addr1, int *size1, u_int *addr2, int *size2)
00321 {
00322 
00323     if (str == NULL)
00324         return 0;
00325 
00326     if (sscanf(str, "%x.%d-%x.%d", addr1, size1, addr2, size2) != 4)
00327     {
00328         *addr1 = 0;
00329         *addr2 = 0;
00330         *size1 = 0;
00331         *size2 = 0;
00332         return -1;
00333     }
00334     return 0;
00335 }
00336 
00337 int
00338 pdv_initcam_load_bitfile(EdtDev * edt_p,
00339                          Dependent * dd_p,
00340                          int unit,
00341                          char *bitdir,
00342                          char *cfgfname)
00343 {
00344     char    dir_arg[256];
00345     char    cfgdir[256];
00346     int     emb = 0;
00347     int     ret, flags=0;
00348     u_char  *ba = NULL;
00349 #ifdef NO_FS
00350     char bitname[128];
00351     int  len;
00352 #endif
00353 
00354     cfgdir[0] = '\0';
00355 
00356     edt_msg(DEBUG2, "pdv_initcam_load_bitfile('%s')\n", dd_p->rbtfile);
00357 
00358     if (strcmp(bitdir, "_NOFS_") == 0)
00359     {
00360         emb = 1;
00361         flags = BITLOAD_FLAGS_NOFS;
00362     }
00363 
00364 
00365     if (edt_p->devid == PDVFOI_ID || edt_p->devid == DMY_ID)
00366     {
00367 #if 0
00368         edt_flush_fifo(edt_p);
00369 #endif
00370         dd_p->serial_respcnt = 4;
00371     }
00372     else
00373     {
00374         u_int addr1, addr2;
00375         int size1, size2;
00376 
00377         dd_p->serial_respcnt = 2;
00378         /*
00379          * if -b flag specified, send "-b dirname". if not, strip off leading
00380          * dir from filename and if that exists, send -d dirname otheriwise
00381          * just send "-d camera_config" and hope there's a
00382          * camera_config/bitfiles
00383          */
00384 
00385         if (get_prom_addrs(dd_p->rbtfile, &addr1, &size1, &addr2, &size2) == 0)
00386         {
00387 
00388             edt_msg(DEBUG1, "loading camera xilinx from PROM @ %x %d / %x %d", addr1, size1, addr2, size2);
00389             ret = edt_bitload_from_prom(edt_p, (u_char *)addr1, size1, (u_char *)addr2, size2, flags);
00390             printf("\n");
00391         }
00392         else
00393         {
00394     #ifdef NO_FS
00395             if (emb)
00396             {
00397                 /* strip off .bit from name if nofs (embedded) xilinx */
00398                 strcpy(bitname, dd_p->rbtfile);
00399                 len = strlen(bitname);
00400                 if ((len >= 4) && (strcasecmp(&bitname[len-4], ".bit") == 0))
00401                     bitname[len-4] = '\0';
00402                 edt_msg(EDT_MSG_INFO_1, "loading embedded camera xilinx %s....\n", bitname);
00403                 ret = edt_bitload(edt_p, bitdir, bitname, 1, 0);
00404                 if (edt_is_dvfox(edt_p))
00405                     edt_msleep(500);
00406                 edt_flush_fifo(edt_p);
00407                 return ret;
00408             }
00409     #endif
00410             if (!emb)
00411             {
00412                 if (*bitdir)
00413                     strcpy(dir_arg, bitdir);
00414                 else
00415                 {
00416                     dir_from_path(cfgdir, cfgfname);
00417                     sprintf(bitdir, "%s/bitfiles", cfgdir);
00418 
00419                     if ((!(*cfgdir)) || (pdv_access(bitdir, 0) != 0))
00420                         strcpy(cfgdir, "camera_config");
00421 
00422                     strcpy(dir_arg, cfgdir);
00423                 }
00424             }
00425 
00426             edt_msg(DEBUG1, "loading camera xilinx %s....\n", dd_p->rbtfile);
00427 
00428             if ((ret = edt_bitload(edt_p, dir_arg, dd_p->rbtfile, 0, 0)) != 0)
00429                 return ret;
00430         }
00431 
00432         if (edt_is_dvfox(edt_p))
00433             edt_msleep(500);
00434 
00435         edt_flush_fifo(edt_p);
00436     }
00437 
00438     return 0;
00439 }
00440 
00441 
00442 
00443 /*
00444  * setup registers on the board and send camera setup serial if indicated
00445  */
00446 int
00447 pdv_initcam_reset_camera(EdtDev * edt_p, Dependent * dd_p, Edtinfo * p_edtinfo)
00448 {
00449     int     ret = 0;
00450     int     data_path = 0;
00451 
00452     if (edt_p->devid == PDVFOI_ID)
00453         edt_reset_serial(edt_p);
00454 
00455     if (dd_p->xilinx_rev == NOT_SET)
00456     {
00457         int     rev;
00458 
00459         edt_msg(DEBUG2, "checking for new rev xilinx\n");
00460         dep_wait(edt_p);
00461         edt_reg_write(edt_p, PDV_STAT, 0xff);
00462         rev = edt_reg_read(edt_p, PDV_REV);
00463         if (rev >= 1 && rev <= 32)
00464         {
00465             edt_msg(DEBUG2, "xilinx rev set to %d (0x%x)\n", rev, rev);
00466             dd_p->xilinx_rev = rev;
00467         }
00468         else
00469         {
00470             dd_p->xilinx_rev = 0;
00471             edt_msg(DEBUG2, "no xilinx rev from IOCTL, setting to 0\n");
00472         }
00473 
00474 #ifdef NOT_DONE
00475         /* xilinx rev 2 we got option flag register */
00476         if ((dd_p->xilinx_rev >= 2) && (dd_p->xilinx_rev != 0xff))
00477             dd_p->xilinx_opt = edt_reg_read(edt_p, PDV_XILINX_OPT);
00478 #endif
00479         dd_p->register_wrap = check_register_wrap(edt_p);
00480 
00481         /*
00482          * need to let the driver know the rev in dep_set/get since register
00483          * offsets changed in rev 2
00484          */
00485         edt_set_dependent(edt_p, dd_p);
00486     }
00487 
00488     /*
00489      * default baud is 9600; USED TO only set if explicitly in config
00490      * file, but why? on DVFOX that is a problem, and really no reason
00491      * not to (?), so jus' do it (as of 4.9.0.4.)
00492      */
00493     if (dd_p->serial_baud == NOT_SET)
00494         dd_p->serial_baud = 9600;
00495     pdv_set_baud(edt_p, dd_p->serial_baud);
00496 
00497 
00498     /*
00499      * infer dual channel from other flags
00500      */
00501     if (pdv_is_cameralink(edt_p)
00502      && (dd_p->cl_data_path & 0x10)
00503      && (!(dd_p->cl_cfg & PDV_CL_CFG_RGB)))
00504         dd_p->dual_channel = 1;
00505 
00506     if (!(edt_is_dvcl2(edt_p) && dd_p->sim_enable))
00507     {
00508         /*
00509          * set width/height.  Width and height as set in config file should be
00510          * actual camera width and height, before any ROI changes. ROI changes
00511          * will change dd_p->width/height but not dd_p->cam_width/height.
00512          */
00513         edt_msg(DEBUG1, "setting device defaults....\n");
00514         pdv_set_width(edt_p, dd_p->width);
00515         pdv_set_height(edt_p, dd_p->height);
00516         pdv_set_depth(edt_p, dd_p->depth);
00517 
00518         pdv_set_cam_width(edt_p, dd_p->width);
00519         pdv_set_cam_height(edt_p, dd_p->height);
00520 
00521         check_roi(edt_p, dd_p);
00522 
00523         if (dd_p->sim_enable) /* old simulator */
00524         {
00525             u_int   roictl;
00526 
00527             roictl = edt_reg_read(edt_p, PDV_ROICTL);
00528             /* default to simulated not from camera */
00529             if (!dd_p->sim_ctl)
00530                 roictl |= (PDV_ROICTL_SIM_DAT | PDV_ROICTL_SIM_SYNC);
00531             else
00532                 roictl |= dd_p->sim_ctl | PDV_ROICTL_SIM_DAT;
00533             edt_msg(DEBUG1, "setting simulator bits in roictl %x\n", roictl);
00534             edt_reg_write(edt_p, PDV_ROICTL, roictl);
00535         }
00536     }
00537 
00538     edt_set_dependent(edt_p, dd_p);
00539 
00540     edt_msg(DEBUG1, "setting registers....\n");
00541     if (edt_p->devid != PDVFOI_ID &&
00542         dd_p->genericsim)
00543     {
00544         edt_msg(DEBUG1, "setting up for simulator....\n");
00545         edt_reg_write(edt_p, SIM_LDELAY, dd_p->line_delay);
00546         edt_reg_write(edt_p, SIM_FDELAY, dd_p->frame_delay);
00547         edt_reg_write(edt_p, SIM_WIDTH, dd_p->sim_width - 1);
00548         edt_reg_write(edt_p, SIM_HEIGHT, dd_p->sim_height - 1);
00549         edt_reg_write(edt_p, SIM_CFG, dd_p->genericsim);
00550 
00551 
00552         edt_msg(DEBUG2, "SIM_CFG %x\n", dd_p->genericsim);
00553         switch (dd_p->sim_speed)
00554         {
00555         case 0:
00556             edt_msg(DEBUG2, "starting pixel clock at 5Mhz\n");
00557             edt_reg_write(edt_p, SIM_SPEED, 0);
00558             break;
00559         case 1:
00560             edt_msg(DEBUG2, "starting pixel clock at 10Mhz\n");
00561             edt_reg_write(edt_p, SIM_SPEED, 1);
00562             break;
00563         case 2:
00564             edt_msg(DEBUG2, "starting pixel clock at 20Mhz\n");
00565             edt_reg_write(edt_p, SIM_SPEED, 2);
00566             break;
00567         }
00568     }
00569 
00570 
00571     /* Configuration register settings (except CL2 simulator */
00572     if (!(edt_is_dvcl2(edt_p) && dd_p->sim_enable))
00573     {
00574         int     configuration = 0;
00575 
00576         if (dd_p->inv_shutter)
00577             configuration |= PDV_INV_SHUTTER;
00578         else
00579             configuration &= ~PDV_INV_SHUTTER;
00580 
00581         /*
00582          * if MODE_CNTL_NORM is not set, set default based on value
00583          * of camera_shutter timing
00584          */
00585         if (dd_p->mode_cntl_norm == NOT_SET)
00586         {
00587             if ((dd_p->camera_shutter_timing == AIA_MCL)
00588              || (dd_p->camera_shutter_timing == AIA_MCL_100US)
00589              || (dd_p->camera_shutter_timing == AIA_TRIG))
00590                 dd_p->mode_cntl_norm = 0x10;
00591             else dd_p->mode_cntl_norm = 0;
00592         }
00593 
00594         /*
00595          * set default values for shutter_speed_min/max if using board shutter
00596          * timer and no min/max specified
00597          */
00598         if ((dd_p->camera_shutter_timing == AIA_MCL)
00599          || (dd_p->camera_shutter_timing == AIA_MCL_100US))
00600         {
00601             int exp;
00602 
00603             if ((dd_p->shutter_speed_min == 0) && (dd_p->shutter_speed_max == 0))
00604             {
00605                 dd_p->shutter_speed_min = 0;
00606                 dd_p->shutter_speed_max = 25500;
00607             }
00608 
00609             exp = pdv_get_exposure(edt_p);
00610             if (exp < dd_p->shutter_speed_min || exp > dd_p->shutter_speed_max)
00611                 pdv_set_exposure(edt_p, dd_p->shutter_speed_min);
00612         }
00613 
00614         if (dd_p->camera_shutter_timing == AIA_SERIAL)
00615             dd_p->trig_pulse = 1;
00616 
00617         if (dd_p->trig_pulse || dd_p->camera_shutter_timing == AIA_SERIAL)
00618             configuration |= PDV_TRIG;
00619         else
00620             configuration &= ~PDV_TRIG;
00621 
00622         if (dd_p->dis_shutter)
00623             configuration |= PDV_DIS_SHUTTER;
00624         else
00625             configuration &= ~PDV_DIS_SHUTTER;
00626 
00627         if (dd_p->enable_dalsa)
00628             configuration |= PDV_EN_DALSA;
00629         else
00630             configuration &= ~PDV_EN_DALSA;
00631 
00632         edt_msg(DEBUG2, "CONFIG %x\n", configuration);
00633         dep_wait(edt_p);
00634         edt_reg_write(edt_p, PDV_CFG, configuration);
00635     }
00636 
00637     /* util3 register settings */
00638     {
00639         int     util3 = 0;
00640 
00641         if (dd_p->inv_ptrig)
00642             util3 |= PDV_LV_INVERT;
00643         else
00644             util3 &= ~PDV_LV_INVERT;
00645 
00646         if (dd_p->inv_fvalid)
00647             util3 |= PDV_FV_INVERT;
00648         else
00649             util3 &= ~PDV_FV_INVERT;
00650 
00651         /*
00652          * set dvfox mode16 automatically (ON if 8 bits single or dual channel
00653          * or 8-16 bits single channel, otherwise off), unless specifically set
00654          * in the config file
00655          */
00656         if (edt_is_dvfox(edt_p))
00657         {
00658             if (dd_p->mode16 == NOT_SET)
00659             {
00660                 if ((!(dd_p->cl_cfg & PDV_CL_CFG_RGB))
00661                  && (((dd_p->cl_data_path & 0x0f) == 0x07)
00662                  || (dd_p->cl_data_path <= 0x0f)))
00663                     util3 |= PDV_MODE16;
00664             }
00665             else if (dd_p->mode16)
00666                 util3 |= PDV_MODE16;
00667         }
00668 
00669 
00670         edt_msg(DEBUG2, "UTIL3 %x\n", util3);
00671         dep_wait(edt_p);
00672 
00673         edt_reg_write(edt_p, PDV_UTIL3, util3);
00674     }
00675 
00676     if (edt_p->devid != PDVFOI_ID)
00677         pdv_set_fval_done(edt_p, dd_p->fval_done);
00678 
00679         /* old initcam for irc was this */
00680     if (dd_p->camera_download == IRC_160)
00681     {
00682         int     tmp;
00683 
00684         edt_msg(DEBUG1, "doing old initcam method for IRC160");
00685 #if 0
00686         tmp = edt_reg_read(edt_p, PDV_CFG);     /* inverse shutter, not
00687                                                  * trigger */
00688         tmp &= ~(PDV_INV_SHUTTER | PDV_TRIG);
00689 #endif
00690         tmp = 0;
00691         if (dd_p->inv_shutter)
00692             tmp |= PDV_INV_SHUTTER;
00693         if (dd_p->camera_shutter_timing != AIA_MCL)
00694             tmp |= PDV_TRIG;
00695         dep_wait(edt_p);
00696         edt_reg_write(edt_p, PDV_CFG, tmp);
00697         edt_msg(DEBUG2, "CONFIG %x", tmp);
00698     }
00699 
00700     /* Data Path register settings (and camera link config/cntl) */
00701     if (pdv_is_cameralink(edt_p))
00702     {
00703         edt_msg(DEBUG2, "camera link cfg register %x\n", dd_p->cl_cfg);
00704         edt_reg_write(edt_p, PDV_CL_CFG, dd_p->cl_cfg);
00705 
00706         edt_msg(DEBUG2, "camera link cfg2 register %x\n", dd_p->cl_cfg2);
00707         edt_reg_write(edt_p, PDV_CL_CFG2, dd_p->cl_cfg2);
00708 
00709         edt_msg(DEBUG2, "camera link data_path register %x\n", dd_p->cl_data_path);
00710         edt_reg_write(edt_p, PDV_CL_DATA_PATH, dd_p->cl_data_path);
00711 
00712         if (dd_p->cl_hmax != 0x0)
00713         {
00714             edt_msg(DEBUG2, "camera link hmax register %x\n", dd_p->cl_hmax);
00715             edt_reg_write(edt_p, PDV_CL_HMAX, dd_p->cl_hmax);
00716         }
00717 
00718         if (dd_p->swinterlace == PDV_BGGR
00719                 || dd_p->swinterlace == PDV_ILLUNIS_BGGR)
00720         {
00721                 /* kludge for now */
00722         }
00723         else if (dd_p->depth > 8)
00724                 data_path |= PDV_EXT_DEPTH;
00725 
00726         if (dd_p->camera_shutter_timing == AIA_MCL_100US)
00727                 data_path |= PDV_MULTIPLIER_100US;
00728 
00729         if (dd_p->fv_once)
00730                 data_path |= PDV_CONTINUOUS;
00731 
00732         if (dd_p->trigdiv)
00733             edt_reg_write(edt_p, PDV_TRIGDIV, dd_p->trigdiv);
00734 
00735         dep_wait(edt_p);
00736         edt_reg_write(edt_p, PDV_DATA_PATH, data_path);
00737         dd_p->datapath_reg = data_path;
00738         edt_set_dependent(edt_p, dd_p);
00739     }
00740     else
00741     {
00742         if (dd_p->camera_shutter_timing == DALSA_CONTINUOUS)
00743             dd_p->continuous = 1;
00744 #if 0
00745         /* don't turn on until in driver */
00746         if (dd_p->continuous)
00747             data_path |= PDV_CONTINUOUS;
00748         else
00749             data_path &= ~PDV_CONTINUOUS;
00750 #endif
00751 
00752         if (dd_p->fv_once)
00753                 data_path |= PDV_CONTINUOUS;
00754 
00755         if (dd_p->interlace)
00756             data_path |= PDV_INTERLACED;
00757         else
00758             data_path &= ~PDV_INTERLACED;
00759 
00760         edt_msg(DEBUG2, "data_path register %x\n", data_path);
00761 
00762         /*
00763          * if async we set the board generated pixel clock speed in
00764          * roictl register (added async check so we can use pclock_speed
00765          * for auto timeout and other stuff 08/06 rwh)
00766          */
00767         if (async_bitfile(edt_p))
00768         {
00769             u_int bits = 0;
00770             u_int roictl = edt_reg_read(edt_p, PDV_ROICTL);
00771 
00772             if (dd_p->pclock_speed < 5)
00773                     dd_p->pclock_speed = 5;
00774 
00775             switch(dd_p->pclock_speed)
00776             {
00777                 case 20: bits = 0x04; break;
00778                 case 10: bits = 0x05; break;
00779                 case 5: bits = 0x06; break;
00780                 default: edt_msg(PDVLIB_MSG_WARNING, "invalid pclock_speed value for async\n");
00781             }
00782 
00783             if (bits)
00784                 edt_reg_write(edt_p, PDV_ROICTL, roictl | bits);
00785                 
00786         }
00787         else if (dd_p->pclock_speed < 1)
00788         {
00789             if (pdv_is_cameralink(edt_p))
00790                     dd_p->pclock_speed = 20;
00791             else dd_p->pclock_speed = 5;
00792         }
00793 
00794         if (dd_p->double_rate)
00795         {
00796             u_int   roictl = edt_reg_read(edt_p, PDV_ROICTL) | PDV_RIOCTL_PCLKSEL_DBL_CAM;
00797 
00798             edt_reg_write(edt_p, PDV_ROICTL,
00799                           roictl);
00800 
00801         }
00802 
00803         if (dd_p->camera_shutter_timing == PDV_DALSA_LS)
00804         {
00805             u_int   roictl = edt_reg_read(edt_p, PDV_ROICTL);
00806 
00807             roictl |= PDV_ROICTL_DALSA_LS;
00808 
00809             edt_reg_write(edt_p, PDV_ROICTL,
00810                           roictl);
00811 
00812         }
00813 
00814         /*
00815          * 'different' dual channel
00816          */
00817         if (dd_p->dual_channel)
00818         {
00819             edt_msg(DEBUG1, "setting dual channel\n");
00820             data_path &= ~PDV_RES0;
00821             data_path |= PDV_RES1;
00822 #if 0                           /* wha...? this seems to BREAK Dalsa
00823                                  * (ca-d4-1024A anyway), so skip it! */
00824             if (dd_p->enable_dalsa)
00825             {
00826                 if (dd_p->extdepth > 8)
00827                     data_path |= PDV_EXT_DEPTH;
00828             }
00829             else
00830 #endif
00831                 data_path |= PDV_EXT_DEPTH;
00832         }
00833         else if (dd_p->swinterlace == PDV_BGGR)
00834         {
00835             /* set for 10 bit ext - 8 bit first pass kludge */
00836             data_path |= PDV_RES0;
00837             data_path &= ~PDV_RES1;
00838         }
00839         else if (dd_p->swinterlace == PDV_BGGR_WORD
00840                  || dd_p->swinterlace == PDV_BGGR_DUAL)
00841         {
00842             /* set for 10 bit ext */
00843             data_path |= PDV_EXT_DEPTH;
00844             data_path |= PDV_RES0;
00845             data_path &= ~PDV_RES1;
00846         }
00847         else
00848         {
00849             if (dd_p->depth > 8)
00850                 data_path |= PDV_EXT_DEPTH;
00851             switch (dd_p->extdepth)
00852             {
00853             case 8:
00854                 data_path &= ~PDV_EXT_DEPTH;
00855                 break;
00856             case 10:
00857                 data_path |= PDV_RES0;
00858                 data_path &= ~PDV_RES1;
00859                 break;
00860             case 12:
00861                 data_path &= ~PDV_RES0;
00862                 data_path &= ~PDV_RES1;
00863                 break;
00864             case 14:
00865                 data_path |= PDV_RES0;
00866                 data_path |= PDV_RES1;
00867                 break;
00868             case 16:
00869                 data_path &= ~PDV_RES0;
00870                 data_path |= PDV_RES1;
00871                 break;
00872             }
00873         }
00874 
00875         if (dd_p->camera_shutter_timing == AIA_MCL_100US)
00876             data_path |= PDV_MULTIPLIER_100US;
00877 
00878         edt_msg(DEBUG2, "DATA_PATH %x\n", data_path);
00879         dep_wait(edt_p);
00880         edt_reg_write(edt_p, PDV_DATA_PATH, data_path);
00881         dd_p->datapath_reg = data_path;
00882         edt_set_dependent(edt_p, dd_p);
00883     }
00884 
00885     /* new aia */
00886     if (dd_p->xilinx_rev >= 1 && dd_p->xilinx_rev <= 32)
00887     {
00888         int util2 = dd_p->util2;
00889 
00890         /*
00891          * set shift/mask (except n/a on cameralink)
00892          */
00893         if (!pdv_is_cameralink(edt_p))
00894         {
00895             if (dd_p->shift == NOT_SET)
00896             {
00897                 int     tmpdepth;
00898 
00899                 if (dd_p->depth == 24)
00900                     tmpdepth = 8;
00901                 else
00902                     tmpdepth = dd_p->depth;
00903 
00904                 /*
00905                  * shift gets a bit weird for DVC -- the DVK and DV44 cables are
00906                  * wired differently, and the older DVK is yet a third case --
00907                  * punt on that one and try to handle the first two as best we we
00908                  * can. Worst case will be that someone will need to use explicit
00909                  * shift in the in the config file if they have a specific cable.
00910                  */
00911                 if (pdv_is_dvc(edt_p))
00912                 {
00913                     edt_msg(DEBUG1, "auto-setting shift for dvc\n");
00914 
00915                     if (edt_p->devid == PDV44_ID)
00916                         dd_p->shift = (16 - dd_p->extdepth) | PDV_AIA_SWAP;
00917                     else if (dd_p->extdepth == 12)      /* dvk 12-bit cable */
00918                     {
00919                         dd_p->shift = 2;
00920                     }
00921                     else
00922                         dd_p->shift = 0;
00923                 }
00924                 /*
00925                  * not set in config so calculate default for non-cameralink
00926                  */
00927                 else
00928                 {
00929                     dd_p->shift = 16 - dd_p->extdepth;
00930                     dd_p->shift |= PDV_AIA_SWAP;
00931                 }
00932 
00933                 /*
00934                  * since shift was not set, check mask as well to see if it
00935                  * appears not to have been set either (0xffff) and set it too
00936                  */
00937                 if (dd_p->mask == 0xffff)
00938                 {
00939                     dd_p->mask = (u_int) (0x0000ffff >> (16 - tmpdepth));
00940                     if (pdv_is_dvc(edt_p))
00941                         edt_msg(DEBUG1, "auto-setting mask for dvc\n");
00942                     else
00943                         edt_msg(DEBUG1, "auto-set shift/mask to %02x/%02x (AIA/swap)\n", dd_p->shift, dd_p->mask);
00944                 }
00945                 else
00946                     edt_msg(DEBUG1, "auto-set shift to %02x (AIA/swap)\n", dd_p->shift);
00947             }
00948 
00949             edt_msg(DEBUG2, "PDV_SHIFT %x\n", dd_p->shift);
00950             dep_wait(edt_p);
00951             edt_reg_write(edt_p, PDV_SHIFT, dd_p->shift);
00952             edt_msg(DEBUG2, "PDV_MASK %x\n", dd_p->mask);
00953             dep_wait(edt_p);
00954             edt_reg_write(edt_p, PDV_MASK, dd_p->mask);
00955         }
00956 #if 0
00957         edt_reg_write(edt_p, PDV_LINERATE, dd_p->linerate);
00958         /* Note dd_p->prin has been retired from dependent struct */
00959         edt_reg_write(edt_p, PDV_PRIN, dd_p->prin);
00960 #endif
00961         if (dd_p->photo_trig)
00962             util2 |= PDV_PHOTO_TRIGGER;
00963         if (dd_p->fieldid_trig)
00964             util2 |= PDV_FLDID_TRIGGER;
00965         if (dd_p->acquire_mult)
00966             util2 |= PDV_AQUIRE_MULTIPLE;
00967 
00968         /*
00969          * RS-232 bit -- overloaded on MC4, only applicable to PCI
00970          * DVA or 3v RCI (LVDS or RS422)
00971          */
00972         if ((dd_p->serial_mode == PDV_SERIAL_RS232)
00973          && ((edt_p->devid == PDVA_ID) || (edt_p->devid == PDVFOI_ID) || (edt_is_dvfox(edt_p))))
00974             util2 |= PDV_RX232;
00975 
00976         else if (dd_p->sel_mc4)
00977             util2 |= PDV_SEL_MC4;
00978 
00979         /*
00980          * mc4 is EXPEXSYNC on camera link, so do it whether or not (the nearly obsolete)
00981          * SEL_MC4 is specified
00982          */
00983         if (dd_p->mc4) /* alias EXPEXSYNC on pcidv c-link */
00984             util2 |= PDV_MC4;
00985 
00986 #if 0
00987         if (dd_p->sim_enable)
00988             util2 |= PDV_SIMEN;
00989         if (dd_p->xilinx_clk)
00990             util2 |= PDV_XOSCSEL;
00991         if (dd_p->linerate)
00992             util2 |= PDV_LINESCAN;
00993 #endif
00994 
00995         if (dd_p->dbl_trig)
00996             util2 |= PDV_DBL_TRIG;
00997         if (dd_p->pulnix)
00998             util2 |= PDV_PULNIX;
00999 
01000 
01001         dd_p->util2 = util2;
01002         edt_msg(DEBUG2, "PDV_UTIL2 %x\n", util2);
01003         dep_wait(edt_p);
01004         edt_reg_write(edt_p, PDV_UTIL2, util2);
01005     }
01006 
01007     if (dd_p->byteswap == NOT_SET)
01008     {
01009         if (edt_little_endian())
01010             dd_p->byteswap = 0;
01011         else
01012             dd_p->byteswap = 1;
01013     }
01014 
01015     /* set Byteswap/ Hwpad */
01016     {
01017         int     padword = 0;
01018 
01019         padword = dd_p->hwpad << 1;
01020 
01021         if (dd_p->byteswap)
01022             padword |= PDV_BSWAP;
01023         if (dd_p->shortswap)
01024             padword |= PDV_SSWAP;
01025         if (dd_p->disable_mdout)
01026             padword |= PDV_DISABLEMD;
01027         if (dd_p->gendata)
01028             padword |= PDV_GENDATA;
01029         if (dd_p->skip)
01030             padword |= PDV_SKIP;
01031 
01032         edt_msg(DEBUG2, "PAD_SWAP %x\n", padword);
01033         dep_wait(edt_p);
01034         edt_reg_write(edt_p, PDV_BYTESWAP, padword);
01035     }
01036 
01037 
01038     /* xybion only (for now) uses fixedlen */
01039     if (dd_p->fixedlen)
01040     {
01041         /* #define SWAPEM 1 */
01042 #if SWAPEM
01043         unsigned short val = dd_p->fixedlen;
01044         unsigned short tmp = ((val & 0xff) << 8) | ((val & 0xff00) >> 8);
01045 
01046         edt_msg(DEBUG2, "FIXEDLEN %x\n", tmp);
01047         dep_wait(edt_p);
01048         edt_reg_write(edt_p, PDV_FIXEDLEN, tmp);
01049 #else
01050 
01051         edt_msg(DEBUG2, "FIXEDLEN %x\n", dd_p->fixedlen);
01052         dep_wait(edt_p);
01053         edt_reg_write(edt_p, PDV_FIXEDLEN, dd_p->fixedlen);
01054 #endif
01055     }
01056 
01057 
01058     edt_msg(DEBUG2, "MODE_CNTL %x\n", dd_p->mode_cntl_norm);
01059     dep_wait(edt_p);
01060     edt_reg_write(edt_p, PDV_MODE_CNTL, dd_p->mode_cntl_norm);
01061     dep_wait(edt_p);
01062 
01063 
01064     if (edt_p->devid == PDVFOI_ID)
01065     {
01066         if (strlen(dd_p->foi_init) > 0)
01067         {
01068             edt_msg(DEBUG1, "sending foi init commands....");
01069             send_foi_commands(edt_p, dd_p->foi_init);
01070         }
01071     }
01072     else
01073         edt_reset_serial(edt_p);
01074 
01075     /* set waitc */
01076     if (dd_p->serial_waitc == NOT_SET)
01077         pdv_set_waitchar(edt_p, 0, 0);
01078     else
01079         pdv_set_waitchar(edt_p, 1, (u_char)dd_p->serial_waitc);
01080 
01081     if (dd_p->user_timeout == NOT_SET && edt_p->devid != PDVFOI_ID)
01082     {
01083         dd_p->user_timeout = 0; /* user_set will be the real flag */
01084         pdv_auto_set_timeout(edt_p);
01085     }
01086     else
01087         pdv_set_timeout(edt_p, dd_p->user_timeout);
01088 
01089     if (dd_p->timeout != NOT_SET)
01090         edt_set_rtimeout(edt_p, dd_p->timeout);
01091 
01092     pdv_set_defaults(edt_p);
01093     check_camera_values(edt_p, dd_p);
01094 
01095     do_xregwrites(edt_p, dd_p);
01096 
01097     /*
01098      * final stuff (none applicable to CL2 sim) 
01099      */
01100     if (!(edt_is_dvcl2(edt_p) && dd_p->sim_enable))
01101     {
01102         check_terminator(dd_p->serial_term);
01103 
01104         if ((dd_p->camera_shutter_timing == SPECINST_SERIAL)
01105             || (dd_p->camera_shutter_speed == SPECINST_SERIAL)
01106             || (dd_p->camera_download == SPECINST_SERIAL))
01107             dd_p->force_single = 1;
01108 
01109         if (dd_p->camera_download == SPECINST_SERIAL)
01110         {
01111             if ((DD_P_CAMERA_DOWNLOAD_FILE[0])
01112                 && ((ret = specinst_download(edt_p, DD_P_CAMERA_DOWNLOAD_FILE)) == 0))
01113                 if (DD_P_CAMERA_COMMAND_FILE[0])
01114                     ret = specinst_setparams(edt_p, DD_P_CAMERA_COMMAND_FILE);
01115             if (ret != 0)
01116                 return ret;
01117         }
01118 
01119         if (strlen(dd_p->serial_init) > 0)
01120             serial_init(edt_p, dd_p);
01121 
01122         if (strlen(dd_p->xilinx_init) > 0)
01123             send_xilinx_commands(edt_p, dd_p->xilinx_init);
01124 
01125         if (dd_p->frame_timing != 0)
01126             pdv_set_frame_period(edt_p, dd_p->frame_period, dd_p->frame_timing);
01127 
01128         if (p_edtinfo->startdma != NOT_SET)
01129             edt_startdma_action(edt_p, p_edtinfo->startdma);
01130         else
01131             edt_startdma_action(edt_p, EDT_ACT_ALWAYS);
01132         if (p_edtinfo->enddma != NOT_SET)
01133             edt_enddma_action(edt_p, p_edtinfo->enddma);
01134         if (p_edtinfo->flushdma != NOT_SET)
01135             edt_set_firstflush(edt_p, p_edtinfo->flushdma);
01136         else
01137             edt_set_firstflush(edt_p, EDT_ACT_ONCE);
01138     }
01139 
01140 
01141     return 0;
01142 }
01143 
01144 
01145 
01146 #ifdef _NT_
01147 #define popen(cmd, mode) _popen(cmd, mode)
01148 #define pclose(cmd) _pclose(cmd)
01149 #define BITLOAD "bitload"
01150 #else
01151 #define BITLOAD "./bitload"
01152 #endif
01153 
01154 /* find id string, starting with "id:". If found return 1, else 0 */
01155 int
01156 findid(char *buf, char *idstr)
01157 {
01158     if (strncmp(buf, "id:", 3) == 0)
01159     {
01160 #if 0
01161         char   *dp = idstr;
01162         char   *p = strchr(buf, '"');
01163         char   *pp = strrchr(p, '"');
01164 
01165         for (; p != pp; p++)
01166             *dp++ = *p;
01167 #endif
01168         return (sscanf(&buf[4], " \"%[^\"]\"", idstr));
01169     }
01170     return 0;
01171 }
01172 
01173 void
01174 dir_from_path(char *dirstr, char *pathstr)
01175 {
01176     char   *bsp = strrchr(pathstr, '\\');
01177     char   *fsp = strrchr(pathstr, '/');
01178     char   *sp;
01179 
01180     if (bsp > fsp)
01181         sp = bsp;
01182     else
01183         sp = fsp;
01184 
01185     if (sp != NULL)
01186     {
01187         strncpy(dirstr, pathstr, sp - pathstr);
01188         dirstr[sp - pathstr] = '\0';
01189     }
01190     else
01191         *dirstr = '\0';
01192 }
01193 
01194 /*
01195  * return 1 if async bitfile (from name); so that we set roictl
01196  * from pclock speed ONLY if async bitfile
01197  */
01198 int
01199 async_bitfile(EdtDev *edt_p)
01200 {
01201     edt_bitpath  pathbuf;
01202 
01203     edt_get_bitpath(edt_p, pathbuf, sizeof(edt_bitpath)) ;
01204     if (pathbuf[0] && (strstr(pathbuf, "async") != NULL))
01205         return 1;
01206     return 0;
01207 }
01208 
01209 void
01210 fname_from_path(char *fname, char *pathstr)
01211 {
01212     char   *bsp = strrchr(pathstr, '\\');
01213     char   *fsp = strrchr(pathstr, '/');
01214     char   *sp;
01215 
01216     if (bsp > fsp)
01217         sp = bsp;
01218     else
01219         sp = fsp;
01220 
01221     if (sp == NULL)
01222         strcpy(fname, pathstr);
01223     else
01224         strcpy(fname, sp + 1);
01225 }
01226 
01227 /*
01228  * check serial_exe to see if it's  Kodak 'i' type, if found then flush the
01229  * serial with a TRM command, and get the idn. Then send serial init string,
01230  * one command at a time.
01231  */
01232 int
01233 serial_init(EdtDev * edt_p, Dependent * dd_p)
01234 {
01235     int     ret;
01236     int     foi = 0;
01237     int     hamamatsu = 0;
01238     int     skip_init = 0;
01239     char    cmdstr[32];
01240     char    resp[257];
01241 
01242     edt_msg(DEBUG1, "sending serial init....\n");
01243 
01244     if (dd_p->serial_format == SERIAL_BINARY)
01245         return serial_init_binary(edt_p, dd_p);
01246 
01247     else if (dd_p->serial_format == SERIAL_BASLER_FRAMING)
01248         return serial_init_basler_binary(edt_p, dd_p);
01249 
01250     else if (dd_p->serial_format == SERIAL_DUNCAN_FRAMING)
01251         return serial_init_duncan_binary(edt_p, dd_p);
01252 
01253     if (edt_p->devid == PDVFOI_ID)
01254         foi = 1;
01255 
01256     if (grepit(dd_p->cameratype, "Hamamatsu") != NULL)
01257         hamamatsu = 1;
01258 
01259     /* first flush any pending/garbage serial */
01260     resp[0] = '\0';
01261     ret = pdv_serial_wait(edt_p, 500, 256);
01262     pdv_serial_read(edt_p, resp, 256);
01263 
01264     /*
01265      * Hamamatsu 4880-8X needs some space after power cycle and also comes
01266      * back before it's really done, so...
01267      */
01268     if (hamamatsu)
01269         propeller_sleep(5);
01270 
01271     edt_msg(DEBUG1, "sending serial init commands to camera....\n");
01272 
01273     /*
01274      * if kodak 'i' camera, send a couple of "TRM?"s just to flush out the
01275      * serial, and send the IDN string to get the camera firmware ID
01276      */
01277     if (pdv_is_kodak_i(edt_p))
01278     {
01279         /* first send a couple of TRM?s to flush and sync */
01280         pdv_serial_command(edt_p, "TRM?");
01281         pdv_serial_wait(edt_p, 500, 40);
01282         pdv_serial_command(edt_p, "TRM?");
01283         pdv_serial_wait(edt_p, 500, 40);
01284         ret = pdv_serial_read(edt_p, resp, 256);
01285 
01286         pdv_serial_command(edt_p, "IDN?");
01287         edt_msg(DEBUG1, "IDN? ");
01288         pdv_serial_wait(edt_p, 1000, 60);
01289         ret = pdv_serial_read(edt_p, resp, 256);
01290         if (ret > 20)
01291             edt_msg(DEBUG1, "%s\n", resp);
01292         else if (ret > 0)
01293             edt_msg(DEBUG1, "%s (unexpected response!)\n", resp);
01294         else
01295         {
01296             edt_msg(DEBUG1, "<no response from camera -- check cables and connections>\n");
01297             skip_init = 1;
01298         }
01299     }
01300 
01301 
01302     if (!skip_init)
01303     {
01304         int    i = 0, just_dots = 1, ms;
01305         char   *lastp = NULL;
01306         char   *p = dd_p->serial_init;
01307 
01308         if (dd_p->serial_init_delay == NOT_SET)
01309             ms = 500;
01310         else ms = dd_p->serial_init_delay;
01311 
01312         /*
01313          * send serial init string
01314          */
01315         cmdstr[0] = '\0';
01316         while (*p)
01317         {
01318             if (i > 31)
01319             {
01320                 edt_msg(EDT_MSG_FATAL, "ERROR: serial command too long\n");
01321                 return -1;
01322             }
01323             if (*p == ':' && lastp && *lastp != '\\')
01324             {
01325                 cmdstr[i] = '\0';
01326                 i = 0;
01327 
01328                 memset(resp, '\0', 257);
01329 
01330