vpc6.c

Go to the documentation of this file.
00001 /*********************************************************************
00002   @file
00003   Name:         vpc6.c
00004   Created by:   Pierre-Andre Amaudruz, Chris Ohlmann
00005 
00006   Contents:      Routines for accessing the vpc6 Triumf board
00007 
00008   $Id: vpc6.c 3746 2007-07-10 08:26:11Z amaudruz $
00009 *********************************************************************/
00010 #include <stdio.h>
00011 #include <string.h>
00012 #include "vpc6.h"
00013 
00014 /*****************************************************************/
00015 /*
00016   Read VPC6 Busy state for a particular port.
00017   Port number start with 1
00018 */
00019 int vpc6_isPortBusy(MVME_INTERFACE *mvme, DWORD base, WORD  port)
00020 {
00021   int   cmode, busy;
00022 
00023   mvme_get_dmode(mvme, &cmode);
00024   mvme_set_dmode(mvme, MVME_DMODE_D32);
00025   busy = mvme_read_value(mvme, base+VPC6_SR_RO);
00026   mvme_set_dmode(mvme, cmode);
00027   return (busy & (1 << (port-1)));
00028 }
00029 
00030 /*****************************************************************/
00031 /**
00032  * Setup Preamp type of the board (2 bit per PA)
00033  * 00 : ASD, 01 : Buckeye
00034  */
00035 void vpc6_PATypeWrite(MVME_INTERFACE *mvme, DWORD base, WORD data)
00036 {
00037   int cmode;
00038 
00039   mvme_get_dmode(mvme, &cmode);
00040   mvme_set_dmode(mvme, MVME_DMODE_D32);
00041   data &= 0xFFF;
00042   mvme_write_value(mvme, base+VPC6_CR_RW, data);
00043   mvme_set_dmode(mvme, cmode);
00044   return;
00045 }
00046 
00047 /*****************************************************************/
00048 /**
00049  * Read the 6 AP type of the board (either ASD01 or Buckeye for now.
00050  */
00051 int vpc6_PATypeRead(MVME_INTERFACE *mvme, DWORD base)
00052 {
00053   int cmode, type;
00054 
00055   mvme_get_dmode(mvme, &cmode);
00056   mvme_set_dmode(mvme, MVME_DMODE_D32);
00057   type = mvme_read_value(mvme, base+VPC6_CR_RW);
00058   mvme_set_dmode(mvme, cmode);
00059   return (type & 0xFFF);
00060 }
00061 
00062 /*****************************************************************/
00063 /**
00064  * Read Port type of the board (either ASD01 or Buckeye for now)
00065  * return the type of the requested port
00066  */
00067 int vpc6_PortTypeRead(MVME_INTERFACE *mvme, DWORD base, WORD port)
00068 {
00069   int cmode, type;
00070 
00071   mvme_get_dmode(mvme, &cmode);
00072   mvme_set_dmode(mvme, MVME_DMODE_D32);
00073   type = mvme_read_value(mvme, base+VPC6_CR_RW);
00074   mvme_set_dmode(mvme, cmode);
00075   type  = ((type >> (2*(port-1))) & 0x03);   // ASD or Buck
00076   return (type & 0xFFF);
00077 }
00078 
00079 /*****************************************************************/
00080 /**
00081  * Load full configuration for a given port.
00082  * the port is either ASD01 or Buckeye for now.
00083  */
00084 int vpc6_PortCfgLoad(MVME_INTERFACE *mvme, DWORD base, WORD port)
00085 {
00086   int cmode, action, timeout=100;
00087 
00088   mvme_get_dmode(mvme, &cmode);
00089   mvme_set_dmode(mvme, MVME_DMODE_D32);
00090   if ((port > 0) && (port < 7)) {
00091     action = (0x18) | port;
00092   }
00093   else
00094     return VPC6_PARAM_ERROR;
00095 
00096   do {
00097     if (~(vpc6_isPortBusy(mvme, base, port))) {
00098       // Not busy, load bit string to PA
00099       mvme_write_value(mvme, base+VPC6_CMD_WO, action);
00100       usleep(10000);
00101       mvme_write_value(mvme, base+VPC6_CMD_WO, action);
00102       break;
00103     }
00104     else
00105       usleep(10000);
00106   } while (timeout--);
00107 
00108   if (timeout == 0)
00109     printf("Port %d still busy\n", port);
00110 
00111   mvme_set_dmode(mvme, cmode);
00112   return VPC6_SUCCESS;
00113 }
00114 
00115 /*****************************************************************/
00116 /**
00117  * Retrieve bit string full configuration from a given port.
00118  * Loads bit string into Readback registers that can then be read.
00119  * the port is either ASD01 or Buckeye for now.
00120  */
00121 int vpc6_CfgRetrieve(MVME_INTERFACE *mvme, DWORD base, WORD port)
00122 {
00123   int cmode, action, timeout=100;
00124 
00125   mvme_get_dmode(mvme, &cmode);
00126   mvme_set_dmode(mvme, MVME_DMODE_D32);
00127   if ((port > 0) && (port < 7)) {
00128     action = (0x10) | port;
00129   }
00130 
00131   do {
00132     if (~(vpc6_isPortBusy(mvme, base, port))) {
00133       // Not busy, read bit string from PA
00134       //      printf(" cfg request 0x%x %d\n", base+VPC6_CMD_WO, action);
00135       mvme_write_value(mvme, base+VPC6_CMD_WO, action);
00136       usleep(10000);
00137       mvme_write_value(mvme, base+VPC6_CMD_WO, action);
00138       break;
00139     }
00140     usleep(10000);
00141   } while (timeout--);
00142 
00143   if (timeout == 0)
00144     printf(" Port %d still busy\n", port);
00145 
00146   mvme_set_dmode(mvme, cmode);
00147   return VPC6_SUCCESS;
00148 }
00149 
00150 /*****************************************************************/
00151 /**
00152  * Read the Readback and Display in a readable form the Port setting
00153  * No action to the PA board
00154  */
00155 int vpc6_PortRegRBRead(MVME_INTERFACE *mvme, DWORD base, WORD port)
00156 {
00157   int cmode, timeout=100;
00158   WORD type;
00159   DWORD reg[4];
00160 
00161   mvme_get_dmode(mvme, &cmode);
00162   mvme_set_dmode(mvme, MVME_DMODE_D32);
00163 
00164   do {
00165     if (~(vpc6_isPortBusy(mvme, base, port))) {
00166       type  = mvme_read_value(mvme, base+VPC6_CR_RW);
00167       type  = ((type >> (2*(port-1))) & 0x03);   // ASD or Buck
00168       reg[0] = mvme_read_value(mvme, base+VPC6_RBCK_RO+(0x10*(port-1))+0x00);
00169       reg[1] = mvme_read_value(mvme, base+VPC6_RBCK_RO+(0x10*(port-1))+0x04);
00170       reg[2] = mvme_read_value(mvme, base+VPC6_RBCK_RO+(0x10*(port-1))+0x08);
00171       reg[3] = mvme_read_value(mvme, base+VPC6_RBCK_RO+(0x10*(port-1))+0x0C);
00172       vpc6_PortDisplay(type, port, reg);
00173       break;
00174     }
00175   } while (timeout--);
00176 
00177   //  printf("DEBUG Readback Register:\n reg[0]=0x%8lx \n reg[1]=0x%8lx \n reg[2]=0x%8lx \n reg[3]=0x%8lx \n"
00178   //     , reg[0], reg[1], reg[2], reg[3]);
00179 
00180   if (timeout == 0)
00181     printf(" Port %d busy\n", port);
00182 
00183   mvme_set_dmode(mvme, cmode);
00184   return VPC6_SUCCESS;
00185 }
00186 
00187 /*****************************************************************/
00188 /**
00189  * Read the Register and Display in a readable form the Port setting
00190  * No action to the PA board
00191  */
00192 int vpc6_PortRegRead(MVME_INTERFACE *mvme, DWORD base, WORD port)
00193 {
00194   int cmode;
00195   WORD type;
00196   DWORD reg[4];
00197 
00198   mvme_get_dmode(mvme, &cmode);
00199   mvme_set_dmode(mvme, MVME_DMODE_D32);
00200 
00201   type  = mvme_read_value(mvme, base+VPC6_CR_RW);
00202   type  = ((type >> (2*(port-1))) & 0x03);   // ASD or Buck
00203   reg[0] = mvme_read_value(mvme, base+VPC6_CFG_RW+(0x10*(port-1))+0x00);
00204   reg[1] = mvme_read_value(mvme, base+VPC6_CFG_RW+(0x10*(port-1))+0x04);
00205   reg[2] = mvme_read_value(mvme, base+VPC6_CFG_RW+(0x10*(port-1))+0x08);
00206   reg[3] = mvme_read_value(mvme, base+VPC6_CFG_RW+(0x10*(port-1))+0x0C);
00207   vpc6_PortDisplay(type, port, reg);
00208 
00209   //printf("DEBUG Configuration Register:\n reg[0]=0x%8lx \n reg[1]=0x%8lx \n reg[2]=0x%8lx \n reg[3]=0x%8lx \n"
00210   // , reg[0], reg[1], reg[2], reg[3]);
00211 
00212   mvme_set_dmode(mvme, cmode);
00213   return VPC6_SUCCESS;
00214 }
00215 
00216 /*****************************************************************/
00217 /**
00218  * decoded printout of readout entry
00219  */
00220 void vpc6_PortDisplay(WORD type, WORD port, DWORD * reg)
00221 {
00222   printf("\n---- Port:%d Type:%s ----------------------------\n"
00223    , port, type == VPC6_ASD01 ? "ASD01" : "Buckeye");
00224   vpc6_EntryPrint(type, 0, (vpc6_Reg *)&reg[0]);
00225   if (type == VPC6_ASD01) {
00226     vpc6_EntryPrint(type, 1, (vpc6_Reg *)&reg[2]);
00227   }
00228 }
00229 
00230 /*****************************************************************/
00231 /**
00232  * decoded printout of readout entry for ASD type preamp
00233  * Not to be trusted for data decoding but acceptable for display
00234  * purpose as its implementation is strongly compiler dependent and
00235  * not flawless.
00236  * @param v
00237  */
00238 void vpc6_EntryPrint(WORD type, WORD chip, const vpc6_Reg* v)
00239 {
00240   vpc6_Reg * v2 = v+1;
00241 
00242 
00243   if (type == VPC6_ASD01) {
00244     switch (chip) {
00245     case vpc6_asd_ch1_8:
00246       printf("Channel 1 to 8...\n");
00247       printf("Chip mode    :%s ", v->asdx1.chipmode == 0 ? "ADC" : "TOT");
00248       printf("     Channel mode :0x%04x \n", v->asdx1.channelmode);
00249       printf("Threshold    :0x%02x     Hysteresis   :0x%02x     CalInjCap    :0x%02x     CalMaskReg   :0x%02x\n"
00250        , v2->asdx2.mainThresholdDAC, v->asdx1.hysteresisDAC
00251        , v2->asdx2.capInjCapSel, v2->asdx2.calMaskReg);
00252       if (v->asdx1.chipmode == 0) {
00253   printf("ADC Threshold:0x%02x     Dead Time    :0x%02x WADC Run Current :0x%02x     WADC Int Gate:0x%02x\n"
00254          , ((v2->asdx2.wilkinsonADC << 1) | v ->asdx1.wilkinsonADC), v->asdx1.deadtime
00255          , v->asdx1.wilkinsonRCurrent, v->asdx1.wilkinsonIGate);
00256       }
00257       break;
00258     case vpc6_asd_ch9_16:
00259       printf("Channel 9 to 16...\n");
00260       printf("Chip mode    :%s ", v->asdx1.chipmode == 0 ? "ADC" : "TOT");
00261       printf("     Channel mode :0x%04x \n", v->asdx1.channelmode);
00262       printf("Threshold    :0x%02x     Hysteresis   :0x%02x     CalInjCap    :0x%02x     CalMaskReg   :0x%02x\n"
00263        , v2->asdx2.mainThresholdDAC, v->asdx1.hysteresisDAC
00264        , v2->asdx2.capInjCapSel, v2->asdx2.calMaskReg);
00265       if (v->asdx1.chipmode == 0) {
00266   printf("ADC Threshold:0x%02x     Dead Time    :0x%02x WADC Run Current :0x%02x     WADC Int Gate:0x%02x\n"
00267          , ((v2->asdx2.wilkinsonADC << 1) | v ->asdx1.wilkinsonADC), v->asdx1.deadtime
00268          , v->asdx1.wilkinsonRCurrent, v->asdx1.wilkinsonIGate);
00269       }
00270       break;
00271     }
00272   }
00273   else if (type == VPC6_BUCKEYE) {
00274     printf("Channel:  1 to 16...\n");
00275   }
00276 }
00277 
00278 
00279 /*****************************************************************/
00280 /**
00281 Sets all the necessary paramters for a given configuration.
00282 The configuration is provided by the mode argument.
00283 Add your own configuration in the case statement. Let me know
00284 your setting if you want to include it in the distribution.
00285 @param *mvme VME structure
00286 @param  base Module base address
00287 @param mode  Configuration mode number
00288 @param *nentry number of entries requested and returned.
00289 @return MVME_SUCCESS
00290 */
00291 int  vpc6_Setup(MVME_INTERFACE *mvme, DWORD base, int mode)
00292 {
00293   int  cmode;
00294 
00295   mvme_get_dmode(mvme, &cmode);
00296   mvme_set_dmode(mvme, MVME_DMODE_D32);
00297 
00298   switch (mode) {
00299   case 0x1:
00300     printf("Default setting after power up (mode:%d)\n", mode);
00301     printf("All Buckeye\n");
00302     vpc6_PATypeWrite(mvme, base, VPC6_ALL_BUCKEYE);
00303     break;
00304   case 0x2:
00305     printf("Modified setting (mode:%d)\n", mode);
00306     printf("All ASD01\n");
00307     vpc6_PATypeWrite(mvme, base, VPC6_ALL_ASD);
00308     break;
00309   case 0x3:
00310     printf("Modified setting (mode:%d)\n", mode);
00311     printf("3 ASD and 3 Buckeye\n");
00312     vpc6_PATypeWrite(mvme, base, VPC6_3ASD_3BUCK);
00313     break;
00314   case 0x4:
00315     printf("Modified setting (mode:%d)\n", mode);
00316     printf("All Buckeye\n");
00317     vpc6_PATypeWrite(mvme, base, VPC6_3BUCK_3ASD);
00318     break;
00319   default:
00320     printf("Unknown setup mode\n");
00321     mvme_set_dmode(mvme, cmode);
00322     return -1;
00323   }
00324   mvme_set_dmode(mvme, cmode);
00325   return 0;
00326 }
00327 
00328 /*****************************************************************/
00329 void  vpc6_Status(MVME_INTERFACE *mvme, DWORD base, WORD port)
00330 {
00331   int status, cmode;
00332 
00333   mvme_get_dmode(mvme, &cmode);
00334   mvme_set_dmode(mvme, MVME_DMODE_D32);
00335   printf("vpc6 Status for Base:0x%lx\n", base);
00336   status = vpc6_isPortBusy(mvme, base, port);
00337   printf("Port Busy Status: 0x%x\n", status);
00338   status = vpc6_PortTypeRead(mvme, base, port);
00339   printf("PA type: 0x%x\n", status);
00340   mvme_set_dmode(mvme, cmode);
00341 }
00342 
00343 /*****************************************************************/
00344 void  vpc6_ASDDefaultLoad(MVME_INTERFACE *mvme, DWORD base, WORD port)
00345 {
00346   vpc6_Reg def;
00347 
00348   def.asdx1.chipmode          = 1; // ToT
00349   def.asdx1.channelmode       = 0; // All on
00350   def.asdx1.deadtime          = 0; // 300ns
00351   def.asdx1.wilkinsonRCurrent = 0; // N/A
00352   def.asdx1.wilkinsonIGate    = 0; // N/A
00353   def.asdx1.hysteresisDAC     = 7; // ~10mV hysteresis
00354   def.asdx1.wilkinsonADC      = 0; // bit0 here  N/A
00355   vpc6_ASDRegSet(mvme, base, port, 0, &def);
00356 
00357   def.asdx2.wilkinsonADC      = 0; // bits2..1 here  N/A
00358   def.asdx2.mainThresholdDAC  = 108; // N/A
00359   def.asdx2.capInjCapSel      = 0; // N/A
00360   def.asdx2.calMaskReg        = 0; // N/A
00361   def.asdx2.notused           = 0;
00362   vpc6_ASDRegSet(mvme, base, port, 1, &def);
00363 
00364   def.asdx1.chipmode          = 1; // ToT
00365   def.asdx1.channelmode       = 0;
00366   def.asdx1.deadtime          = 0;
00367   def.asdx1.wilkinsonRCurrent = 0;
00368   def.asdx1.wilkinsonIGate    = 0;
00369   def.asdx1.hysteresisDAC     = 7;
00370   def.asdx1.wilkinsonADC      = 0; // bit0 here  N/A
00371   vpc6_ASDRegSet(mvme, base, port, 2, &def);
00372 
00373   def.asdx2.wilkinsonADC      = 0; // bits2..1 here  N/A
00374   def.asdx2.mainThresholdDAC  = 108;
00375   def.asdx2.capInjCapSel      = 0;
00376   def.asdx2.calMaskReg        = 0;
00377   def.asdx2.notused           = 0;
00378   vpc6_ASDRegSet(mvme, base, port, 3, &def);
00379 }
00380 
00381 /*****************************************************************/
00382 void  vpc6_ASDRegSet(MVME_INTERFACE *mvme, DWORD base, WORD port
00383          , WORD reg, vpc6_Reg * Reg)
00384 {
00385   int  cmode;
00386 
00387   mvme_get_dmode(mvme, &cmode);
00388   mvme_set_dmode(mvme, MVME_DMODE_D32);
00389 
00390   mvme_write_value(mvme, base+VPC6_CFG_RW+((port-1)*0x10)+(reg*0x04), Reg->asdcfg);
00391   //DEBUG
00392   //printf("port:%d reg:%d addr: 0x%x\n",port, reg, VPC6_CFG_RW+((port-1)*0x10)+(reg*0x04));
00393   mvme_set_dmode(mvme, cmode);
00394 }
00395 
00396 /*****************************************************************/
00397 int vpc6_ASDModeSet(MVME_INTERFACE *mvme, DWORD base, WORD port, int channel,  int mode)
00398 {
00399   int  cmode;
00400   int ch;
00401   vpc6_Reg reg[2];
00402 
00403   mvme_get_dmode(mvme, &cmode);
00404   mvme_set_dmode(mvme, MVME_DMODE_D32);
00405 
00406   reg[0] = (vpc6_Reg) mvme_read_value(mvme, base+VPC6_CFG_RW+(0x10*(port-1))+0x00);
00407   reg[1] = (vpc6_Reg) mvme_read_value(mvme, base+VPC6_CFG_RW+(0x10*(port-1))+0x08);
00408 
00409   if((mode >= 0) && (mode < 4)) {
00410     if (channel == ALL_CHANNELS) {
00411       reg[0].asdx1.channelmode = 0x0000;
00412       reg[1].asdx1.channelmode = 0x0000;
00413       for (ch=0; ch<8; ch++) {
00414   reg[0].asdx1.channelmode |= mode << ch*2;
00415       }
00416       for (ch=0; ch<8; ch++) {
00417   reg[1].asdx1.channelmode |= mode << ch*2;
00418       }
00419     }
00420     else if ((channel >= 0) && (channel < 8)) {
00421       reg[0].asdx1.channelmode &= (~0x0003) << channel*2;
00422       reg[0].asdx1.channelmode |= mode << channel*2;
00423     }
00424     else if ((channel >= 8) && (channel < 16)) {
00425       reg[1].asdx1.channelmode &= (~0x0003) << (channel-8)*2;
00426       reg[1].asdx1.channelmode |= mode << channel*2;
00427     }
00428     else {
00429       printf("Invalid Channel # %d...\n", channel);
00430       printf("Channels 0..15  (%d for ALL)\n", ALL_CHANNELS);
00431       mvme_set_dmode(mvme, cmode);
00432       return -1;
00433     }
00434   }
00435   else {
00436     printf("Invalid ASD Channel Mode Setting... %d\n", mode);
00437     printf("Modes:  0 (ON), 1 (ON), 2 (Forced LOW), 3 (Forced HIGH)\n");
00438     mvme_set_dmode(mvme, cmode);
00439     return -1;
00440   }
00441 
00442   vpc6_ASDRegSet(mvme, base, port, 0, &reg[0]);
00443   vpc6_ASDRegSet(mvme, base, port, 2, &reg[1]);
00444   vpc6_PortCfgLoad(mvme, base, port);
00445   vpc6_CfgRetrieve(mvme, base, port);
00446   mvme_set_dmode(mvme, cmode);
00447   return 0;
00448 }
00449 
00450 
00451 /*****************************************************************/
00452 int vpc6_ASDThresholdSet(MVME_INTERFACE *mvme, DWORD base, WORD port, int value)
00453 {
00454   int  cmode;
00455   vpc6_Reg reg[2];
00456 
00457   mvme_get_dmode(mvme, &cmode);
00458   mvme_set_dmode(mvme, MVME_DMODE_D32);
00459 
00460   reg[0] = (vpc6_Reg) mvme_read_value(mvme, base+VPC6_CFG_RW+(0x10*(port-1))+0x04);
00461   reg[1] = (vpc6_Reg) mvme_read_value(mvme, base+VPC6_CFG_RW+(0x10*(port-1))+0x0C);
00462 
00463   // Threshold Value in mV (~9mV / fC)
00464   if ((value >= -256) && (value <= 254)) {
00465     reg[0].asdx2.mainThresholdDAC = (value / 2) + 128;
00466     reg[1].asdx2.mainThresholdDAC = (value / 2) + 128;
00467   }
00468   else {
00469     printf("Invalid Threshold Setting %d...\n", value);
00470     printf("Threshold = -256 .. 254 (in mV's)\n");
00471     mvme_set_dmode(mvme, cmode);
00472     return -1;
00473   }
00474 
00475   vpc6_ASDRegSet(mvme, base, port, 1, &reg[0]);
00476   vpc6_ASDRegSet(mvme, base, port, 3, &reg[1]);
00477 
00478   vpc6_PortCfgLoad(mvme, base, port);
00479   vpc6_CfgRetrieve(mvme, base, port);
00480 
00481   mvme_set_dmode(mvme, cmode);
00482 
00483   return 0;
00484 }
00485 
00486 
00487 /*****************************************************************/
00488 int vpc6_ASDHysteresisSet(MVME_INTERFACE *mvme, DWORD base, WORD port, float value)
00489 {
00490   int  cmode;
00491   int ivalue;
00492   vpc6_Reg reg[2];
00493 
00494   mvme_get_dmode(mvme, &cmode);
00495   mvme_set_dmode(mvme, MVME_DMODE_D32);
00496 
00497   reg[0] = (vpc6_Reg) mvme_read_value(mvme, base+VPC6_CFG_RW+(0x10*(port-1))+0x00);
00498   reg[1] = (vpc6_Reg) mvme_read_value(mvme, base+VPC6_CFG_RW+(0x10*(port-1))+0x08);
00499 
00500   // Hysteresis Value
00501   ivalue = (int) (value / 1.25);
00502   if ((ivalue >= 0x0) && (ivalue <= 0xF)) {
00503     reg[0].asdx1.hysteresisDAC = ivalue;
00504     reg[1].asdx1.hysteresisDAC = ivalue;
00505   }
00506   else {
00507     printf("Invalid Hysteresis Setting %f...\n", value);
00508     printf("Hysteresis = 0x0 .. 0xF (ie. 0 - 18.75mV)\n");
00509     mvme_set_dmode(mvme, cmode);
00510     return -1;
00511   }
00512 
00513   vpc6_ASDRegSet(mvme, base, port, 0, &reg[0]);
00514   vpc6_ASDRegSet(mvme, base, port, 2, &reg[1]);
00515   vpc6_PortCfgLoad(mvme, base, port);
00516   vpc6_CfgRetrieve(mvme, base, port);
00517   mvme_set_dmode(mvme, cmode);
00518 
00519   return 0;
00520 }
00521 
00522 
00523 /*****************************************************************/
00524 int vpc6_BuckeyeModeSet(MVME_INTERFACE *mvme, DWORD base, WORD port, int channel,  int mode)
00525 {
00526 
00527   return 0;
00528 }
00529 
00530 
00531 
00532 
00533 
00534 
00535 
00536 /*****************************************************************/
00537 /*-PAA- For test purpose only */
00538 #ifdef MAIN_ENABLE
00539 int main (int argc, char* argv[]) {
00540   int i;
00541   int status;
00542   int argindex = 1;
00543   DWORD VPC6_BASE  = 0x300000;
00544   WORD port = 0;
00545   MVME_INTERFACE *myvme;
00546   int channel;
00547   int value;
00548   float fvalue;
00549 
00550 
00551   // Test under vmic
00552   status = mvme_open(&myvme, 0);
00553 
00554   // Set am to A24 non-privileged Data
00555   mvme_set_am(myvme, MVME_AM_A24_ND);
00556 
00557   // Set dmode to D32
00558   mvme_set_dmode(myvme, MVME_DMODE_D32);
00559 
00560 
00561   // Set VPC6 Port Modes (3 ASD / 3 Buckeye)
00562   vpc6_Setup(myvme, VPC6_BASE, 3);
00563 
00564   // Load Default Configurations
00565   for (i=1;i<7;i++) {
00566     vpc6_ASDDefaultLoad(myvme, VPC6_BASE, i);
00567     vpc6_PortCfgLoad(myvme, VPC6_BASE, i);
00568     vpc6_CfgRetrieve(myvme, VPC6_BASE, i);
00569   }
00570 
00571   printf("\n\n");
00572 
00573 
00574   if (argc > 1) {
00575 
00576     while (argindex < argc) {
00577       if ((strncmp(argv[argindex],"-help",2) == 0) && (argc == 2)) {
00578   printf("vpc6 command line usage...\n");
00579   printf("vpc6 -help -baseaddr [a] -port [p] -threshold [t] -hysteresis [h]\n");
00580   printf("     -channelmode [c] [m] -readback\n");
00581   printf("[a]: base address of vpc6 module (eg. 0x300000)\n");
00582   printf("[p]: port number (1..6; 0 for all ports!!! '0' NOT IMPLEMENTED IN FIRMWARE YET)\n");
00583   printf("[t]: theshold setting (-256..254 [mV])\n");
00584   printf("[h]: hysteresis setting (0x0..0xF [0-18.75mV])\n");
00585   printf("[c]: channel number (0..15; -1 for all channels)\n");
00586   printf("[m]: channel mode (0,1=On; 2=Forced Low; 3=Forced High)\n");
00587       }
00588       else if (strncmp(argv[argindex],"-baseaddr",2) == 0) {
00589   if ((argindex+1) < argc) {
00590     argindex = argindex + 1;
00591     sscanf(argv[argindex],"%lx",&VPC6_BASE);
00592     printf("Base Set... 0x%lx\n", VPC6_BASE);
00593   }
00594   else {
00595     printf("Invalid number of arguments for %s modifier\n",argv[argindex]);
00596     break;
00597   }
00598       }
00599       else if (strncmp(argv[argindex],"-port",2) == 0) {
00600   if ((argindex+1) < argc) {
00601     argindex = argindex + 1;
00602     sscanf(argv[argindex],"%d",&port);
00603     printf("Port Set... %d\n", port);
00604   }
00605   else {
00606     printf("Invalid number of arguments for %s modifier\n",argv[argindex]);
00607     break;
00608   }
00609       }
00610       else if (strncmp(argv[argindex],"-threshold",2) == 0) {
00611   if ((argindex+1) < argc) {
00612     argindex = argindex + 1;
00613     sscanf(argv[argindex],"%d",&value);
00614     vpc6_ASDThresholdSet(myvme, VPC6_BASE, port, value);
00615     printf("Threshold Set... %4.0d mV\n", value);
00616   }
00617   else {
00618     printf("Invalid number of arguments for %s modifier\n",argv[argindex]);
00619     break;
00620   }
00621       }
00622       else if (strncmp(argv[argindex],"-hysteresis",3) == 0) {
00623   if ((argindex+1) < argc) {
00624     argindex = argindex + 1;
00625     sscanf(argv[argindex],"%f",&fvalue);
00626     vpc6_ASDHysteresisSet(myvme, VPC6_BASE, port, fvalue);
00627     printf("Hysteresis Set... %4.2f\n", fvalue);
00628   }
00629   else {
00630     printf("Invalid number of arguments for %s modifier\n",argv[argindex]);
00631     break;
00632   }
00633       }
00634       else if (strncmp(argv[argindex],"-channelmode",2) == 0) {
00635   if ((argindex+2) < argc) {
00636     argindex = argindex + 1;
00637     sscanf(argv[argindex],"%d",&channel);
00638     argindex = argindex + 1;
00639     sscanf(argv[argindex],"%d",&value);
00640     vpc6_ASDModeSet(myvme, VPC6_BASE, port, channel, value);
00641     if (channel == -1) {
00642       printf("ALL Channels Set... %d\n", value);
00643     }
00644     else {
00645       printf("Channel %d Set... %d\n", channel, value);
00646     }
00647   }
00648   else {
00649     printf("Invalid number of arguments for %s modifier\n",argv[argindex]);
00650     break;
00651   }
00652   printf("Channel Mode Set...\n");
00653       }
00654 
00655       else if (strncmp(argv[argindex],"-readback",2) == 0) {
00656   vpc6_PortRegRBRead(myvme, VPC6_BASE, 1);
00657       }
00658       else {
00659   printf("Invalid Argument... %s\n", argv[argindex]);
00660   printf("'vpc6 -help' for command line usage...\n");
00661   break;
00662      }
00663       argindex++;
00664     }
00665 
00666   }
00667 
00668 
00669 
00670 
00671   //  vpc6_PortRegRead(myvme, VPC6_BASE, 1);
00672   //  vpc6_PortRegRBRead(myvme, VPC6_BASE, 1);
00673   printf("\n\n");
00674 
00675 
00676 
00677 
00678 
00679 
00680 
00681 
00682   /*** FOR TESTING ***/
00683   if(0) {
00684 
00685   vpc6_Setup(myvme, VPC6_BASE, 2);
00686 
00687   // for (i=1;i<7;i++) {
00688   for (i=1;i<2;i++) {
00689     //vpc6_Status(myvme, VPC6_BASE, i);
00690     //    vpc6_ASDDefaultLoad(myvme, VPC6_BASE, i);
00691     //    vpc6_PortCfgLoad(myvme, VPC6_BASE, i);
00692     //    vpc6_CfgRetrieve(myvme, VPC6_BASE, i);
00693     vpc6_PortRegRead(myvme, VPC6_BASE, i);
00694     vpc6_PortRegRBRead(myvme, VPC6_BASE, i);
00695   }
00696 
00697   }
00698   status = mvme_close(myvme);
00699   return 1;
00700 }
00701 #endif
00702 
00703 /* emacs
00704  * Local Variables:
00705  * mode:C
00706  * mode:font-lock
00707  * tab-width: 8
00708  * c-basic-offset: 2
00709  * End:
00710  */

Midas DOC Version 2.0.2 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Exaos Lee - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk