caenv1190B.h File Reference

Go to the source code of this file.

Defines

#define V1190B_H_INCLUDED   1
#define V1190_MAX_CHANNELS   (uint16_t) 64
#define V1190_REG_BASE   (uint16_t) (0x1000>>1)
#define V1190_CR_RW   (uint16_t) (0x1000>>1)
#define V1190_SR_RO   (uint16_t) (0x1002>>1)
#define V1190_DATA_READY   (uint16_t) (0x0001)
#define V1190_ALMOST_FULL   (uint16_t) (0x0002)
#define V1190_FULL   (uint16_t) (0x0004)
#define V1190_TRIGGER_MATCH   (uint16_t) (0x0008)
#define V1190_HEADER_ENABLE   (uint16_t) (0x0010)
#define V1190_GEO_REG_RW   (uint16_t) (0x001E)
#define V1190_MODULE_RESET_WO   (uint16_t) (0x1014>>1)
#define V1190_SOFT_CLEAR_WO   (uint16_t) (0x1016>>1)
#define V1190_SOFT_EVT_RESET_WO   (uint16_t) (0x1018>>1)
#define V1190_SOFT_TRIGGER_WO   (uint16_t) (0x101A>>1)
#define V1190_EVT_CNT_RO   (uint16_t) (0x101C>>1)
#define V1190_EVT_STORED_RO   (uint16_t) (0x1020>>1)
#define V1190_FIRM_REV_RO   (uint16_t) (0x1026>>1)
#define V1190_MICRO_RW   (uint16_t) (0x102E>>1)
#define V1190_MICRO_HAND_RO   (uint16_t) (0x1030>>1)
#define V1190_MICRO_WR_OK   (uint16_t) (0x0001)
#define V1190_MICRO_RD_OK   (uint16_t) (0x0002)
#define V1190_MICRO_TDCID   (uint16_t) (0x6000)
#define V1190_RESOLUTION_RO   (uint16_t) (0x2600)
#define V1190_TRIGGER_MATCH_WO   (uint16_t) (0x0000)
#define V1190_CONTINUOUS_WO   (uint16_t) (0x0100)
#define V1190_ACQ_MODE_RO   (uint16_t) (0x0200)

Functions

int udelay (int usec)
int v1190_EventRead (DWORD *base, DWORD *pdest, int *nentry)
int v1190_DataRead (DWORD *base, uint32_t *dest, int maxwords)
void v1190_SoftReset (uint16_t *pbase)
void v1190_SoftClear (uint16_t *pbase)
void v1190_SoftTrigger (uint16_t *pbase)
void v1190_DataReset (uint16_t *pbase)
int v1190_DataReady (uint16_t *pbase)
int v1190_EvtCounter (uint16_t *pbase)
int v1190_EvtStored (uint16_t *pbase)
int v1190_MicroCheck (const uint16_t *pbase, int what)
int v1190_MicroWrite (uint16_t *pbase, uint16_t data)
int v1190_MicroRead (const uint16_t *pbase)
int v1190_MicroFlush (const uint16_t *pbase)
int v1190B_TdcIdList (uint16_t *pbase)
int v1190B_ResolutionRead (uint16_t *pbase)
int v1190B_TriggerMatchingSet (uint16_t *pbase)
int v1190B_AcqModeRead (uint16_t *pbase)
int v1190B_ContinuousSet (uint16_t *pbase)
int v1190_GeoWrite (WORD *pbase, int geo)
int v1190_Setup (uint16_t *pbase, int mode)
int v1190_Status (uint16_t *pbase)
void v1190_SetEdgeDetection (uint16_t *pbase, int enableLeading, int enableTrailing)


Define Documentation

#define V1190_ACQ_MODE_RO   (uint16_t) (0x0200)

Definition at line 44 of file caenv1190B.h.

Referenced by v1190_AcqModeRead(), and v1190B_AcqModeRead().

#define V1190_ALMOST_FULL   (uint16_t) (0x0002)

Definition at line 24 of file caenv1190B.h.

#define V1190_CONTINUOUS_WO   (uint16_t) (0x0100)

Definition at line 43 of file caenv1190B.h.

Referenced by v1190_ContinuousSet(), and v1190B_ContinuousSet().

#define V1190_CR_RW   (uint16_t) (0x1000>>1)

Definition at line 21 of file caenv1190B.h.

#define V1190_DATA_READY   (uint16_t) (0x0001)

Definition at line 23 of file caenv1190B.h.

Referenced by v1190_DataReady().

#define V1190_EVT_CNT_RO   (uint16_t) (0x101C>>1)

Definition at line 33 of file caenv1190B.h.

Referenced by v1190_EvtCounter().

#define V1190_EVT_STORED_RO   (uint16_t) (0x1020>>1)

Definition at line 34 of file caenv1190B.h.

Referenced by v1190_EvtStored().

#define V1190_FIRM_REV_RO   (uint16_t) (0x1026>>1)

Definition at line 35 of file caenv1190B.h.

#define V1190_FULL   (uint16_t) (0x0004)

Definition at line 25 of file caenv1190B.h.

#define V1190_GEO_REG_RW   (uint16_t) (0x001E)

Definition at line 28 of file caenv1190B.h.

Referenced by v1190_GeoWrite().

#define V1190_HEADER_ENABLE   (uint16_t) (0x0010)

Definition at line 27 of file caenv1190B.h.

#define V1190_MAX_CHANNELS   (uint16_t) 64

Definition at line 19 of file caenv1190B.h.

#define V1190_MICRO_HAND_RO   (uint16_t) (0x1030>>1)

Definition at line 37 of file caenv1190B.h.

Referenced by v1190_MicroRead(), and v1190_MicroWrite().

#define V1190_MICRO_RD_OK   (uint16_t) (0x0002)

Definition at line 39 of file caenv1190B.h.

Referenced by v1190_MicroRead().

#define V1190_MICRO_RW   (uint16_t) (0x102E>>1)

Definition at line 36 of file caenv1190B.h.

Referenced by v1190_MicroRead(), and v1190_MicroWrite().

#define V1190_MICRO_TDCID   (uint16_t) (0x6000)

Definition at line 40 of file caenv1190B.h.

Referenced by v1190_TdcIdList().

#define V1190_MICRO_WR_OK   (uint16_t) (0x0001)

Definition at line 38 of file caenv1190B.h.

Referenced by v1190_MicroWrite().

#define V1190_MODULE_RESET_WO   (uint16_t) (0x1014>>1)

Definition at line 29 of file caenv1190B.h.

Referenced by v1190_SoftReset().

#define V1190_REG_BASE   (uint16_t) (0x1000>>1)

Definition at line 20 of file caenv1190B.h.

#define V1190_RESOLUTION_RO   (uint16_t) (0x2600)

Definition at line 41 of file caenv1190B.h.

Referenced by v1190_ResolutionRead(), and v1190B_ResolutionRead().

#define V1190_SOFT_CLEAR_WO   (uint16_t) (0x1016>>1)

Definition at line 30 of file caenv1190B.h.

Referenced by v1190_SoftClear().

#define V1190_SOFT_EVT_RESET_WO   (uint16_t) (0x1018>>1)

Definition at line 31 of file caenv1190B.h.

#define V1190_SOFT_TRIGGER_WO   (uint16_t) (0x101A>>1)

Definition at line 32 of file caenv1190B.h.

Referenced by v1190_SoftTrigger().

#define V1190_SR_RO   (uint16_t) (0x1002>>1)

Definition at line 22 of file caenv1190B.h.

Referenced by v1190_DataReady().

#define V1190_TRIGGER_MATCH   (uint16_t) (0x0008)

Definition at line 26 of file caenv1190B.h.

#define V1190_TRIGGER_MATCH_WO   (uint16_t) (0x0000)

Definition at line 42 of file caenv1190B.h.

Referenced by v1190_TriggerMatchingSet(), and v1190B_TriggerMatchingSet().

#define V1190B_H_INCLUDED   1

Definition at line 15 of file caenv1190B.h.


Function Documentation

int udelay ( int  usec  ) 

Definition at line 402 of file caenv1190B.c.

00403 {
00404   int i, j, k = 0;
00405   for (i=0; i<133; i++)
00406     for (j=0; j<usec; j++)
00407       k += (k+1)*j*k*(j+1);
00408   return k;
00409 }

int v1190_DataRead ( DWORD base,
uint32_t *  dest,
int  maxwords 
)

Definition at line 64 of file caenv1190B.c.

00065 {
00066   int i;
00067   for (i=0; i<maxwords; i++)
00068     {
00069       if (!v1190_DataReady((uint16_t *)pbase))
00070         break;
00071       *dest++ = *pbase;
00072     }
00073   return i;
00074 }

int v1190_DataReady ( uint16_t *  pbase  ) 

Definition at line 102 of file caenv1190B.c.

00103 {
00104   return (pbase[V1190_SR_RO] & V1190_DATA_READY);
00105 }

void v1190_DataReset ( uint16_t *  pbase  ) 

int v1190_EventRead ( DWORD base,
DWORD pdest,
int *  nentry 
)

Definition at line 21 of file caenv1190B.c.

00022 {
00023   uint32_t hdata;
00024 
00025   *nentry = 0;
00026   if (v1190_DataReady((WORD *)pbase)) {
00027     do {
00028       hdata = *pbase;
00029     } while (!(hdata & 0x40000000));
00030     pdest[*nentry] = hdata;
00031     *nentry += 1;
00032     do {
00033       pdest[*nentry] = *pbase;
00034       *nentry += 1;
00035     } while (!(pdest[*nentry-1] & 0xc0000000)); 
00036 
00037     nentry--;
00038   }
00039   return *nentry;
00040 
00041 /*
00042   header = *pbase & 0xFF000000;
00043   
00044   switch (header) {
00045   case 0x40000000:  // Global Header 
00046     break;
00047   case 0x00000000:  // TDC Header
00048     break;
00049   case 0x10000000:  // Data
00050     break;
00051   case 0x20000000:  // Error
00052     break;
00053   case 0x80000000:  // Trailer
00054     break;
00055   case 0xc0000000:  // Filler
00056     break;
00057   }
00058   
00059   return *nentry;
00060 */
00061 }

int v1190_EvtCounter ( uint16_t *  pbase  ) 

Definition at line 114 of file caenv1190B.c.

00115 {
00116   return (pbase[V1190_EVT_CNT_RO]);
00117 }

int v1190_EvtStored ( uint16_t *  pbase  ) 

Definition at line 108 of file caenv1190B.c.

00109 {
00110   return (pbase[V1190_EVT_STORED_RO]);
00111 }

int v1190_GeoWrite ( WORD pbase,
int  geo 
)

Definition at line 77 of file caenv1190B.c.

00078 {
00079   pbase[V1190_GEO_REG_RW] = (geo & 0x1F);
00080   return (int) (pbase[V1190_GEO_REG_RW] & 0x1F); 
00081 }

int v1190_MicroCheck ( const uint16_t *  pbase,
int  what 
)

int v1190_MicroFlush ( const uint16_t *  pbase  ) 

Definition at line 247 of file caenv1190B.c.

00248 {
00249   int count = 0;
00250   while (1)
00251     {
00252       int data = v1190_MicroRead(pbase);
00253       printf("microData[%d]: 0x%04x\n",count,data);
00254       if (data < 0)
00255         break;
00256       count++;
00257     }
00258   return count;
00259 }

int v1190_MicroRead ( const uint16_t *  pbase  ) 

Definition at line 229 of file caenv1190B.c.

00230 {
00231   int i;
00232   int reg=-1;
00233 
00234   for (i=100; i>0; i--) {
00235     uint16_t  microHS = pbase[V1190_MICRO_HAND_RO];
00236     if (microHS & V1190_MICRO_RD_OK) {
00237       reg = pbase[V1190_MICRO_RW];
00238 //      printf("i:%d microHS:%d %x\n", i, microHS, reg);
00239       return (reg);
00240     }
00241     udelay(500);
00242   };
00243   return -1;
00244 }

int v1190_MicroWrite ( uint16_t *  pbase,
uint16_t  data 
)

Definition at line 211 of file caenv1190B.c.

00212 {
00213   int i;
00214   for (i=0; i<1000; i++)
00215   {
00216     uint16_t microHS = pbase[V1190_MICRO_HAND_RO];
00217     if (microHS & V1190_MICRO_WR_OK) {
00218       pbase[V1190_MICRO_RW] = data;
00219       return 0;
00220     }
00221     udelay(500);
00222   }
00223   
00224   printf("v1190_MicroWrite: Micro not ready for writing!\n");
00225   return -1;
00226 }

void v1190_SetEdgeDetection ( uint16_t *  pbase,
int  enableLeading,
int  enableTrailing 
)

Definition at line 195 of file caenv1190B.c.

00196 {
00197   int value = 0;
00198 
00199   if (enableLeading)
00200     value |= 2;
00201 
00202   if (enableTrailing)
00203     value |= 1;
00204 
00205   v1190_MicroFlush(pbase);
00206   v1190_MicroWrite(pbase, 0x2200);
00207   v1190_MicroWrite(pbase, value);
00208 }

int v1190_Setup ( uint16_t *  pbase,
int  mode 
)

Definition at line 262 of file caenv1190B.c.

00263 {
00264   uint16_t value;
00265   int      status = -1;
00266   
00267 //  v1190_MicroFlush(pbase);
00268   switch (mode) {
00269   case 0x1:
00270     printf("Trigger Matching Setup (mode:%d)\n", mode);
00271     printf("Default setting + Width : 800ns, Offset : -400ns\n");
00272     printf("Time subtract, Leading Edge only\n");
00273     status = v1190_MicroWrite(pbase, 0x0000);
00274     if (status < 0)
00275       return status;
00276 #if 0
00277     value = v1190_MicroWrite(pbase, 0x1000); // width
00278     value = v1190_MicroWrite(pbase, 0x60);     // Width : 800ns
00279     value = v1190_MicroWrite(pbase, 0x1100); // offset
00280     value = v1190_MicroWrite(pbase, 0xfe8);  // offset: -400ns
00281     value = v1190_MicroWrite(pbase, 0x1500); // subtraction flag
00282     value = v1190_MicroWrite(pbase, 0x2100); // leading edge detection
00283 #endif
00284     break;
00285   case 0x2:
00286     value = v1190_MicroWrite(pbase, 0x0500); // default configuration
00287     break;
00288   default:
00289     printf("Unknown setup mode\n");
00290     return -1;
00291   }
00292   v1190_Status(pbase);
00293   return 0;
00294 }

void v1190_SoftClear ( uint16_t *  pbase  ) 

Definition at line 90 of file caenv1190B.c.

00091 {
00092   pbase[V1190_SOFT_CLEAR_WO] = 0;
00093 }

void v1190_SoftReset ( uint16_t *  pbase  ) 

Definition at line 84 of file caenv1190B.c.

00085 {
00086   pbase[V1190_MODULE_RESET_WO] = 0;
00087 }

void v1190_SoftTrigger ( uint16_t *  pbase  ) 

Definition at line 96 of file caenv1190B.c.

00097 {
00098   pbase[V1190_SOFT_TRIGGER_WO] = 0;
00099 }

int v1190_Status ( uint16_t *  pbase  ) 

Definition at line 297 of file caenv1190B.c.

00298 {
00299   uint16_t  i, code, pair=0;
00300   uint32_t value;
00301   
00302   printf("\nAcquisition mode:\n");
00303   value = v1190_MicroWrite(pbase, 0x0200);
00304   value = v1190_MicroRead(pbase);
00305   printf("  mode: 0x%02x\n", value);  
00306 
00307   code = 0x1600;
00308   printf("\nTrigger Section [code:0x%04x]:\n", code);
00309   if ((value = v1190_MicroWrite(pbase, code)) < 0)
00310     return -value;
00311   value = v1190_MicroRead(pbase);
00312   printf("  Match Window width       : 0x%04x\n", value);  
00313   value = v1190_MicroRead(pbase);
00314   printf("  Window offset            : 0x%04x\n", value);  
00315   value = v1190_MicroRead(pbase);
00316   printf("  Extra Search Window Width: 0x%04x\n", value);  
00317   value = v1190_MicroRead(pbase);
00318   printf("  Reject Margin            : 0x%04x\n", value);  
00319   value = v1190_MicroRead(pbase);
00320   printf("  Trigger Time subtration  : %s\n",(value & 0x1) ? "y" : "n");  
00321 
00322   printf("\nEdge Detection & Resolution Section:\n");
00323   code = 0x2300;
00324   value = v1190_MicroWrite(pbase, code);
00325   pair = value = v1190_MicroRead(pbase);
00326   printf("  Edge Detection (1:T/2:L/3:TL)           : 0x%02x\n", (value&0x3));  
00327   code = 0x2600;
00328   value = v1190_MicroWrite(pbase, code);
00329   value = v1190_MicroRead(pbase);
00330   if (pair==0x3) {
00331     value = v1190_MicroRead(pbase);
00332     printf("  Leading Edge Resolution (see table)     : 0x%02x\n", (value&0x3));  
00333     printf("  Pulse Width Resolution (see table)      : 0x%02x\n", ((value>>8)&0xF));  
00334   } else {
00335     printf("  Resolution [ps] (0:800/1:200/2:100)     : 0x%02x\n", (value&0x3));  
00336   }
00337   code = 0x2900;
00338   value = v1190_MicroWrite(pbase, code);
00339   value = v1190_MicroRead(pbase);
00340   printf("  Dead Time between hit [~ns](5/10/30/100): 0x%02x\n", (value&0x3));  
00341   
00342   printf("\nReadout Section:\n");
00343   code = 0x3200;
00344   value = v1190_MicroWrite(pbase, code);
00345   value = v1190_MicroRead(pbase);
00346   printf("  Header/Trailer                            : %s\n",(value & 0x1) ? "y" : "n");  
00347   code = 0x3400;
00348   value = v1190_MicroWrite(pbase, code);
00349   value = v1190_MicroRead(pbase);
00350   printf("  Max #hits per event 2^n-1 (>128:no limit) : %d\n", value&0xF);  
00351   code = 0x3a00;
00352   value = v1190_MicroWrite(pbase, code);
00353   value = v1190_MicroRead(pbase);
00354   printf("  Internal TDC error type (see doc)         : 0x%04x\n", (value&0x7FF));  
00355   code = 0x3c00;
00356   value = v1190_MicroWrite(pbase, code);
00357   value = v1190_MicroRead(pbase);
00358   printf("  Effective size of readout Fifo 2^n-1      : 0x%04x\n", (value&0xF));  
00359   
00360   printf("\nChannel Enable Section:\n");
00361   code = 0x4500;
00362   value = v1190_MicroWrite(pbase, code);
00363   value = v1190_MicroRead(pbase);
00364   printf("  Read Enable Pattern [  0..15 ] : 0x%04x\n", value);  
00365   value = v1190_MicroRead(pbase);
00366   printf("  Read Enable Pattern [ 16..31 ] : 0x%04x\n", value);  
00367   value = v1190_MicroRead(pbase);
00368   printf("  Read Enable Pattern [ 32..47 ] : 0x%04x\n", value);  
00369   value = v1190_MicroRead(pbase);
00370   printf("  Read Enable Pattern [ 48..63 ] : 0x%04x\n", value);  
00371   code = 0x4700;
00372   value = v1190_MicroWrite(pbase, code);
00373   value = v1190_MicroRead(pbase);
00374   value = (v1190_MicroRead(pbase)<<16) | value;
00375   printf("  Read Enable Pattern 32 (0) : 0x%08x\n", value);  
00376   code = 0x4701;
00377   value = v1190_MicroWrite(pbase, code);
00378   value = v1190_MicroRead(pbase);
00379   value = (v1190_MicroRead(pbase)<<16) | value;
00380   printf("  Read Enable Pattern 32 (1) : 0x%08x\n", value);  
00381   printf("\nAdjust Section:\n");
00382   code = 0x5100;
00383   value = v1190_MicroWrite(pbase, code);
00384   value = v1190_MicroRead(pbase);
00385   printf("  Coarse Counter Offset: 0x%04x\n", (value&0x7FF));  
00386   value = v1190_MicroRead(pbase);
00387   printf("  Fine   Counter Offset: 0x%04x\n", (value&0x1F));  
00388   printf("\nMiscellaneous Section:\n");
00389   for (i=0; i<2 ; i++) {
00390     code = 0x6000 | (i & 0x0F);
00391     value = v1190_MicroWrite(pbase, code);
00392     value = v1190_MicroRead(pbase);
00393     value = (v1190_MicroRead(pbase) << 16) | value;
00394     printf("  TDC ID(%i)  0x%08x  [code:0x%04x]\n", i, value, code);  
00395   }
00396   return 0;
00397 }

int v1190B_AcqModeRead ( uint16_t *  pbase  ) 

Definition at line 153 of file caenv1190B.c.

00154 {
00155   uint16_t  code;
00156   uint32_t value;
00157 
00158 //  v1190_MicroFlush(pbase);
00159   code = V1190_ACQ_MODE_RO;
00160   value = v1190_MicroWrite(pbase, code);
00161   value = v1190_MicroRead(pbase);
00162 //  printf("Received :code: 0x%04x  0x%08x\n", code, value); 
00163   return 1;
00164 }

int v1190B_ContinuousSet ( uint16_t *  pbase  ) 

Definition at line 181 of file caenv1190B.c.

00182 {
00183   uint16_t  code;
00184   uint32_t value;
00185 
00186 //  v1190_MicroFlush(pbase);
00187   code = V1190_CONTINUOUS_WO;
00188   value = v1190_MicroWrite(pbase, code);
00189 //  printf("Received :code: 0x%04x  0x%08x\n", code, value); 
00190   
00191   return 1;
00192 }

int v1190B_ResolutionRead ( uint16_t *  pbase  ) 

Definition at line 137 of file caenv1190B.c.

00138 {
00139   uint16_t  i, code;
00140   uint32_t value;
00141 
00142 //  v1190_MicroFlush(pbase);
00143   for (i=0; i<2 ; i++) {
00144     code = V1190_RESOLUTION_RO | (i & 0x0F);
00145     value = v1190_MicroWrite(pbase, code);
00146     value = v1190_MicroRead(pbase);
00147 //    printf("Received :code: 0x%04x  0x%08x\n", code, value); 
00148   }
00149   return 1;
00150 }

int v1190B_TdcIdList ( uint16_t *  pbase  ) 

Definition at line 120 of file caenv1190B.c.

00121 {
00122   uint16_t  i, code;
00123   uint32_t value;
00124 
00125 //  v1190_MicroFlush(pbase);
00126   for (i=0; i<2 ; i++) {
00127     code   = 0x6000 | (i & 0x0F);
00128     value  = v1190_MicroWrite(pbase, code);
00129     value  = v1190_MicroRead(pbase);
00130     value = (v1190_MicroRead(pbase) << 16) | value;
00131     printf("Received :code: 0x%04x  0x%08x\n", code, value); 
00132   }
00133   return 1;
00134 }

int v1190B_TriggerMatchingSet ( uint16_t *  pbase  ) 

Definition at line 167 of file caenv1190B.c.

00168 {
00169   uint16_t  code;
00170   uint32_t value;
00171 
00172 //  v1190_MicroFlush(pbase);
00173   code = V1190_TRIGGER_MATCH_WO;
00174   value = v1190_MicroWrite(pbase, code);
00175 //  printf("Received :code: 0x%04x  0x%08x\n", code, value); 
00176   
00177   return 1;
00178 }


Midas DOC Version 3.0.0 ---- 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