/* Routines for configuring the LRS1881M ADC and LRS1877 TDC */ #include #include #include #include #include #include #include #include #include #include #define BYPASS 0x0 #define PRIMARY_LINK 0x800 #define END_LINK 0x1000 #define MIDDLE_LINK 0x1800 /* This enum was copied from translation.h in the PrimEx code */ enum MODULE_TYPE_t{ MODULE_NONE, MODULE_UNKNOWN, MODULE_LRS1881M, MODULE_LRS1877, MODULE_TS2, NUM_MODULE_TYPES }; #define MAX_SLOTS 25 int MODULE_TYPE[MAX_SLOTS]; int Nmodules=0; int SlotHi=0, SlotLo=0, SlotsContiguous=0; char myhostname[256]; extern volatile struct sfiStruct sfi; /*---------------------------------- /* Set1881SparsificationThresholds /*----------------------------------*/ int Set1881SparsificationThresholds(char *myhostname,int slot) { char fname[512]; FILE *file=NULL; char buff[1024], *ptr; int nbytes=0; unsigned long thresholds[64]; int nthresholds=0; int i,status; /* Enable SFI Sequencer (what does this do again?) */ *sfi.sequencerEnable = 1; /* Try opening file */ sprintf(fname,"/usr/local/primex/online/config/sparsification_%s_slot%d.dat",myhostname,slot); file = fopen(fname,"r"); if(!file){ printf("missing file \"%s\"\n",fname); return -1; } /* Read in entire file contents and remove comments */ nbytes = fread(buff,1,1023,file); fclose(file); if(nbytes>1020){ printf("File too long \"%s\"\n", fname); return -2; } buff[nbytes]=0; /* ensure a terminating null for string operations */ while(ptr=strstr(buff,"#")){ char *ptr2; if(ptr2=strstr(ptr,"\n")){ strcpy(ptr,++ptr2); }else{ *ptr = 0; } } /* Loop over entries and copy thresholds into local array */ ptr = strtok(buff,"\n"); while(ptr){ if(nthresholds<64)thresholds[nthresholds++] = atoi(ptr); ptr = strtok(NULL,"\n"); } if(nthresholds != 64)printf("ERROR: "); printf("%d entires found in \"%s\"\n",nthresholds,fname); if(nthresholds>64)nthresholds=64; /* Program sparsification thresholds */ for(i=0;i0xFFF)scale=0xFFF; printf("Setting time window to %f microseconds (input=%d)\n" ,32.768*(float)scale/(float)0xFFF, microseconds); for(slot=0;slot