doubleTriggerBurstSequence.cxx

00001 // problems: if runnin in burst, random mode with FFT veto
00002 // - how to poll for end?
00003 // - how to check for vetos?
00004 
00005 void doubleTriggerBurstSequence(bool burst=true, bool random=false){
00006  if (random && !burst) {
00007     printf("random only allowed in burst mode\n");
00008     return;
00009  } 
00010 printf("starting double trigger sequence:, burst %b, random %b\n",burst,random);
00011 
00012 const int length=300;
00013 const unsigned long ntrigs=100000;
00014 
00015 int* ttrigs = new int[length];
00016 printf ("allocated ttrigs[%d]\n",length);
00017 
00018 for (int i=0; i<length; ++i){
00019   ttrigs[i]=0;
00020 }
00021 
00022 // add a couple of L1As:
00023 ttrigs[0]=0x01;
00024 ttrigs[130]=0x01;
00025 // sequence end
00026 
00027 
00028 // reset sequence control - need to do this before loading the sequence
00029 tapi.timRegLoad(0x1a,0x0200);
00030 tapi.timRegLoad(0x1a,0x0);
00031 
00032 // load the sequence
00033 tapi.timRegLoad(0x1C,length-1);
00034 for (int i=0; i<length; ++i){
00035   tapi.timRegLoad(0x8000 + i*2, ttrigs[i]);
00036   int in = tapi.timReadRegister(0x8000 + i*2);
00037   //printf("in[%d]=0x%x (%x)\n",i,in,trigs[i]);
00038 }
00039 
00040 // enables
00041 if (!random){
00042   tapi.timRegLoad(0x0,0xFDFD);
00043   tapi.timRegLoad(0x18,0xFFFD);
00044 }
00045 
00046 // L1 counters
00047 tapi.timRegLoad(0x12,0x0); 
00048 tapi.timRegLoad(0x10,0x0);
00049 
00050 printf("Using burst register? %b\n",burst);
00051 
00052 if (burst){
00053   // set the burst counter
00054   tapi.timRegLoad(0x04, (ntrigs & 0xffff ) );
00055   tapi.timRegLoad(0x8e, (ntrigs >> 16) );
00056 
00057   // set burst mode
00058   tapi.timRegLoad(0x02,0x200);
00059 
00060   if (random) {
00061     // trigger, go
00062     tapi.timRegLoad(0x1a,0x0401);
00063     tapi.timRegLoad(0x42,0x100);
00064     tapi.timRegLoad(0x00,0x12);
00065   }else{
00066     // trigger, cyclic, go
00067     tapi.timRegLoad(0x1a,0x0C01);
00068   }
00069 
00070   // set burst go + burst mode
00071   tapi.timRegLoad(0x02,0x600);
00072 
00073 }else{
00074   // set up sequencer in trigger, cyclic go mode
00075   tapi.timRegLoad(0x1a,0x0C01);
00076 }
00077 
00078 unsigned long l1id=0;
00079 unsigned long poll=0;
00080 unsigned long unchanged_polls=0;
00081 bool stalled=false;
00082 unsigned long lastl1id=-1;
00083 do{
00084   poll++;
00085   l1id = ((tapi.timReadRegister(0x12)<<16) + (tapi.timReadRegister(0x10)));
00086 
00087   //intermittent diagnostics
00088   if (poll%(ntrigs/10)==0){
00089     printf("%d of %d sent \n",l1id,ntrigs,lastl1id);
00090 
00091     // check if l1id has stopped increasing
00092     if (l1id==lastl1id) {
00093       unchanged_polls++;
00094       if (unchanged_polls>10) stalled=true;
00095     }else{
00096       unchanged_polls=0;
00097     }
00098   }
00099   lastl1id=l1id;
00100 } while ((l1id<ntrigs) && !stalled);
00101 
00102 if (stalled) printf("stalled\n");
00103 const bool incomplete=(burst && l1id!=ntrigs);
00104 if (incomplete){
00105   printf("Incorrect number of triggers sent - %d rather than %d\n",l1id,ntrigs);
00106 }
00107 
00108 if (incomplete || stalled) {
00109   for (unsigned reg=0; reg<0x1F; ++reg){
00110      printf ("reg 0x%x=0x%x\t",reg,tapi.timReadRegister(reg));
00111      if (reg%4==0) printf("\n");
00112   }
00113   printf("\n\n");
00114 }
00115 
00116 // stop the sequence, reset other registers
00117 tapi.timRegLoad(0x1a,0x0);
00118 tapi.timRegLoad(0x02,0x0);
00119 tapi.timRegLoad(0x04,0x0);
00120 tapi.timRegLoad(0x8e,0x0);
00121 if (random) tapi.timRegLoad(0x00,0x0);
00122 if (burst)  tapi.timRegLoad(0x02,0x0);
00123 
00124 unsigned outl1id = tapi.timReadRegister(0x10) + (tapi.timReadRegister(0x12)<<16);
00125 printf("number of l1ids sent was %d \n\n",outl1id);
00126 
00127 
00128 for (int i=0; i<length; ++i){
00129   int out = tapi.timReadRegister(0x8000 + i*2);
00130   if (out==0){
00131     printf(".");
00132   }else if (out==0xffff){
00133     printf("x");
00134   }else{
00135     printf("\nOutput[%d]=0x%x\n",i,out);
00136   }
00137 }
00138 printf("\n");
00139 
00140 delete[] ttrigs;
00141 
00142 } // end of macro
00143 
00144 

Generated on Mon Feb 6 14:01:19 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6