initpcd.c

00001 /* #pragma ident "@(#)initpcd.c 1.32 12/04/07 EDT" */
00002 
00003 #include "edtinc.h"
00004 #include "initedt.h"
00005 #include "initpcd.h"
00006 #include "edt_bitload.h"
00007 #include <stdlib.h>
00008 #include "edt_vco.h"
00009 
00010 void
00011 initedt_usage()
00012 {
00013     puts( "\nUsage: initpcd [-u unit#] [-v] [-p] [-n] -f <file.cfg>\n");
00014     puts("    -u unit#      -  pcd unit select (default unit 0).\n");
00015     puts("    -v            -  Verbose - print lines from cfg file.");
00016     puts("    -p            -  Print commands - print commands after parsing.");
00017     puts("    -n            -  No execute - don't run the commands.");
00018     puts("    -f <file.cfg> -  Configuration file name - required.\n");
00019 
00020     puts("/******************************************************************************");
00021     puts(" *");
00022     puts(" *");
00023     puts(" * User       Commands                                               initpcd(1)");
00024     puts(" *");
00025     puts(" *");
00026     puts(" *");
00027     puts(" * NAME");
00028     puts(" *    initpcd - Configure a PCD board using an ascii configuration file.");
00029     puts(" *");
00030     puts(" * SYNOPSIS");
00031     puts(" *    initpcd [ -u unit# ] [ -v ] [ -p ] [ -n ] [ -N ] -f file.cfg");
00032     puts(" *");
00033     puts(" * DESCRIPTION");
00034     puts(" *    The initpcd command  reads  configuration  commands  from");
00035     puts(" *    the specified file.cfg and executes  them on the selected");
00036     puts(" *    PCD board (default unit 0).  Currently supported commands");
00037     puts(" *    are listed below.  All numeric values are hexadecimal.");
00038     puts(" *");
00039     puts(" *        bitfile:  bitfile_name [basedir]");
00040     puts(" *");
00041     puts(" *            When executed causes the named interface  bitfile");
00042     puts(" *            to be loaded into the PCD.  bitfile_name  can  be");
00043     puts(" *            a simple name or the path to a bitfile.  The optional");
00044     puts(" *            basedir path specifies where to begin searching for bitfiles.");
00045     puts(" *");
00046     puts(" *        intfc_reg:  hex_offset hex_value");
00047     puts(" *");
00048     puts(" *            Set the 8-bit interface  register  at  offset  to");
00049     puts(" *            hex_value.");
00050     puts(" *");
00051     puts(" *        command_reg:  hex_value");
00052     puts(" *");
00053     puts(" *            Set the 8-bit PCD Command Register to hex_value.");
00054     puts(" *");
00055     puts(" *        dpstat_reg:  hex_value");
00056     puts(" *");
00057     puts(" *            Set the 8-bit PCD Data Path Status Register to hex_value.");
00058     puts(" *");
00059     puts(" *        funct_reg:  hex_value");
00060     puts(" *");
00061     puts(" *            Set the 8-bit PCD Funct Register to hex_value.");
00062     puts(" *");
00063     puts(" *        stat_pol_reg:  hex_value");
00064     puts(" *");
00065     puts(" *            Set the 8-bit PCD Stat Polarity Register to hex_value.");
00066     puts(" *");
00067     puts(" *        config_reg:  hex_value");
00068     puts(" *");
00069     puts(" *            Set the 8-bit PCD Interface Configuration  Register  to");
00070     puts(" *            hex_value.");
00071     puts(" *");
00072     puts(" *        direction_reg:  hex_value");
00073     puts(" *");
00074     puts(" *            Set the 16-bit PCD Direction Register to hex_value.");
00075     puts(" *");
00076     puts(" *        byteswap:  hex_value");
00077     puts(" *");
00078     puts(" *            Enables byteswap if 1, disables byteswap if 0.");
00079     puts(" *");
00080     puts(" *        shortswap:  hex_value");
00081     puts(" *");
00082     puts(" *            Enables shortswap if 1, disables shortswap if 0.");
00083     puts(" *");
00084     puts(" *        byteswap_x86:  hex_value");
00085     puts(" *");
00086     puts(" *            If x86, Enables byteswap if 1, disables byteswap if 0.");
00087     puts(" *");
00088     puts(" *        shortswap_x86:  hex_value");
00089     puts(" *");
00090     puts(" *            If x86, Enables shortswap if 1, disables short swap if 0.");
00091     puts(" * ");
00092     puts(" *        byteswap_sun:  hex_value");
00093     puts(" *");
00094     puts(" *            If sun, Enables byteswap if 1, disables byteswap if 0.");
00095     puts(" *");
00096     puts(" *        shortswap_sun:  hex_value");
00097     puts(" *");
00098     puts(" *            If sun, Enables shortswap if 1, disables shortswap if 0.");
00099     puts(" *");
00100     puts(" *        ssd_msb_first:  hex_value");
00101     puts(" *");
00102     puts(" *            Enables most significant bit first if 1, disables if 0.");
00103     puts(" *            Works on all SSD configurations except the GPSSD16.");
00104     puts(" *");
00105     puts(" *        ssd_chanbits:  hex_value");
00106     puts(" *");
00107     puts(" *            Sets the number of bits per serial channel.");
00108     puts(" *            Works on all SSD configurations except the GPSSD16.");
00109     puts(" *");
00110     puts(" *        ssd16_chen_reg:  hex_value16");
00111     puts(" *");
00112     puts(" *            Sets the SSD16_CHEN channel enable bit register.");
00113     puts(" *            Works on all SSD16 configurations.");
00114     puts(" *");
00115     puts(" *        ssd16_chdir_reg:  hex_value16");
00116     puts(" *");
00117     puts(" *            Sets the SSD16_CHDIR channel direction bit register.");
00118     puts(" *            Works on all SSD16 configurations.");
00119     puts(" *");
00120     puts(" *        ssd16_chedge_reg:  hex_value16");
00121     puts(" *");
00122     puts(" *            Sets the SSD16_CHEDGE channel edge bit register.");
00123     puts(" *            Works on all SSD16 configurations.");
00124     puts(" *");
00125     puts(" *        ssd16_chdata_invert:  hex_value16");
00126     puts(" *");
00127     puts(" *            Sets the ssd16 channel data invert register.");
00128     puts(" *            Works on differential boards using ssd16io FPGA");
00129     puts(" *            configurations.");
00130     puts(" *");
00131     puts(" *        ssd16_idle_pattern:  hex_value32");
00132     puts(" *");
00133     puts(" *            Sets the ssd16 idle pattern register.");
00134     puts(" *            Works on differential boards using ssd16io FPGA");
00135     puts(" *            configurations.");
00136     puts(" *");
00137     puts(" *        combo_diff_clk_pol:  hex_value8");
00138     puts(" *");
00139     puts(" *            Sets the Combo channel differential clock polarity register.");
00140     puts(" *            Works on all Combo boards using the combo16io FPGA");
00141     puts(" *            configurations.");
00142     puts(" *");
00143     puts(" *        combo_diff_data_inv:  hex_value8");
00144     puts(" *");
00145     puts(" *            Sets the Combo channel differential data invert register.");
00146     puts(" *            Works on all Combo boards using the combo16io FPGA");
00147     puts(" *            configurations.");
00148     puts(" *");
00149     puts(" *        pll_clock_freq:  floating_value");
00150     puts(" *");
00151     puts(" *            Programs the PLL clock frequency to closely match");
00152     puts(" *            the real value provided.");
00153     puts(" *");
00154     puts(" *        flush_fifo:  hex_value");
00155     puts(" *");
00156     puts(" *            Flush the PCD fifo after configuration is complete.");
00157     puts(" *");
00158     puts(" *        msleep:  floating_value");
00159     puts(" *");
00160     puts(" *            Pause floating_value miliseconds");
00161     puts(" *");
00162     puts(" *        run_program:  path_value");
00163     puts(" *");
00164     puts(" *            Run the specified program and arguments from a shell.");
00165     puts(" *");
00166     puts(" *        run_command:  path_value");
00167     puts(" *");
00168     puts(" *            Run the specified command and arguments from a shell,");
00169     puts(" *            but with the argument \"-u N\" where N is the unit number");
00170     puts(" *            initpcd is running on.");
00171     puts(" *");
00172     puts(" * OPTIONS");
00173     puts(" *    -u unit#  Selects the PCD board number to configure.  Default 0.");
00174     puts(" *");
00175     puts(" *    -v        Print all actions and warnings.");
00176     puts(" *");
00177     puts(" *    -p        Print the table of commands from the .cfg file.");
00178     puts(" *");
00179     puts(" *    -n        Don't execute any commands.  Useful to check  .cfg");
00180     puts(" *              file syntax or with the -p command.");
00181     puts(" *");
00182     puts(" *    -N        Don't load the Xilinx bitfile, but do everything else.");
00183     puts(" *              Useful for configuring after the Xilinx has been loaded.");
00184     puts(" *");
00185     puts(" *    -f file.cfg  Specifies the configuration  file  from  which");
00186     puts(" *                 commands are read.");
00187     puts(" *");
00188     puts(" ******************************************************************************/");
00189     puts("");
00190     }
00191 
00192 /*
00193  * ADDING NEW COMMANDS
00194  *
00195  *      New commands may be added by to initpcd by editing initpcd.c,
00196  *      adding a new command function to the func_cmd_*() declarations,
00197  *      a new line to the commands[] table, then adding the definition
00198  *      for func_cmd_*().  Search for the string \"ADD\" in initpcd.c.
00199  *
00200  *      Other EDT boards may be supported or new configuration programs
00201  *      created by completely replacing the set of commands in initpcd.c.
00202  *
00203  * FILES
00204  *      /opt/EDTpcd/(*).cfg, /opt/EDTpcd/initpcd.c, /opt/EDTpcd/initedt.c.
00205  */
00206 
00207 /*
00208  * ADD new command function declarations here.  Commands use and return an int.
00209  */
00210 int func_bitfile(cmd_operator *cmd_ptr) ;
00211 int func_intfc_reg(cmd_operator *cmd_ptr) ;
00212 int func_command_reg(cmd_operator *cmd_ptr) ;
00213 int func_dpstat_reg(cmd_operator *cmd_ptr) ;
00214 int func_funct_reg(cmd_operator *cmd_ptr) ;
00215 int func_stat_pol_reg(cmd_operator *cmd_ptr) ;
00216 int func_config_reg(cmd_operator *cmd_ptr) ;
00217 int func_direction_reg(cmd_operator *cmd_ptr) ;
00218 int func_ssd16_chen_reg(cmd_operator *cmd_ptr) ;
00219 int func_ssd16_chdir_reg(cmd_operator *cmd_ptr) ;
00220 int func_ssd16_chedge_reg(cmd_operator *cmd_ptr) ;
00221 int func_byteswap(cmd_operator *cmd_ptr) ;
00222 int func_byteswap86(cmd_operator *cmd_ptr) ;
00223 int func_byteswapsun(cmd_operator *cmd_ptr) ;
00224 int func_shortswap(cmd_operator *cmd_ptr) ;
00225 int func_shortswap86(cmd_operator *cmd_ptr) ;
00226 int func_shortswapsun(cmd_operator *cmd_ptr) ;
00227 int func_ssd_msb_first(cmd_operator *cmd_ptr) ;
00228 int func_ssd_chanbits(cmd_operator *cmd_ptr) ;
00229 int func_pll_clock_freq(cmd_operator *cmd_ptr) ;
00230 int func_flush_fifo(cmd_operator *cmd_ptr) ;
00231 int func_run_program(cmd_operator *cmd_ptr) ;
00232 int func_run_command(cmd_operator *cmd_ptr) ;
00233 int func_msleep(cmd_operator *cmd_ptr) ;
00234 int func_ssd16_chdata_invert(cmd_operator *cmd_ptr) ;
00235 int func_ssd16_idle_pattern(cmd_operator *cmd_ptr) ;
00236 int func_combo_diff_clk_pol(cmd_operator *cmd_ptr) ;
00237 int func_combo_diff_data_inv(cmd_operator *cmd_ptr) ;
00238 
00239 /*
00240  * Table of commands.  Each entry has a unique name and a type specified.
00241  *
00242  */
00243 cmd_operator commands[] = 
00244 
00245 /*
00246  * The cmd_type determines how command arguments in the .cfg file will be
00247  * processed:
00248  *
00249  *      1 = expect one hex integer
00250  *      2 = expect two hex integers
00251  *      3 = expect one floating point number
00252  *      4 = expect one pathname
00253  *
00254  *    Command name:          arg_type:       cmd_func:
00255  */
00256 {
00257         { "bitfile",               4,           func_bitfile            },
00258 
00259         { "intfc_reg",             2,           func_intfc_reg          },
00260         { "command_reg",           1,           func_command_reg        },
00261         { "dpstat_reg",            1,           func_dpstat_reg         },
00262         { "funct_reg",             1,           func_funct_reg          },
00263         { "stat_pol_reg",          1,           func_stat_pol_reg       },
00264         { "config_reg",            1,           func_config_reg         },
00265         { "direction_reg",         1,           func_direction_reg      },
00266         { "ssd16_chen_reg",        1,           func_ssd16_chen_reg     },
00267         { "ssd16_chdir_reg",       1,           func_ssd16_chdir_reg    },
00268         { "ssd16_chedge_reg",      1,           func_ssd16_chedge_reg   },
00269         { "ssd16_chdata_invert",   1,           func_ssd16_chdata_invert},
00270         { "ssd16_idle_pattern",    1,           func_ssd16_idle_pattern },
00271         { "combo_diff_clk_pol",    1,           func_combo_diff_clk_pol },
00272         { "combo_diff_data_inv",   1,           func_combo_diff_data_inv},
00273 
00274         { "byteswap",              1,           func_byteswap           },
00275         { "shortswap",             1,           func_shortswap          },
00276         { "byteswap_x86",          1,           func_byteswap86 },
00277         { "shortswap_x86",         1,           func_shortswap86        },
00278         { "byteswap_sun",          1,           func_byteswapsun        },
00279         { "shortswap_sun",         1,           func_shortswapsun       },
00280         { "ssd_msb_first",         1,           func_ssd_msb_first      },
00281         { "ssd_chanbits",          1,           func_ssd_chanbits       },
00282         { "pll_clock_freq",        3,           func_pll_clock_freq     },
00283         { "flush_fifo",            1,           func_flush_fifo         },
00284         { "run_program",           4,           func_run_program        },
00285         { "run_command",           4,           func_run_command        },
00286         { "msleep",                3,           func_msleep             },
00287 
00288 /*                      ADD new commands entries here.                      */
00289 };
00290 
00291 
00292 /******************************************************************************
00293  *                                                                            *
00294  * Housekeeping stuff.  Leave these alone; initedt.c uses them to access  *
00295  * the command table.                                                         *
00296  *                                                                            *
00297  ******************************************************************************/
00298 
00299 extern int initedt_verbose ;
00300 extern int initedt_load_bitfile ;
00301 extern int edt_unit     ;
00302 extern EdtDev *initedt_p ;
00303 
00304 
00305 cmd_operator
00306 get_cmd_copy(int cmd_index)
00307 {
00308     return commands[cmd_index] ;
00309 }
00310 
00311 char *
00312 get_cmd_name(int cmd_index)
00313 {
00314     return commands[cmd_index].cmd_name ;
00315 }
00316 
00317 int
00318 cmd_table_entries()
00319 {
00320     return (sizeof(commands) / sizeof(cmd_operator)) ;
00321 }
00322 
00323 
00324 /******************************************************************************
00325  *                                                                            *
00326  * These functions carry out the work for each line found in the config       *
00327  * file.  Add functions for new commands here.                                *
00328  *                                                                            *
00329  ******************************************************************************/
00330 
00331 int
00332 func_bitfile(cmd_operator *cmd_ptr)
00333 {
00334     char *p, *path = ".";
00335     int ret = 0 ;
00336 
00337     if (initedt_verbose)
00338         printf("\tload_bitfile: %s\n", (initedt_load_bitfile) ? "Yes" : "No") ;
00339 
00340     if (initedt_load_bitfile)
00341     {
00342         int level = 0 ;
00343 
00344         level |= EDTAPP_MSG_INFO_1;
00345         level |= EDTLIB_MSG_INFO_1;
00346         edt_msg_set_level(edt_msg_default_handle(), level);
00347 
00348         if ((p = strchr(cmd_ptr->cmd_pathval, ' '))
00349          || (p = strchr(cmd_ptr->cmd_pathval, '\t')))
00350         {
00351             *p++ = '\0' ;
00352 
00353             while (*p == ' ' || *p == '\t')
00354                 ++p ;
00355 
00356             if (*p != '\n' && *p != '\r')
00357                 path = p ;
00358         }
00359 
00360         if (initedt_verbose)
00361             printf("\tbitfile:  %s  path:  %s\n", cmd_ptr->cmd_pathval, path) ;
00362         
00363         if ((ret = edt_bitload(initedt_p, path, cmd_ptr->cmd_pathval, 0, 0)) != 0)
00364             fputs("bitload: could not load bitfile.\n", stderr) ;
00365     }
00366 
00367     return ret ;
00368 }
00369 
00370 int
00371 func_intfc_reg(cmd_operator *cmd_ptr)
00372 {
00373     if (initedt_verbose) printf(
00374                 "\tpcd set intfc reg:  offset 0x%x, val 0x%x\n",
00375                                           cmd_ptr->cmd_intval1,
00376                                           cmd_ptr->cmd_intval2) ;
00377     edt_intfc_write(initedt_p, PCD_CMD + cmd_ptr->cmd_intval1,
00378                                  (u_char) cmd_ptr->cmd_intval2) ;
00379 
00380     if (initedt_verbose) printf("\treadback:  offset 0x%x val 0x%x\n\n",
00381                                           cmd_ptr->cmd_intval1,
00382           edt_intfc_read(initedt_p,     PCD_CMD + cmd_ptr->cmd_intval1));
00383 
00384          return 0;
00385 }
00386 
00387 
00388 int
00389 func_command_reg(cmd_operator *cmd_ptr)
00390 {
00391     if (initedt_verbose) printf("\tpcd_set_cmd(0x%x)\n",
00392                                           cmd_ptr->cmd_intval1) ;
00393     pcd_set_cmd(initedt_p, (u_char)     cmd_ptr->cmd_intval1) ;
00394 
00395     if (initedt_verbose) printf("\treadback:  0x%x\n\n", pcd_get_cmd(initedt_p)) ;
00396 
00397          return 0;
00398 }
00399 
00400 
00401 int 
00402 func_dpstat_reg(cmd_operator *cmd_ptr)
00403 {
00404     if (initedt_verbose) printf("\tpcd set dpstat:  0x%x\n",
00405                                           cmd_ptr->cmd_intval1) ;
00406     edt_intfc_write(initedt_p, PCD_DATA_PATH_STAT,
00407                                  (u_char) cmd_ptr->cmd_intval1) ;
00408     if (initedt_verbose) printf("\treadback:  0x%x\n\n",
00409                         edt_intfc_read(initedt_p, PCD_DATA_PATH_STAT)) ;
00410          
00411          return 0;
00412 }
00413 
00414 
00415 int
00416 func_funct_reg(cmd_operator *cmd_ptr)
00417 {
00418     if (initedt_verbose) printf("\tpcd_set_funct(0x%x)\n",
00419                                           cmd_ptr->cmd_intval1) ;
00420     pcd_set_funct(initedt_p, (u_char) cmd_ptr->cmd_intval1) ;
00421 
00422     if (initedt_verbose) printf("\treadback:  0x%x\n\n",
00423                                              pcd_get_funct(initedt_p)) ;
00424          return 0;
00425 }
00426 
00427 
00428 int
00429 func_stat_pol_reg(cmd_operator *cmd_ptr)
00430 {
00431     if (initedt_verbose) printf("\tpcd_set_stat_polarity(0x%x)\n",
00432                                           cmd_ptr->cmd_intval1) ;
00433     pcd_set_stat_polarity(initedt_p, (u_char) cmd_ptr->cmd_intval1) ;
00434 
00435     if (initedt_verbose) printf("\treadback:  0x%x\n\n",
00436                                      pcd_get_stat_polarity(initedt_p)) ;
00437          return 0;
00438 }
00439 
00440 
00441 int 
00442 func_config_reg(cmd_operator *cmd_ptr)
00443 {
00444     if (initedt_verbose) printf("\tpcd set config:  0x%x\n",
00445                             (u_char)      cmd_ptr->cmd_intval1) ;
00446     edt_intfc_write(initedt_p, PCD_CONFIG,
00447                             (u_char)      cmd_ptr->cmd_intval1) ;
00448 
00449     if (initedt_verbose) printf("\treadback:  0x%x\n\n",
00450                                 edt_intfc_read(initedt_p, PCD_CONFIG)) ;
00451 
00452          return 0;
00453 }
00454 
00455 
00456 int 
00457 func_direction_reg(cmd_operator *cmd_ptr)
00458 {
00459     if (initedt_verbose)
00460         printf("\tpcd_set_direction(0x%x)\n", cmd_ptr->cmd_intval1) ;
00461 
00462     edt_intfc_write(initedt_p, PCD_DIRA,
00463                         (u_char) (cmd_ptr->cmd_intval1 & 0xff));
00464     edt_intfc_write(initedt_p, PCD_DIRB,
00465                 (u_char) ((cmd_ptr->cmd_intval1 >> 8) & 0xff)) ;
00466     if (initedt_verbose)
00467         printf("\treadback: 0x%x\n\n", edt_get_direction(initedt_p)) ;
00468 
00469          return 0;
00470 }
00471 
00472 
00473 int 
00474 func_ssd16_chen_reg(cmd_operator *cmd_ptr)
00475 {
00476     if (initedt_verbose)
00477         printf("\tpcd set SSD16_CHEN 0x%x\n", cmd_ptr->cmd_intval1);
00478 
00479     edt_intfc_write(initedt_p, SSD16_CHENL,
00480                         (u_char) (cmd_ptr->cmd_intval1 & 0xff));
00481     edt_intfc_write(initedt_p, SSD16_CHENH,
00482                 (u_char)  ((cmd_ptr->cmd_intval1 >> 8) & 0xff));
00483     if (initedt_verbose)
00484         printf("\treadback: 0x%x\n\n",
00485              (edt_intfc_read(initedt_p, SSD16_CHENH) << 8)
00486             | edt_intfc_read(initedt_p, SSD16_CHENL)) ;
00487 
00488          return 0;
00489 }
00490 
00491 
00492 int
00493 func_ssd16_chdir_reg(cmd_operator *cmd_ptr)
00494 {
00495     if (initedt_verbose)
00496         printf("\tpcd set SSD16_CHDIR 0x%x\n", cmd_ptr->cmd_intval1);
00497 
00498     edt_intfc_write(initedt_p, SSD16_CHDIRL,
00499             (u_char) (cmd_ptr->cmd_intval1 &    0xff));
00500     edt_intfc_write(initedt_p, SSD16_CHDIRH,
00501             (u_char) ((cmd_ptr->cmd_intval1 >> 8) & 0xff));
00502 
00503     if (initedt_verbose)
00504         printf("\treadback: 0x%x\n\n",
00505                      (edt_intfc_read(initedt_p, SSD16_CHDIRH) << 8)
00506                     | edt_intfc_read(initedt_p, SSD16_CHDIRL)) ;
00507 
00508          return 0;
00509 }
00510 
00511 
00512 int
00513 func_ssd16_chedge_reg(cmd_operator *cmd_ptr)
00514 {
00515     if (initedt_verbose) printf("\tpcd set SSD16_CHEDGE 0x%x\n",
00516                                             cmd_ptr->cmd_intval1) ;
00517     edt_intfc_write(initedt_p, SSD16_CHEDGEL,
00518                           (u_char) (cmd_ptr->cmd_intval1 & 0xff)) ;
00519     edt_intfc_write(initedt_p, SSD16_CHEDGEH,
00520                    (u_char) ((cmd_ptr->cmd_intval1 >> 8) & 0xff)) ;
00521     if (initedt_verbose)
00522         printf("\treadback: 0x%x\n\n",
00523              (edt_intfc_read(initedt_p, SSD16_CHEDGEH) << 8)
00524             | edt_intfc_read(initedt_p, SSD16_CHEDGEL)) ;
00525 
00526      return 0;
00527 }
00528 
00529 
00530 int
00531 func_ssd16_chdata_invert(cmd_operator *cmd_ptr)
00532 {
00533     if (initedt_verbose)
00534         printf("\tpcd set SSD16_CHINVERT        0x%x\n", cmd_ptr->cmd_intval1);
00535 
00536     edt_reg_write(initedt_p, SSD16_CHINVERT, cmd_ptr->cmd_intval1);
00537 
00538     if (initedt_verbose)
00539         printf("\treadback: 0x%x\n\n", edt_reg_read(initedt_p,
00540                                                 SSD16_CHINVERT));
00541      return 0;
00542 }
00543 
00544 
00545 int
00546 func_ssd16_idle_pattern(cmd_operator *cmd_ptr)
00547 {
00548     if (initedt_verbose)
00549         printf("\tpcd set SSD16_IDLE_PAT        0x%x\n", cmd_ptr->cmd_intval1);
00550 
00551     edt_reg_write(initedt_p, SSD16_IDLE_PAT, cmd_ptr->cmd_intval1);
00552 
00553     if (initedt_verbose)
00554         printf("\treadback: 0x%x\n\n",
00555             edt_reg_read(initedt_p, SSD16_IDLE_PAT));
00556 
00557      return 0;
00558 }
00559 
00560 
00561 int
00562 func_combo_diff_clk_pol(cmd_operator *cmd_ptr)
00563 {
00564     if (initedt_verbose)
00565         printf("\tpcd set COMBO_DIFF_CLK_POL    0x%x\n", cmd_ptr->cmd_intval1);
00566 
00567     edt_reg_write(initedt_p, COMBO_DIFF_CLK_POL, cmd_ptr->cmd_intval1);
00568 
00569     if (initedt_verbose)
00570         printf("\treadback: 0x%x\n\n",
00571             edt_reg_read(initedt_p, COMBO_DIFF_CLK_POL));
00572 
00573      return 0;
00574 }
00575 
00576 
00577 int
00578 func_combo_diff_data_inv(cmd_operator *cmd_ptr)
00579 {
00580     if (initedt_verbose)
00581         printf("\tpcd set COMBO_DIFF_DATA_INV   0x%x\n", cmd_ptr->cmd_intval1);
00582 
00583     edt_reg_write(initedt_p, COMBO_DIFF_DATA_INV, cmd_ptr->cmd_intval1);
00584 
00585     if (initedt_verbose)
00586         printf("\treadback: 0x%x\n\n",
00587             edt_reg_read(initedt_p, COMBO_DIFF_DATA_INV));
00588 
00589      return 0;
00590 }
00591 
00592 
00593 int
00594 func_byteswap(cmd_operator *cmd_ptr)
00595 {
00596     u_char  config;
00597 
00598     config = edt_intfc_read(initedt_p, PCD_CONFIG);
00599 
00600     if (initedt_verbose)
00601         printf("\tset byteswap:  %d\n\n", cmd_ptr->cmd_intval1) ;
00602 
00603     if (cmd_ptr->cmd_intval1)
00604         config |= PCD_BYTESWAP;
00605     else
00606         config &= ~PCD_BYTESWAP;
00607 
00608     edt_intfc_write(initedt_p, PCD_CONFIG, config);
00609 
00610          return 0;
00611 }
00612 
00613 int
00614 func_byteswap86(cmd_operator *cmd_ptr)
00615 {
00616     if (!edt_little_endian()) return 0 ;
00617 
00618     return (func_byteswap(cmd_ptr)) ;
00619 }
00620 
00621 int 
00622 func_byteswapsun(cmd_operator *cmd_ptr)
00623 {
00624     if (edt_little_endian()) return 0 ;
00625 
00626     return (func_byteswap(cmd_ptr)) ;
00627 }
00628 
00629 
00630 int 
00631 func_shortswap(cmd_operator *cmd_ptr)
00632 {
00633     u_char  config;
00634 
00635     config = edt_intfc_read(initedt_p, PCD_CONFIG);
00636 
00637     if (initedt_verbose) printf("\tset shortswap:  %d\n\n",
00638                  cmd_ptr->cmd_intval1) ;
00639 
00640     if (cmd_ptr->cmd_intval1)
00641         config |= PCD_SHORTSWAP;
00642     else
00643         config &= ~PCD_SHORTSWAP;
00644 
00645     edt_intfc_write(initedt_p, PCD_CONFIG, config);
00646          
00647          return 0;
00648 }
00649 
00650 int
00651 func_shortswap86(cmd_operator *cmd_ptr)
00652 {
00653     if (!edt_little_endian()) return 0 ;
00654 
00655     return (func_shortswap(cmd_ptr)) ;
00656 }
00657 
00658 int
00659 func_shortswapsun(cmd_operator *cmd_ptr)
00660 {
00661     if (edt_little_endian()) return 0 ;
00662 
00663     return (func_shortswap(cmd_ptr)) ;
00664 }
00665 
00666 
00667 
00668 int
00669 func_ssd_msb_first(cmd_operator *cmd_ptr)
00670 {
00671     u_char funct = pcd_get_funct(initedt_p);
00672 
00673     if (initedt_verbose) printf("\tset msb_first:  %d\n\n",
00674                  cmd_ptr->cmd_intval1) ;
00675 
00676     if (cmd_ptr->cmd_intval1)
00677         funct |=  0x04 ;
00678     else
00679         funct &= ~0x04 ;
00680 
00681     pcd_set_funct(initedt_p, funct);
00682          return 0;
00683 }
00684 
00685 
00686 
00687 int
00688 func_ssd_chanbits(cmd_operator *cmd_ptr)
00689 {
00690     u_char funct = pcd_get_funct(initedt_p);
00691     int bits = cmd_ptr->cmd_intval1 ;
00692 
00693     if (initedt_verbose) printf("\tset ssd_chanbits:  %d\n\n", bits) ;
00694 
00695     switch (bits)
00696     {
00697     case 1:
00698         {
00699             funct &= ~0x03 ;
00700             break;
00701         }
00702     case 2:
00703         {
00704             funct &= ~0x03 ;
00705             funct |=  0x01 ;
00706             break;
00707         }
00708     case 4:
00709         {
00710             funct |= 0x03 ;
00711             break;
00712         }
00713     default:
00714         {
00715             fprintf(stderr,
00716 "\tssd_chanbits:  illegal value %d.  Must be 1, 2, or 4.  Exiting.\n\n", bits) ;
00717             return -1 ;
00718             break;
00719         }
00720     }
00721 
00722     pcd_set_funct(initedt_p, funct);
00723 
00724     return 0 ;
00725 }
00726 
00727 
00728 int 
00729 func_pll_clock_freq(cmd_operator *cmd_ptr)
00730 {
00731     edt_pll clkset ;
00732 
00733     if (initedt_verbose)
00734         printf("\tpll set clock freq: %f\n\n", cmd_ptr->cmd_realval);
00735 
00736     edt_find_vco_frequency(initedt_p, cmd_ptr->cmd_realval, 0,
00737                                                   &clkset, initedt_verbose) ;
00738     edt_set_out_clk(initedt_p, &clkset);
00739 
00740          return 0;
00741 }
00742 
00743 int
00744 func_flush_fifo(cmd_operator *cmd_ptr)
00745 {
00746     if (cmd_ptr->cmd_intval1)
00747     {
00748         if (initedt_verbose) puts("\tcalling edt_flush_fifo()\n") ;
00749         edt_flush_fifo(initedt_p) ;
00750     }
00751          return 0;
00752 }
00753 
00754 int
00755 func_run_program(cmd_operator *cmd_ptr)
00756 {
00757     if (initedt_verbose)
00758         printf("\trunning \"%s\"\n\n", cmd_ptr->cmd_pathval)    ;
00759 
00760     return edt_system(cmd_ptr->cmd_pathval) ;
00761 }
00762 
00763 #include <string.h>
00764 
00765 int
00766 func_run_command(cmd_operator *cmd_ptr)
00767 {
00768     static char cmd[512], tmp[512] ;
00769     char *p, unit_str[16] ;
00770     int len ;
00771 
00772     strncpy(tmp, cmd_ptr->cmd_pathval, 511) ;
00773 
00774     if ((p = strchr(tmp, ' ')) || (p = strchr(tmp, '\t')))
00775         *p++ = '\0' ;
00776 
00777     strncpy(cmd, tmp, 511) ;
00778     sprintf(unit_str, " -u %d ", edt_unit) ;
00779 
00780     len = strlen(cmd) ;
00781     strncat(cmd, unit_str, 511 - len) ;
00782 
00783     if (p)
00784     {
00785         len = strlen(cmd) ;
00786         strncat(cmd, p, 511 - len) ;
00787     }
00788 
00789     if (initedt_verbose)
00790         printf("\trunning \"%s\"\n\n", cmd)     ;
00791 
00792     return edt_system(cmd) ;
00793 }
00794 
00795 int 
00796 func_msleep(cmd_operator *cmd_ptr)
00797 {
00798     int msecs = (int) cmd_ptr->cmd_realval;
00799 
00800     if (initedt_verbose)
00801         printf("\tsleep %d msec\n\n", msecs);
00802 
00803     edt_msleep(msecs);
00804 
00805      return 0;
00806 }
00807 
00808 int
00809 initpcd_fn(EdtDev *edt_p, char *cfg_file, int no_execute, int no_load_bitfile, int verbose)
00810 {
00811     extern int initedt_load_bitfile ;
00812     extern int initedt_verbose ;
00813     extern EdtDev * initedt_p ;
00814 
00815     initedt_load_bitfile = !no_load_bitfile ;
00816     initedt_p = edt_p ;
00817 
00818     if (input_config_file(cfg_file))
00819         return(-1) ;
00820 
00821     if (verbose) 
00822     {
00823         initedt_verbose = 1 ;
00824         print_cmds() ;
00825     }
00826 
00827     if (!no_execute)
00828         return process_cmds() ;
00829     else
00830         return 1 ;
00831 }
00832 
00833 int
00834 initpcd_str(char *cfg_str, int unit, int verbose)
00835 {
00836     extern int initedt_load_bitfile ;
00837     extern int initedt_verbose ;
00838     extern EdtDev * initedt_p;
00839     int ret;
00840 
00841     edt_unit = unit;
00842 
00843     initedt_p = edt_open("pcd", unit);
00844 
00845     if (initedt_p == NULL)
00846     {
00847         if (verbose) 
00848             edt_perror("initpcd_str: edt_open");
00849         return -1;
00850     }
00851 
00852     initedt_load_bitfile = 1;
00853 
00854     if (input_config_str(cfg_str))
00855         return(-1) ;
00856 
00857     if (verbose) 
00858     {
00859         initedt_verbose = 1 ;
00860         print_cmds() ;
00861     }
00862 
00863     ret = process_cmds() ;
00864 
00865     initedt_verbose = 0 ;
00866     edt_close(initedt_p);
00867 
00868     return ret ;
00869 }
00870 
00871 #include <fcntl.h>
00872 
00873 int
00874 initpcd_file(char *filename, int unit, int nobitload, int verbose)
00875 {
00876     extern int initedt_load_bitfile ;
00877     extern int initedt_verbose ;
00878     extern EdtDev * initedt_p;
00879     FILE *cfg_fp = fopen(filename, "r");
00880     char *cfg_str = NULL;
00881     int filesize = 0, retval = 0;
00882     extern int errno;
00883 
00884     if (cfg_fp)
00885     {
00886         /* Get the size of the .cfg file */
00887         fseek(cfg_fp, 0, SEEK_END);
00888         filesize = ftell(cfg_fp);
00889         rewind(cfg_fp);
00890 
00891         if ((cfg_str = (char *)edt_alloc(filesize + 1)) == NULL)
00892             return -1;
00893 
00894         if (fread(cfg_str, 1, filesize, cfg_fp) != filesize)
00895             return -1;
00896 
00897         cfg_str[filesize] = '\0';
00898 
00899         /*
00900          * Send the config string through the initpcd mechanism.
00901          */
00902         edt_unit = unit;
00903 
00904         initedt_p = edt_open("pcd", unit);
00905 
00906         if (initedt_p == NULL)
00907         {
00908             if (verbose) 
00909                 edt_perror("initpcd_str: edt_open");
00910             return -1;
00911         }
00912 
00913         initedt_load_bitfile = !nobitload;
00914 
00915         if (input_config_str(cfg_str))
00916             return(-1) ;
00917 
00918         if (verbose) 
00919         {
00920             initedt_verbose = 1 ;
00921             print_cmds() ;
00922         }
00923 
00924         retval = process_cmds() ;
00925 
00926         initedt_verbose = 0 ;
00927         edt_close(initedt_p);
00928 
00929 
00930         edt_free((u_char *)cfg_str);
00931 
00932         return retval;
00933     }
00934     else
00935         return -1;
00936 }

Generated on Mon May 12 16:38:53 2008 by  doxygen 1.5.1