v1190B.c

Go to the documentation of this file.
00001 /*********************************************************************
00002 
00003   Name:         v1190B.c
00004   Created by:   Pierre-Andre Amaudruz
00005 
00006   Contents:     V1190B 64ch. TDC
00007 
00008   $Id: v1190B.c 3746 2007-07-10 08:26:11Z amaudruz $
00009 *********************************************************************/
00010 #include <stdio.h>
00011 #include <string.h>
00012 #include "v1190B.h"
00013 
00014 /*****************************************************************/
00015 /*****************************************************************/
00016 /**
00017 Read Data buffer for single event (check delimiters)
00018 0x4... and 0xC...
00019 @param *mvme VME structure
00020 @param  base Module base address
00021 @param *pdest destination pointer address
00022 @param *nentry number of entries requested and returned.
00023 @return
00024 */
00025 int v1190_EventRead(MVME_INTERFACE *mvme, DWORD base, DWORD *pdest, int *nentry)
00026 {
00027   int cmode;
00028   DWORD hdata;
00029 
00030   *nentry = 0;
00031   mvme_get_dmode(mvme, &cmode);
00032   mvme_set_dmode(mvme, MVME_DMODE_D32);
00033   if (v1190_DataReady(mvme, base)) {
00034     do {
00035       hdata = mvme_read_value(mvme, base);
00036     } while (!(hdata & 0x40000000));
00037     pdest[*nentry] = hdata;
00038     *nentry += 1;
00039 
00040     do {
00041       pdest[*nentry] = mvme_read_value(mvme, base);
00042       *nentry += 1;
00043     } while (!(pdest[*nentry-1] & 0xc0000000));
00044   }
00045   mvme_set_dmode(mvme, cmode);
00046   return *nentry;
00047 
00048 /*
00049   header = *pbase & 0xFF000000;
00050 
00051   switch (header) {
00052   case 0x40000000:  // Global Header
00053     break;
00054   case 0x00000000:  // TDC Header
00055     break;
00056   case 0x10000000:  // Data
00057     break;
00058   case 0x20000000:  // Error
00059     break;
00060   case 0x80000000:  // Trailer
00061     break;
00062   case 0xc0000000:  // Filler
00063     break;
00064   }
00065 
00066   return *nentry;
00067 */
00068 }
00069 
00070 /*****************************************************************/
00071 /**
00072 Read data buffer for nentry data.
00073 @param *mvme VME structure
00074 @param  base Module base address
00075 @param *pdest destination pointer address
00076 @param *nentry number of entries requested and returned.
00077 @return
00078 */
00079 int v1190_DataRead(MVME_INTERFACE *mvme, DWORD base, DWORD *pdest, int nentry)
00080 {
00081   int cmode, status;
00082 
00083     mvme_get_dmode(mvme, &cmode);
00084     mvme_set_dmode(mvme, MVME_DMODE_D32);
00085 
00086     status = mvme_read(mvme, pdest, base, sizeof(DWORD) * nentry);
00087 
00088     mvme_set_dmode(mvme, cmode);
00089     return nentry;
00090 
00091     /*
00092       for (i=0 ; i<nentry ; i++) {
00093       if (!v1190_DataReady(mvme, base))
00094       break;
00095       pdest[i] = mvme_read_value(mvme, base);
00096       }
00097       mvme_set_dmode(mvme, cmode);
00098       return i;
00099     */
00100 }
00101 
00102 /*****************************************************************/
00103 int v1190_GeoWrite(MVME_INTERFACE *mvme, DWORD base, int geo)
00104 {
00105   int cmode, data;
00106 
00107   mvme_get_dmode(mvme, &cmode);
00108   mvme_set_dmode(mvme, MVME_DMODE_D16);
00109   mvme_write_value(mvme, base+V1190_GEO_REG_RW, (geo & 0x1F));
00110   data = mvme_read_value(mvme, base+V1190_GEO_REG_RW);
00111   mvme_set_dmode(mvme, cmode);
00112 
00113   return (int) (data & 0x1F);
00114 }
00115 
00116 /*****************************************************************/
00117 void v1190_SoftReset(MVME_INTERFACE *mvme, DWORD base)
00118 {
00119   int cmode;
00120 
00121   mvme_get_dmode(mvme, &cmode);
00122   mvme_set_dmode(mvme, MVME_DMODE_D16);
00123   mvme_write_value(mvme, base+V1190_MODULE_RESET_WO, 0);
00124   mvme_set_dmode(mvme, cmode);
00125 }
00126 
00127 /*****************************************************************/
00128 void v1190_SoftClear(MVME_INTERFACE *mvme, DWORD base)
00129 {
00130   int cmode;
00131 
00132   mvme_get_dmode(mvme, &cmode);
00133   mvme_set_dmode(mvme, MVME_DMODE_D16);
00134   mvme_write_value(mvme, base+V1190_SOFT_CLEAR_WO, 0);
00135   mvme_set_dmode(mvme, cmode);
00136 }
00137 
00138 /*****************************************************************/
00139 void v1190_SoftTrigger(MVME_INTERFACE *mvme, DWORD base)
00140 {
00141   int cmode;
00142 
00143   mvme_get_dmode(mvme, &cmode);
00144   mvme_set_dmode(mvme, MVME_DMODE_D16);
00145   mvme_write_value(mvme, base+V1190_SOFT_TRIGGER_WO, 0);
00146   mvme_set_dmode(mvme, cmode);
00147 }
00148 
00149 /*****************************************************************/
00150 int  v1190_DataReady(MVME_INTERFACE *mvme, DWORD base)
00151 {
00152   int cmode, data;
00153 
00154   mvme_get_dmode(mvme, &cmode);
00155   mvme_set_dmode(mvme, MVME_DMODE_D16);
00156   data = mvme_read_value(mvme, base+V1190_SR_RO);
00157   mvme_set_dmode(mvme, cmode);
00158   return (data & V1190_DATA_READY);
00159 }
00160 
00161 /*****************************************************************/
00162 int  v1190_EvtStored(MVME_INTERFACE *mvme, DWORD base)
00163 {
00164   int cmode, data;
00165 
00166   mvme_get_dmode(mvme, &cmode);
00167   mvme_set_dmode(mvme, MVME_DMODE_D16);
00168   data = mvme_read_value(mvme, base+V1190_EVT_STORED_RO);
00169   mvme_set_dmode(mvme, cmode);
00170   return (data);
00171 }
00172 
00173 /*****************************************************************/
00174 int  v1190_EvtCounter(MVME_INTERFACE *mvme, DWORD base)
00175 {
00176   int cmode, data;
00177 
00178   mvme_get_dmode(mvme, &cmode);
00179   mvme_set_dmode(mvme, MVME_DMODE_D32);
00180   data = mvme_read_value(mvme, base+V1190_EVT_CNT_RO);
00181   mvme_set_dmode(mvme, cmode);
00182   return (data);
00183 }
00184 
00185 /*****************************************************************/
00186 void v1190_TdcIdList(MVME_INTERFACE *mvme, DWORD base)
00187 {
00188   int  cmode, i, code;
00189   DWORD value;
00190 
00191   mvme_get_dmode(mvme, &cmode);
00192   mvme_set_dmode(mvme, MVME_DMODE_D16);
00193 
00194   for (i=0; i<2 ; i++) {
00195     code   = V1190_MICRO_TDCID | (i & 0x0F);
00196     value  = v1190_MicroWrite(mvme, base, code);
00197     value  = v1190_MicroRead(mvme, base);
00198     value = (v1190_MicroRead(mvme, base) << 16) | value;
00199     //    printf("Received :code: 0x%04x  0x%08lx\n", code, value);
00200   }
00201   mvme_set_dmode(mvme, cmode);
00202 }
00203 
00204 /*****************************************************************/
00205 int  v1190_ResolutionRead(MVME_INTERFACE *mvme, DWORD base)
00206 {
00207   WORD  i, code;
00208   int   cmode, value;
00209 
00210   mvme_get_dmode(mvme, &cmode);
00211   mvme_set_dmode(mvme, MVME_DMODE_D16);
00212 
00213   for (i=0; i<2 ; i++) {
00214     code = V1190_RESOLUTION_RO | (i & 0x0F);
00215     value = v1190_MicroWrite(mvme, base, code);
00216     value = v1190_MicroRead(mvme, base);
00217     // printf("Received RR :code: 0x%04x  0x%08x\n", code, value);
00218   }
00219   mvme_set_dmode(mvme, cmode);
00220   return value;
00221 }
00222 
00223 /*****************************************************************/
00224 void v1190_LEResolutionSet(MVME_INTERFACE *mvme, DWORD base, WORD le)
00225 {
00226   int   cmode, value;
00227 
00228   mvme_get_dmode(mvme, &cmode);
00229   mvme_set_dmode(mvme, MVME_DMODE_D16);
00230 
00231   if ((le == LE_RESOLUTION_100) ||
00232       (le == LE_RESOLUTION_200) ||
00233       (le == LE_RESOLUTION_800)) {
00234     printf("le:%x\n", le);
00235     value = v1190_MicroWrite(mvme, base, V1190_LE_RESOLUTION_WO);
00236     value = v1190_MicroWrite(mvme, base, le);
00237   } else {
00238     printf("Wrong Leading Edge Resolution -> Disabled\n");
00239     value = v1190_MicroWrite(mvme, base, V1190_LE_RESOLUTION_WO);
00240     value = v1190_MicroWrite(mvme, base, 3);
00241   }
00242   mvme_set_dmode(mvme, cmode);
00243 }
00244 
00245 /*****************************************************************/
00246 void v1190_LEWResolutionSet(MVME_INTERFACE *mvme, DWORD base, WORD le, WORD width)
00247 {
00248   printf("Not yet implemented\n");
00249 }
00250 
00251 /*****************************************************************/
00252 void v1190_AcqModeRead(MVME_INTERFACE *mvme, DWORD base)
00253 {
00254   int   cmode, value;
00255 
00256   mvme_get_dmode(mvme, &cmode);
00257   mvme_set_dmode(mvme, MVME_DMODE_D16);
00258 
00259   value = v1190_MicroWrite(mvme, base, V1190_ACQ_MODE_RO);
00260   value = v1190_MicroRead(mvme, base);
00261   //  printf("Received AR :code: 0x%04x  0x%08x\n", V1190_ACQ_MODE_RO, value);
00262   mvme_set_dmode(mvme, cmode);
00263 }
00264 
00265 /*****************************************************************/
00266 void v1190_TriggerMatchingSet(MVME_INTERFACE *mvme, DWORD base)
00267 {
00268   int   cmode, value;
00269 
00270   mvme_get_dmode(mvme, &cmode);
00271   mvme_set_dmode(mvme, MVME_DMODE_D16);
00272 
00273   value = v1190_MicroWrite(mvme, base, V1190_TRIGGER_MATCH_WO);
00274   //  printf("Received MS :code: 0x%04x  0x%08x\n", V1190_TRIGGER_MATCH_WO, value);
00275 
00276   mvme_set_dmode(mvme, cmode);
00277 }
00278 
00279 /*****************************************************************/
00280 void v1190_ContinuousSet(MVME_INTERFACE *mvme, DWORD base)
00281 {
00282   int   cmode, value;
00283 
00284   mvme_get_dmode(mvme, &cmode);
00285   mvme_set_dmode(mvme, MVME_DMODE_D16);
00286 
00287   value = v1190_MicroWrite(mvme, base, V1190_CONTINUOUS_WO);
00288   //  printf("Received CS :code: 0x%04x  0x%08x\n", V1190_CONTINUOUS_WO, value);
00289 
00290   mvme_set_dmode(mvme, cmode);
00291 }
00292 
00293 /*****************************************************************/
00294 /**
00295 Set the width of the matching Window. The width parameter should be
00296 in the range of 1 to 4095 (0xFFF). Example 0x14 == 500ns.
00297 @param *mvme VME structure
00298 @param  base Module base address
00299 @param width window width in ns units
00300 @return
00301 */
00302 void v1190_WidthSet(MVME_INTERFACE *mvme, DWORD base, WORD width)
00303 {
00304   int   cmode, value;
00305 
00306   mvme_get_dmode(mvme, &cmode);
00307   mvme_set_dmode(mvme, MVME_DMODE_D16);
00308 
00309   //  v1190_MicroFlush(mvme, base);
00310   value = v1190_MicroWrite(mvme, base, V1190_WINDOW_WIDTH_WO);
00311   value = v1190_MicroWrite(mvme, base, width);
00312   //  printf("Received WS :code: 0x%04x  0x%08x\n", V1190_WINDOW_WIDTH_WO, value);
00313 
00314   mvme_set_dmode(mvme, cmode);
00315 }
00316 
00317 /*****************************************************************/
00318 /**
00319 Set the offset of the matching window with respect to the trigger.
00320 The offset parameter should be in 25ns units. The range is
00321 from -2048(0x800) to +40(0x28). Example 0xFE8 == 600ns.
00322 @param *mvme VME structure
00323 @param  base Module base address
00324 @param  offset offset in ns units
00325 */
00326 void v1190_OffsetSet(MVME_INTERFACE *mvme, DWORD base, WORD offset)
00327 {
00328   int   cmode, value;
00329 
00330   mvme_get_dmode(mvme, &cmode);
00331   mvme_set_dmode(mvme, MVME_DMODE_D16);
00332 
00333   //  v1190_MicroFlush(mvme, base);
00334   value = v1190_MicroWrite(mvme, base, V1190_WINDOW_OFFSET_WO);
00335   value = v1190_MicroWrite(mvme, base, offset);
00336   //  printf("Received OS :code: 0x%04x  0x%08x\n", V1190_WINDOW_OFFSET_WO, value);
00337 
00338   mvme_set_dmode(mvme, cmode);
00339 }
00340 
00341 /*****************************************************************/
00342 void v1190_SetEdgeDetection(MVME_INTERFACE *mvme, DWORD base, int eLeading, int eTrailing)
00343 {
00344   int cmode, value = 0;
00345 
00346   mvme_get_dmode(mvme, &cmode);
00347   mvme_set_dmode(mvme, MVME_DMODE_D16);
00348 
00349   if (eLeading)
00350     value |= 2;
00351 
00352   if (eTrailing)
00353     value |= 1;
00354 
00355   //  v1190_MicroFlush(mvme, base);
00356   v1190_MicroWrite(mvme, base, V1190_EDGE_DETECTION_WO);
00357   v1190_MicroWrite(mvme, base, value);
00358   mvme_set_dmode(mvme, cmode);
00359 }
00360 
00361 
00362 /*****************************************************************/
00363 int v1190_MicroWrite(MVME_INTERFACE *mvme, DWORD base, WORD data)
00364 {
00365   int cmode, i;
00366 
00367   mvme_get_dmode(mvme, &cmode);
00368   mvme_set_dmode(mvme, MVME_DMODE_D16);
00369 
00370   for (i=0; i<1000; i++)
00371   {
00372     WORD microHS = mvme_read_value(mvme, base+V1190_MICRO_HAND_RO);
00373     if (microHS & V1190_MICRO_WR_OK) {
00374       mvme_write_value(mvme, base+V1190_MICRO_RW, data);
00375       mvme_set_dmode(mvme, cmode);
00376       return 1;
00377     }
00378     udelay(500);
00379   }
00380 
00381   printf("v1190_MicroWrite: Micro not ready for writing!\n");
00382   mvme_set_dmode(mvme, cmode);
00383   return -1;
00384 }
00385 
00386 /*****************************************************************/
00387 int v1190_MicroRead(MVME_INTERFACE *mvme, const DWORD base)
00388 {
00389   int cmode, i;
00390   int reg=-1;
00391 
00392   mvme_get_dmode(mvme, &cmode);
00393   mvme_set_dmode(mvme, MVME_DMODE_D16);
00394   for (i=100; i>0; i--) {
00395     WORD  microHS = mvme_read_value(mvme, base+V1190_MICRO_HAND_RO);
00396     if (microHS & V1190_MICRO_RD_OK) {
00397       reg = mvme_read_value(mvme, base+V1190_MICRO_RW);
00398 //      printf("i:%d microHS:%d %x\n", i, microHS, reg);
00399       mvme_set_dmode(mvme, cmode);
00400       return (reg);
00401     }
00402     udelay(500);
00403   };
00404   mvme_set_dmode(mvme, cmode);
00405   return -1;
00406 }
00407 
00408 /*****************************************************************/
00409 int v1190_MicroFlush(MVME_INTERFACE *mvme, const DWORD base)
00410 {
00411   int cmode, count = 0;
00412 
00413   mvme_get_dmode(mvme, &cmode);
00414   mvme_set_dmode(mvme, MVME_DMODE_D16);
00415 
00416   while (1)
00417     {
00418       int data = v1190_MicroRead(mvme, base);
00419       printf("microData[%d]: 0x%04x\n",count,data);
00420       if (data < 0)
00421   break;
00422       count++;
00423     }
00424   mvme_set_dmode(mvme, cmode);
00425   return count;
00426 }
00427 
00428 /*****************************************************************/
00429 /**
00430 Sets all the necessary paramters for a given configuration.
00431 The configuration is provided by the mode argument.
00432 Add your own configuration in the case statement. Let me know
00433 your setting if you want to include it in the distribution.
00434 @param *mvme VME structure
00435 @param  base Module base address
00436 @param mode  Configuration mode number
00437 @param *nentry number of entries requested and returned.
00438 @return MVME_SUCCESS
00439 */
00440 int  v1190_Setup(MVME_INTERFACE *mvme, DWORD base, int mode)
00441 {
00442   WORD code, value;
00443   int      cmode, status = -1;
00444 
00445   mvme_get_dmode(mvme, &cmode);
00446   mvme_set_dmode(mvme, MVME_DMODE_D16);
00447 
00448 //  v1190_MicroFlush(mvme, base);
00449   switch (mode) {
00450   case 0x1:
00451     printf("Trigger Matching Setup (mode:%d)\n", mode);
00452     printf("Default setting + Width : 800ns, Offset : -400ns\n");
00453     printf("Time subtract, Leading Edge only\n");
00454     code = 0x0000;  // Trigger matching Flag
00455     if ((status = v1190_MicroWrite(mvme, base, code)) < 0)
00456       return status;
00457     code = 0x1000;  // Width
00458     value = v1190_MicroWrite(mvme, base, code);
00459     value = v1190_MicroWrite(mvme, base, 0x20);   // Width : 800ns
00460     code = 0x1100;  // Offset
00461     value = v1190_MicroWrite(mvme, base, code);
00462     value = v1190_MicroWrite(mvme, base, 0xfe8);  // offset: -400ns
00463     code = 0x1500;  // Subtraction flag
00464     value = v1190_MicroWrite(mvme, base, code);
00465     code = 0x2100;  // Leading Edge Detection
00466     value = v1190_MicroWrite(mvme, base, code);
00467     break;
00468   case 0x2:
00469     code = 0x0500;  // Default configuration
00470     value = v1190_MicroWrite(mvme, base, code);
00471     break;
00472   default:
00473     printf("Unknown setup mode\n");
00474     mvme_set_dmode(mvme, cmode);
00475     return -1;
00476   }
00477   v1190_Status(mvme, base);
00478   mvme_set_dmode(mvme, cmode);
00479   return 0;
00480 }
00481 
00482 /*****************************************************************/
00483 /**
00484 Read and display the curent status of the TDC.
00485 @param *mvme VME structure
00486 @param  base Module base address
00487 @return MVME_SUCCESS, MicroCode error
00488 */
00489 int v1190_Status(MVME_INTERFACE *mvme, DWORD base)
00490 {
00491   WORD  i, code, pair=0;
00492   int   cmode, value;
00493 
00494   mvme_get_dmode(mvme, &cmode);
00495   mvme_set_dmode(mvme, MVME_DMODE_D16);
00496 
00497   //-------------------------------------------------
00498   printf("\n--- Trigger Section [0x1600]:\n");
00499   code = 0x1600;
00500   if ((value = v1190_MicroWrite(mvme, base, code)) < 0)
00501     return -value;
00502   value = v1190_MicroRead(mvme, base);
00503   printf("  Match Window width       : 0x%04x\n", value);
00504   value = v1190_MicroRead(mvme, base);
00505   printf("  Window offset            : 0x%04x\n", value);
00506   value = v1190_MicroRead(mvme, base);
00507   printf("  Extra Search Window Width: 0x%04x\n", value);
00508   value = v1190_MicroRead(mvme, base);
00509   printf("  Reject Margin            : 0x%04x\n", value);
00510   value = v1190_MicroRead(mvme, base);
00511   printf("  Trigger Time subtration  : %s\n",(value & 0x1) ? "y" : "n");
00512 
00513   //-------------------------------------------------
00514   printf("\n--- Edge Detection & Resolution Section[0x2300/26/29]:\n");
00515   code = 0x2300;
00516   value = v1190_MicroWrite(mvme, base, code);
00517   pair = value = v1190_MicroRead(mvme, base);
00518   printf("  Edge Detection (1:T/2:L/3:TL)           : 0x%02x\n", (value&0x3));
00519   code = 0x2600;
00520   value = v1190_MicroWrite(mvme, base, code);
00521   value = v1190_MicroRead(mvme, base);
00522   if (pair==0x3) {
00523     value = v1190_MicroRead(mvme, base);
00524     printf("  Leading Edge Resolution (see table)     : 0x%02x\n", (value&0x3));
00525     printf("  Pulse Width Resolution (see table)      : 0x%02x\n", ((value>>8)&0xF));
00526   } else {
00527     printf("  Resolution [ps] (0:800/1:200/2:100)     : 0x%02x\n", (value&0x3));
00528   }
00529   code = 0x2900;
00530   value = v1190_MicroWrite(mvme, base, code);
00531   value = v1190_MicroRead(mvme, base);
00532   printf("  Dead Time between hit [~ns](5/10/30/100): 0x%02x\n", (value&0x3));
00533 
00534   //-------------------------------------------------
00535   printf("\n--- Readout Section[0x3200/34/3a/3c]:\n");
00536   code = 0x3200;
00537   value = v1190_MicroWrite(mvme, base, code);
00538   value = v1190_MicroRead(mvme, base);
00539   printf("  Header/Trailer                            : %s\n",(value & 0x1) ? "y" : "n");
00540   code = 0x3400;
00541   value = v1190_MicroWrite(mvme, base, code);
00542   value = v1190_MicroRead(mvme, base);
00543   printf("  Max #hits per event 2^n-1 (>128:no limit) : %d\n", value&0xF);
00544   code = 0x3a00;
00545   value = v1190_MicroWrite(mvme, base, code);
00546   value = v1190_MicroRead(mvme, base);
00547   printf("  Internal TDC error type (see doc)         : 0x%04x\n", (value&0x7FF));
00548   code = 0x3c00;
00549   value = v1190_MicroWrite(mvme, base, code);
00550   value = v1190_MicroRead(mvme, base);
00551   printf("  Effective size of readout Fifo 2^n-1      : 0x%04x\n", (value&0xF));
00552 
00553   //-------------------------------------------------
00554   printf("\n--- Channel Enable Section[0x4500/47/49]:\n");
00555   code = 0x4500;
00556   value = v1190_MicroWrite(mvme, base, code);
00557   value = v1190_MicroRead(mvme, base);
00558   printf("  Read Enable Pattern [  0..15 ] : 0x%04x\n", value);
00559   value = v1190_MicroRead(mvme, base);
00560   printf("  Read Enable Pattern [ 16..31 ] : 0x%04x\n", value);
00561   value = v1190_MicroRead(mvme, base);
00562   printf("  Read Enable Pattern [ 32..47 ] : 0x%04x\n", value);
00563   value = v1190_MicroRead(mvme, base);
00564   printf("  Read Enable Pattern [ 48..63 ] : 0x%04x\n", value);
00565   code = 0x4700;
00566   value = v1190_MicroWrite(mvme, base, code);
00567   value = v1190_MicroRead(mvme, base);
00568   value = (v1190_MicroRead(mvme, base)<<16) | value;
00569   printf("  Read Enable Pattern 32 (0) : 0x%08x\n", value);
00570   code = 0x4701;
00571   value = v1190_MicroWrite(mvme, base, code);
00572   value = v1190_MicroRead(mvme, base);
00573   value = (v1190_MicroRead(mvme, base)<<16) | value;
00574   printf("  Read Enable Pattern 32 (1) : 0x%08x\n", value);
00575 
00576   //-------------------------------------------------
00577   printf("\n--- Adjust Section[0x5100/60]:\n");
00578   code = 0x5100;
00579   value = v1190_MicroWrite(mvme, base, code);
00580   value = v1190_MicroRead(mvme, base);
00581   printf("  Coarse Counter Offset: 0x%04x\n", (value&0x7FF));
00582   value = v1190_MicroRead(mvme, base);
00583   printf("  Fine   Counter Offset: 0x%04x\n", (value&0x1F));
00584   printf("\nMiscellaneous Section:\n");
00585   for (i=0; i<2 ; i++) {
00586     code = 0x6000 | (i & 0x0F);
00587     value = v1190_MicroWrite(mvme, base, code);
00588     value = v1190_MicroRead(mvme, base);
00589     value = (v1190_MicroRead(mvme, base) << 16) | value;
00590     printf("  TDC ID(%i)  0x%08x  [code:0x%04x]\n", i, value, code);
00591   }
00592   mvme_set_dmode(mvme, cmode);
00593   return 0;
00594 }
00595 
00596 /*****************************************************************/
00597 #ifndef HAVE_UDELAY
00598 // this is the VMIC version of udelay()
00599 int udelay(int usec)
00600 {
00601   int i, j, k = 0;
00602   for (i=0; i<133; i++)
00603     for (j=0; j<usec; j++)
00604       k += (k+1)*j*k*(j+1);
00605   return k;
00606 }
00607 #endif
00608 
00609 /********************************************************************/
00610 /*-PAA- For test purpose only */
00611 #ifdef MAIN_ENABLE
00612 int main () {
00613 
00614   MVME_INTERFACE *myvme;
00615 
00616   DWORD VMEIO_BASE = 0x780000;
00617   DWORD V1190_BASE = 0xF10000;
00618   int status, csr, i;
00619   DWORD    cnt, array[10000];
00620 
00621 
00622   // Test under vmic
00623   status = mvme_open(&myvme, 0);
00624 
00625   // Set am to A24 non-privileged Data
00626   mvme_set_am(myvme, MVME_AM_A24_ND);
00627 
00628   // Set dmode to D16
00629   mvme_set_dmode(myvme, MVME_DMODE_D16);
00630 
00631   // Get Firmware revision
00632   csr = mvme_read_value(myvme, V1190_BASE+V1190_FIRM_REV_RO);
00633   printf("Firmware revision: 0x%x\n", csr);
00634 
00635   // Print Current status
00636   v1190_Status(myvme, V1190_BASE);
00637 
00638   // Set mode 1
00639   // v1190_Setup(myvme, V1190_BASE, 1);
00640 
00641   csr = v1190_DataReady(myvme, V1190_BASE);
00642   printf("Data Ready: 0x%x\n", csr);
00643 
00644   // Read Event Counter
00645   cnt = v1190_EvtCounter(myvme, V1190_BASE);
00646   printf("Event counter: 0x%lx\n", cnt);
00647 
00648   memset(array, 0, sizeof(array));
00649 
00650   // Set dmode to D32
00651   mvme_set_dmode(myvme, MVME_DMODE_D32);
00652 
00653   // Set 0x3 in pulse mode for timing purpose
00654   mvme_write_value(myvme, VMEIO_BASE+0x8, 0xF);
00655 
00656   // Write pulse for timing purpose
00657   mvme_write_value(myvme, VMEIO_BASE+0xc, 0x2);
00658 
00659    mvme_set_blt(myvme, MVME_BLT_BLT32);
00660 
00661   // Read Data
00662   v1190_DataRead(myvme, V1190_BASE, array, 500);
00663 
00664   // Write pulse for timing purpose
00665   mvme_write_value(myvme, VMEIO_BASE+0xc, 0x8);
00666 
00667   for (i=0;i<12;i++)
00668     printf("Data[%i]=0x%lx\n", i, array[i]);
00669 
00670   memset(array, 0, sizeof(array));
00671 
00672   // Event Data
00673   /*
00674   status = 10;
00675   v1190_EventRead(myvme, V1190_BASE, array, &status);
00676   printf("count: 0x%x\n", status);
00677   for (i=0;i<12;i++)
00678     printf("Data[%i]=0x%x\n", i, array[i]);
00679   */
00680 
00681   status = mvme_close(myvme);
00682   return 0;
00683 }
00684 #endif
00685 

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