mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 04:47:14 +02:00
After meeting on 30.11.09 - Some functions became pure virtual in slsDetector and have been moved to mythenDetector - setSpeed function added
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@3 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
@ -13,8 +13,8 @@ INSTMODE= 0777
|
||||
SRCS= server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
|
||||
OBJS= $(SRCS:%.c=%.o)
|
||||
|
||||
CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS
|
||||
# -DVERBOSE
|
||||
CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DVERBOSE
|
||||
# -DVERYVERBOSE
|
||||
#-Werror
|
||||
|
||||
LDLIBS+= -lm
|
||||
@ -25,7 +25,7 @@ boot: $(OBJS)
|
||||
|
||||
$(PROGS): $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
||||
$(CC) $(LDFLAGS) $^ $(LDLIBS) $(CFLAGS) -o $@
|
||||
|
||||
install: $(PROGS)
|
||||
$(INSTALL) -d $(INSTDIR)
|
||||
|
@ -179,7 +179,7 @@ u_int32_t setWaitStates(int d1) {
|
||||
u_int32_t c;
|
||||
int d=d1-2;
|
||||
char cmd[100];
|
||||
sprintf(cmd,"bus -a 0xb0000000 -w 0xd000%1x",d1);
|
||||
sprintf(cmd,"bus -a 0xb0000000 -w 0x%x0008",d1);
|
||||
c=bus_r(SPEED_REG);
|
||||
bus_w(SPEED_REG,(d<<WAIT_STATES_OFFSET)|(c&~(WAIT_STATES_MASK)));
|
||||
system(cmd);
|
||||
@ -280,7 +280,7 @@ u_int32_t getMcsVersion() {
|
||||
u_int32_t testFpga(void) {
|
||||
u_int32_t val;
|
||||
int result=OK;
|
||||
|
||||
//while (1) {
|
||||
//fixed pattern
|
||||
val=bus_r(FIX_PATT_REG);
|
||||
if (val==FIXED_PATT_VAL) {
|
||||
@ -320,6 +320,20 @@ u_int32_t testFpga(void) {
|
||||
result=FAIL;
|
||||
// return FAIL;
|
||||
}
|
||||
// }
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// for fpga test
|
||||
u_int32_t testRAM(void) {
|
||||
int result=OK;
|
||||
int i=0;
|
||||
allocateRAM();
|
||||
// while(i<100000) {
|
||||
memcpy(ram_values, values, dataBytes);
|
||||
printf ("%d: copied fifo %x to memory %x size %d\n",i++, values, ram_values, dataBytes);
|
||||
// }
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -350,14 +364,16 @@ int setNMod(int n) {
|
||||
/* should enable all fifos*/
|
||||
bus_w(FIFO_CNTRL_REG_OFF+(ALLFIFO<<SHIFTMOD), FIFO_RESET_BIT | FIFO_DISABLE_TOGGLE_BIT);
|
||||
|
||||
/*disable the fifos relative to the unused modules */
|
||||
/*d isable the fifos relative to the unused modules */
|
||||
|
||||
ifste=NCHAN*dynamicRange/32;
|
||||
ifsta=nModX*NCHIP*ifste;
|
||||
ifsto=nModBoard*NCHIP*ifste;
|
||||
|
||||
for (ififo=ifsta; ififo<ifsto; ififo+=ifste) {
|
||||
fifocntrl[ififo]=FIFO_DISABLE_TOGGLE_BIT;
|
||||
//fifocntrl[ififo]=FIFO_DISABLE_TOGGLE_BIT;
|
||||
bus_w(FIFO_CNTRL_REG_OFF+(ififo<<SHIFTMOD), FIFO_DISABLE_TOGGLE_BIT);
|
||||
printf("Disabling fifo %d\n",ififo);
|
||||
}
|
||||
|
||||
|
||||
@ -665,6 +681,9 @@ u_int32_t* fifo_read_event()
|
||||
}
|
||||
#endif
|
||||
memcpy(now_ptr, values, dataBytes);
|
||||
#ifdef VERBOSE
|
||||
printf("Copying to ptr %x %d\n",now_ptr, dataBytes);
|
||||
#endif
|
||||
#ifdef VERYVERBOSE
|
||||
printf("after readout\n");
|
||||
for (ichip=0; ichip<nModBoard*NCHIP; ichip++) {
|
||||
@ -682,7 +701,7 @@ u_int32_t* fifo_read_event()
|
||||
|
||||
u_int32_t* decode_data(int *datain)
|
||||
{
|
||||
int *dataout;
|
||||
u_int32_t *dataout;
|
||||
const char one=1;
|
||||
const int bytesize=8;
|
||||
char *ptr=(char*)datain;
|
||||
@ -699,7 +718,6 @@ u_int32_t* decode_data(int *datain)
|
||||
for (ibyte=0; ibyte<dataBytes; ibyte++) {
|
||||
iptr=ptr[ibyte];
|
||||
for (ipos=0; ipos<bytesize; ipos++) {
|
||||
// dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
|
||||
dataout[ichan]=(iptr>>(ipos))&0x1;
|
||||
ichan++;
|
||||
}
|
||||
@ -709,7 +727,6 @@ u_int32_t* decode_data(int *datain)
|
||||
for (ibyte=0; ibyte<dataBytes; ibyte++) {
|
||||
iptr=ptr[ibyte]&0xff;
|
||||
for (ipos=0; ipos<2; ipos++) {
|
||||
// dataout[ibyte*2+ichan]=((iptr&((0xf)<<ichan))>>ichan)&0xf;
|
||||
dataout[ichan]=(iptr>>(ipos*4))&0xf;
|
||||
ichan++;
|
||||
}
|
||||
@ -731,7 +748,7 @@ u_int32_t* decode_data(int *datain)
|
||||
break;
|
||||
default:
|
||||
for (ichan=0; ichan<nChans*nChips*nModX; ichan++)
|
||||
dataout[ichan]=datain[ichan];//&0xffffff;
|
||||
dataout[ichan]=datain[ichan]&0xffffff;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
@ -743,17 +760,11 @@ u_int32_t* decode_data(int *datain)
|
||||
|
||||
|
||||
int setDynamicRange(int dr) {
|
||||
|
||||
|
||||
|
||||
|
||||
int ow;
|
||||
u_int32_t np=getProbes();
|
||||
#ifdef VERYVERBOSE
|
||||
printf("probes==%02x\n",np);
|
||||
#endif
|
||||
|
||||
|
||||
if (dr>0) {
|
||||
if (dr<=1) {
|
||||
dynamicRange=1;
|
||||
@ -850,20 +861,31 @@ int setStoreInRAM(int b) {
|
||||
|
||||
int allocateRAM() {
|
||||
size_t size;
|
||||
|
||||
u_int32_t nt, nf;
|
||||
nt=setTrains(-1);
|
||||
nf=setFrames(-1);
|
||||
if (nt==0) nt=1;
|
||||
if (nf==0) nf=1;
|
||||
// ret=clearRAM();
|
||||
if (storeInRAM) {
|
||||
size=dataBytes*setFrames(-1);
|
||||
#ifdef VERBOSE
|
||||
// printf("nmodx=%d nmody=%d dynamicRange=%d dataBytes=%d nFrames=%d size=%d\n",nModX,nModY,dynamicRange,dataBytes,setFrameNumber(-1),size );
|
||||
#endif
|
||||
size=dataBytes*nf*nt;
|
||||
if (size<dataBytes)
|
||||
size=dataBytes;
|
||||
} else
|
||||
size=dataBytes;
|
||||
|
||||
if (size==ram_size)
|
||||
return OK;
|
||||
#ifdef VERBOSE
|
||||
printf("nmodx=%d nmody=%d dynamicRange=%d dataBytes=%d nFrames=%d nTrains, size=%d\n",nModX,nModY,dynamicRange,dataBytes,nf,nt,size );
|
||||
#endif
|
||||
|
||||
if (size==ram_size) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("RAM of size %d already allocated: nothing to be done\n", size);
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -892,6 +914,7 @@ int allocateRAM() {
|
||||
printf("Fatal error: there must be a memory leak somewhere! You can't allocate even one frame!\n");
|
||||
else {
|
||||
now_ptr=(char*)ram_values;
|
||||
ram_size=size;
|
||||
#ifdef VERBOSE
|
||||
printf("ram allocated 0x%x of size %d to %x\n",now_ptr, size, now_ptr+size);
|
||||
#endif
|
||||
|
@ -44,6 +44,7 @@ u_int64_t getMcsNumber();
|
||||
u_int32_t getMcsVersion();
|
||||
u_int32_t testFifos(void);
|
||||
u_int32_t testFpga(void);
|
||||
u_int32_t testRAM(void);
|
||||
int testBus(void);
|
||||
int64_t set64BitReg(int64_t value, int aLSB, int aMSB);
|
||||
int64_t get64BitReg(int aLSB, int aMSB);
|
||||
|
@ -16,6 +16,8 @@
|
||||
#undef DEBUGOUT
|
||||
|
||||
extern int nModX;
|
||||
extern int dataBytes;
|
||||
extern int dynamicRange;
|
||||
const int nChans=NCHAN;
|
||||
const int nChips=NCHIP;
|
||||
const int nDacs=NDAC;
|
||||
@ -74,6 +76,7 @@ int initDetector() {
|
||||
(detectorModules+imod)->module=imod;
|
||||
(detectorModules+imod)->gain=0;
|
||||
(detectorModules+imod)->offset=0;
|
||||
(detectorModules+imod)->reg=0;
|
||||
/* initialize registers, dacs, retrieve sn, adc values etc */
|
||||
}
|
||||
thisSettings=UNINITIALIZED;
|
||||
@ -89,7 +92,9 @@ int initDetector() {
|
||||
putout("0000000000000000",ALLMOD);
|
||||
|
||||
/* initialize dynamic range etc. */
|
||||
nModX=n;
|
||||
nModX=n;
|
||||
dataBytes=nModX*NCHIP*NCHAN*4;
|
||||
dynamicRange=32;
|
||||
initChip(0, 1,ALLMOD);
|
||||
// allocateRAM();
|
||||
|
||||
@ -135,13 +140,24 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
|
||||
|
||||
int ichip, idac, ichan, iadc;
|
||||
|
||||
int ret=FAIL;
|
||||
if (srcMod->module>=0)
|
||||
destMod->module=srcMod->module;
|
||||
int ret=OK;
|
||||
|
||||
if (srcMod->serialnumber>=0)
|
||||
#ifdef VERBOSE
|
||||
printf("Copying module %x to module %x\n",srcMod,destMod);
|
||||
#endif
|
||||
|
||||
if (srcMod->module>=0) {
|
||||
#ifdef VERBOSE
|
||||
printf("Copying module number %d to module number %d\n",srcMod->module,destMod->module);
|
||||
#endif
|
||||
destMod->module=srcMod->module;
|
||||
}
|
||||
if (srcMod->serialnumber>=0){
|
||||
/* #ifdef VERBOSE */
|
||||
/* printf("Copying module serial number %x to module serial number %x\n",srcMod->serialnumber,destMod->serialnumber); */
|
||||
/* #endif */
|
||||
destMod->serialnumber=srcMod->serialnumber;
|
||||
|
||||
}
|
||||
if ((srcMod->nchip)>(destMod->nchip)) {
|
||||
printf("Number of chip of source is larger than number of chips of destination\n");
|
||||
return FAIL;
|
||||
@ -158,13 +174,26 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
|
||||
printf("Number of dacs of source is larger than number of dacs of destination\n");
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("DACs: src %d, dest %d\n",srcMod->ndac,destMod->ndac);
|
||||
printf("ADCs: src %d, dest %d\n",srcMod->nadc,destMod->nadc);
|
||||
printf("Chips: src %d, dest %d\n",srcMod->nchip,destMod->nchip);
|
||||
printf("Chans: src %d, dest %d\n",srcMod->nchan,destMod->nchan);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
destMod->ndac=srcMod->ndac;
|
||||
destMod->nadc=srcMod->nadc;
|
||||
destMod->nchip=srcMod->nchip;
|
||||
destMod->nchan=srcMod->nchan;
|
||||
if (srcMod->reg>=0)
|
||||
destMod->reg=srcMod->reg;
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Copying register %x (%x)\n",destMod->reg,srcMod->reg );
|
||||
#endif
|
||||
if (srcMod->gain>=0)
|
||||
destMod->gain=srcMod->gain;
|
||||
if (srcMod->offset>=0)
|
||||
@ -188,7 +217,6 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
|
||||
if (*((srcMod->adcs)+iadc)>=0)
|
||||
*((destMod->adcs)+iadc)=*((srcMod->adcs)+iadc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -440,13 +468,13 @@ int program_one_dac(int addr, int value, int imod) {
|
||||
// myMod=detectorModules+imod;
|
||||
//(detectorModules+imod)->dacs[idac]=v;
|
||||
#ifdef VERBOSE
|
||||
printf("module=%d index=%d, val=%d\n",imod, idac, v);
|
||||
printf("module=%d index=%d, val=%d addr=%x\n",imod, idac, v, detectorDacs+idac+NDAC*imod);
|
||||
#endif
|
||||
detectorDacs[idac+NDAC*imod]=v;
|
||||
} else if (imod==ALLMOD) {
|
||||
for (im=0; im<getNModBoard(); im++) {
|
||||
#ifdef VERBOSE
|
||||
printf("all: module=%d index=%d, val=%d\n",im, idac, v);
|
||||
printf("all: module=%d index=%d, val=%d addr=%x\n",im, idac, v,detectorDacs+idac+NDAC*im);
|
||||
#endif
|
||||
detectorDacs[idac+NDAC*im]=v;
|
||||
// (detectorModules+im)->dacs[idac]=v;
|
||||
@ -642,10 +670,12 @@ int setThresholdEnergy(int ethr) {
|
||||
|
||||
float getDACbyIndexDACU(int ind, int imod) {
|
||||
|
||||
if (detectorDacs)
|
||||
return (detectorDacs[ind+imod*NDAC]);
|
||||
else
|
||||
return FAIL;
|
||||
if (detectorDacs) {
|
||||
if (imod<getNModBoard())
|
||||
if (ind<(detectorModules+imod)->ndac)
|
||||
return (detectorDacs[ind+imod*NDAC]);
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
@ -725,9 +755,9 @@ int setSettings(int i) {
|
||||
v[RGPR]=rgpr[i];
|
||||
v[RGSH1]=rgsh1[i];
|
||||
v[RGSH2]=rgsh2[i];
|
||||
break;
|
||||
initDACs(v,ALLMOD);
|
||||
thisSettings=i;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -743,13 +773,19 @@ int setSettings(int i) {
|
||||
isett=is;
|
||||
}
|
||||
}
|
||||
for (imod=1; imod<getNModBoard(); imod++) {
|
||||
#ifdef VERBOSE
|
||||
printf("Settings of module 0 are %d\n",isett);
|
||||
#endif
|
||||
for (imod=1; imod<nModX; imod++) {
|
||||
if (isett!=UNDEFINED) {
|
||||
irgpr=detectorDacs[4+imod*NDAC];
|
||||
irgsh1=detectorDacs[imod*NDAC+RGSH1];
|
||||
irgsh2=detectorDacs[imod*NDAC+RGSH2];
|
||||
if (irgpr!=rgpr[isett] || irgsh1!=rgsh1[isett] || irgsh2!=rgsh2[isett]) {
|
||||
isett=UNDEFINED;
|
||||
#ifdef VERBOSE
|
||||
printf("Settings of module %d are undefined\n",imod);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -801,17 +837,23 @@ int getChannelbyNumber(sls_detector_channel* myChan) {
|
||||
ichip=myChan->chip;
|
||||
ichan=myChan->chan;
|
||||
|
||||
if (detectorChans)
|
||||
myChan->reg=detectorChans[imod*NCHAN*NCHIP+ichip*NCHAN+ichan];
|
||||
else
|
||||
return FAIL;
|
||||
return OK;
|
||||
if (detectorChans) {
|
||||
if (imod<getNModBoard()) {
|
||||
if (ichip<(detectorModules+imod)->nchip && ichan<(detectorModules+imod)->nchan/(detectorModules+imod)->nchip)
|
||||
myChan->reg=detectorChans[imod*NCHAN*NCHIP+ichip*NCHAN+ichan];
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
return FAIL;
|
||||
|
||||
}
|
||||
|
||||
int getTrimbit(int imod, int ichip, int ichan) {
|
||||
if (detectorChans)
|
||||
return (detectorChans[imod*NCHAN*NCHIP+ichip*NCHAN+ichan] & TRIM_DR);
|
||||
else
|
||||
if (detectorChans) {
|
||||
if (imod<getNModBoard())
|
||||
if (ichip<(detectorModules+imod)->nchip && ichan<(detectorModules+imod)->nchan/(detectorModules+imod)->nchip)
|
||||
return (detectorChans[imod*NCHAN*NCHIP+ichip*NCHAN+ichan] & TRIM_DR);
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -875,10 +917,12 @@ int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts, int imod)
|
||||
for (im=modmi; im<modma; im++) {
|
||||
for (ichip=chipmi; ichip<chipma; ichip++) {
|
||||
for (ichan=chanmi; ichan<chanma; ichan++) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
// printf("im=%d ichi=%d icha=%d tot=%d reg=%x\n",im,ichip, ichan, im*NCHAN*NCHIP+ichip*NCHAN+ichan,detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]);
|
||||
#endif
|
||||
detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]= ft | (cae<<(NTRIMBITS+1)) | (ae<<(NTRIMBITS+2)) | (coe<<(NTRIMBITS+3)) | (ocoe<<(NTRIMBITS+4)) | (counts<<(NTRIMBITS+5));
|
||||
#ifdef VERBOSE
|
||||
// printf("imod=%d ichip=%d ichan=%d reg=%x\n",im,ichip,ichan,detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]);
|
||||
// printf("imod=%d ichip=%d ichan=%d addr=%x reg=%x\n",im,ichip,ichan,detectorChans+im*NCHAN*NCHIP+ichip*NCHAN+ichan, detectorChans[im*NCHAN*NCHIP+ichip*NCHAN+ichan]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -1076,11 +1120,15 @@ int getChipbyNumber(sls_detector_chip* myChip){
|
||||
ichip=myChip->chip;
|
||||
|
||||
if (detectorChips) {
|
||||
myChip->reg=detectorChips[ichip+imod*NCHIP];
|
||||
myChip->nchan=NCHAN;
|
||||
myChip->chanregs=detectorChans+imod*NCHAN*NCHIP+ichip*NCHIP;
|
||||
if (imod<getNModBoard())
|
||||
if (ichip<(detectorModules+imod)->nchip) {
|
||||
myChip->reg=detectorChips[ichip+imod*NCHIP];
|
||||
myChip->nchan=NCHAN;
|
||||
myChip->chanregs=detectorChans+imod*NCHAN*NCHIP+ichip*NCHIP;
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
return FAIL;
|
||||
|
||||
}
|
||||
|
||||
@ -1208,9 +1256,9 @@ int initChip(int obe, int ow,int imod){
|
||||
for (ichip=chipmi; ichip<chipma; ichip++) {
|
||||
// printf("imod %d ichip %d\n",im,ichip);
|
||||
detectorChips[im*NCHIP+ichip]=obe | (ow<<1);
|
||||
/*#ifdef VERBOSE
|
||||
printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*NCHIP+ichip],detectorChips+im*NCHIP+ichip);
|
||||
#endif*/
|
||||
#ifdef VERBOSE
|
||||
//printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*NCHIP+ichip],detectorChips+im*NCHIP+ichip);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1303,9 +1351,9 @@ int initChipWithProbes(int obe, int ow,int nprobes, int imod){
|
||||
for (ichip=chipmi; ichip<chipma; ichip++) {
|
||||
// printf("imod %d ichip %d\n",im,ichip);
|
||||
detectorChips[im*NCHIP+ichip]=obe | (ow<<1);
|
||||
/*#ifdef VERBOSE
|
||||
printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*NCHIP+ichip],detectorChips+im*NCHIP+ichip);
|
||||
#endif*/
|
||||
#ifdef VERBOSE
|
||||
//printf("imod=%d ichip=%d reg=%d (%x)\n",im,ichip,detectorChips[im*NCHIP+ichip],detectorChips+im*NCHIP+ichip);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1323,6 +1371,9 @@ int getNProbes() {
|
||||
int initMCBregisters(int cm, int imod){
|
||||
|
||||
int im, modmi, modma;
|
||||
if (cm<0)
|
||||
return 0;
|
||||
|
||||
|
||||
putout("0000000001000000",imod);
|
||||
putout("0000000001100000",imod);
|
||||
@ -1418,7 +1469,7 @@ int initModulebyNumber(sls_detector_module myMod) {
|
||||
v[VCAL]=(myMod.dacs)[5];
|
||||
v[RGPR]=(myMod.dacs)[4];
|
||||
|
||||
#ifdef VERBOSE
|
||||
/*#ifdef VERBOSE
|
||||
printf("imod=%d\n",imod);
|
||||
printf("Vtrim=%d\n",v[VTRIM]);
|
||||
printf("Vthresh=%d\n",v[VTHRESH]);
|
||||
@ -1427,7 +1478,7 @@ int initModulebyNumber(sls_detector_module myMod) {
|
||||
printf("Vcal=%d\n",v[VCAL]);
|
||||
printf("Rgpr=%d\n",v[RGPR]);
|
||||
#endif
|
||||
|
||||
*/
|
||||
|
||||
initDACs(v,imod);
|
||||
clearCSregister(imod);
|
||||
@ -1459,7 +1510,9 @@ int initModulebyNumber(sls_detector_module myMod) {
|
||||
|
||||
if (detectorModules) {
|
||||
for (im=modmi; im<modma; im++) {
|
||||
#ifdef VERBOSE
|
||||
printf("im=%d\n",im);
|
||||
#endif
|
||||
copyModule(detectorModules+im,&myMod);
|
||||
}
|
||||
}
|
||||
@ -1637,6 +1690,7 @@ int getModuleNumber(int modnum) {
|
||||
int testShiftIn(int imod) {
|
||||
int val,i,j, k, result=OK;
|
||||
setCSregister(ALLMOD);
|
||||
printf("testing shift in for module %d\n", imod);
|
||||
//for (j=0; j<10; j++) {
|
||||
//selChip(j);
|
||||
for (i=0; i<34; i++) {
|
||||
@ -1692,6 +1746,7 @@ int testShiftOut(int imod) {
|
||||
int dum;
|
||||
dum=0xaaaaaa;
|
||||
|
||||
printf("testing shift out for module %d\n", imod);
|
||||
|
||||
setCSregister(254);
|
||||
for (i=0; i<24; i++) {
|
||||
@ -1742,6 +1797,7 @@ int testShiftOut(int imod) {
|
||||
int testShiftStSel(int imod) {
|
||||
int result=OK;
|
||||
int val,i,j,k;
|
||||
printf("testing shift stsel for module %d\n", imod);
|
||||
setCSregister(ALLMOD);
|
||||
for (i=0; i<NCHAN; i++) {
|
||||
if (i%2) {
|
||||
@ -1794,7 +1850,7 @@ int testDataInOut(int num, int imod) {
|
||||
int val[NCHIP*nModX], result=OK;
|
||||
int ich, ichip;
|
||||
setCSregister(ALLMOD);
|
||||
printf("Testing data in out\n");
|
||||
printf("Testing data in out for module %d pattern 0x%x\n", imod, num);
|
||||
setSSregister(ALLMOD);
|
||||
initChannel(0,0,0,0,0,num,ALLMOD);
|
||||
putout("0000000000000000",ALLMOD);
|
||||
@ -1827,6 +1883,7 @@ int testExtPulse(int imod) {
|
||||
int i, ichan, ichip, result=OK;
|
||||
int *val1;
|
||||
|
||||
printf("Testing counter for module %d\n", imod);
|
||||
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
@ -1873,11 +1930,11 @@ int testExtPulse(int imod) {
|
||||
int testExtPulseMux(int imod, int ow) {
|
||||
|
||||
int i, ichan, ichip, result=0, ind;
|
||||
int *values;
|
||||
int *values, *v1;
|
||||
int vright,v;
|
||||
int nbit_mask=0xffffff;
|
||||
|
||||
printf("Testing counter\n");
|
||||
printf("Testing counter for module %d, mux %d\n", imod, ow);
|
||||
setExposureTime(0);
|
||||
setFrames(1);
|
||||
setTrains(1);
|
||||
@ -1894,7 +1951,6 @@ int testExtPulseMux(int imod, int ow) {
|
||||
|
||||
|
||||
|
||||
printf("mux %d\n",ow);
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
@ -1919,9 +1975,9 @@ int testExtPulseMux(int imod, int ow) {
|
||||
|
||||
startReadOut();
|
||||
usleep(100);
|
||||
values=fifo_read_event();
|
||||
if (values)
|
||||
values=decode_data(values);
|
||||
v1=fifo_read_event();
|
||||
if (v1)
|
||||
values=decode_data(v1);
|
||||
else {
|
||||
printf("no data found in fifos\n");
|
||||
return 1;
|
||||
@ -1953,9 +2009,9 @@ int testDataInOutMux(int imod, int ow, int num) {
|
||||
int ichan, ichip, result=0, ind;
|
||||
int vright,v;
|
||||
int nbit_mask=0xffffff;
|
||||
int *values;
|
||||
int *values, *v1;
|
||||
|
||||
printf("Testing data in-out\n");
|
||||
printf("Testing data inout for module %d, mux %d, pattern 0x%x\n", imod, ow, num);
|
||||
setExposureTime(0);
|
||||
setFrames(1);
|
||||
setTrains(1);
|
||||
@ -1988,9 +2044,9 @@ int testDataInOutMux(int imod, int ow, int num) {
|
||||
printf("mux %d\n",ow);
|
||||
startReadOut();
|
||||
usleep(100);
|
||||
values=fifo_read_event();
|
||||
if (values)
|
||||
values=decode_data(values);
|
||||
v1=fifo_read_event();
|
||||
if (v1)
|
||||
values=decode_data(v1);
|
||||
else {
|
||||
printf("no data found in fifos\n");
|
||||
return 1;
|
||||
@ -2021,7 +2077,7 @@ int testOutMux(int imod) {
|
||||
int ibit, i, val, v, j, dist, k;
|
||||
int result=OK;
|
||||
long pat=0xf0f0f0;
|
||||
printf("testing outmux\n");
|
||||
printf("testing outmux for module %d\n", imod);
|
||||
setCSregister(ALLMOD);
|
||||
// Clear outshift reg
|
||||
putout("0000010000000000",ALLMOD);
|
||||
@ -2211,6 +2267,7 @@ int testFpgaMux(int imod) {
|
||||
int ibit, i, val, v, j, dist,k;
|
||||
int result=OK;
|
||||
long pat=0xf0f0af;
|
||||
printf("testing fpga mux of module %d\n",imod);
|
||||
|
||||
// Clear outshift reg
|
||||
putout("0000010000000000",ALLMOD);
|
||||
|
@ -7,7 +7,9 @@
|
||||
#define CSP0 0x90000000 // Base Addresse CSP0
|
||||
#define CSP4 0xa0000000 // Base Addresse CSP4
|
||||
|
||||
#define MEM_SIZE 0xFFFFFF // map so much memory
|
||||
//#define MEM_SIZE 0xFFFFFF // map so much memory
|
||||
#define MEM_SIZE 0xFFFFFFF // map so much memory
|
||||
|
||||
|
||||
|
||||
/* registers defined in FPGA */
|
||||
|
@ -35,6 +35,7 @@ int main(int argc, char *argv[])
|
||||
printf("opening stop server on port %d\n",portno);
|
||||
}
|
||||
|
||||
system("bus -a 0xb0000000 -w 0xd0008");
|
||||
init_detector(b);
|
||||
|
||||
|
||||
|
@ -44,6 +44,7 @@ int init_detector( int b) {
|
||||
if (b) {
|
||||
initDetector();
|
||||
setSettings(GET_SETTINGS);
|
||||
testRAM();
|
||||
}
|
||||
#endif
|
||||
strcpy(mess,"dummy message");
|
||||
@ -130,7 +131,7 @@ int M_nofunc(int fnum){
|
||||
sprintf(mess,"Unrecognized Function %d\n",fnum);
|
||||
printf(mess);
|
||||
sendDataOnly(&retval,sizeof(retval));
|
||||
sendDataOnly(mess,sizeof(mess));
|
||||
sendDataOnly(mess,strlen(mess)+1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -140,7 +141,7 @@ int exit_server(int fnum) {
|
||||
sendDataOnly(&retval,sizeof(retval));
|
||||
printf("closing server.");
|
||||
sprintf(mess,"closing server");
|
||||
sendDataOnly(mess,sizeof(mess));
|
||||
sendDataOnly(mess,strlen(mess)+1);
|
||||
return GOODBYE;
|
||||
}
|
||||
|
||||
@ -213,7 +214,7 @@ int get_detector_type(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&ret,sizeof(ret));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
/*return ok/fail*/
|
||||
return retval;
|
||||
@ -269,7 +270,7 @@ int set_number_of_modules(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&ret,sizeof(ret));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
/*return ok/fail*/
|
||||
return retval;
|
||||
@ -321,7 +322,7 @@ int get_max_number_of_modules(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&ret,sizeof(ret));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
|
||||
@ -383,7 +384,7 @@ int set_external_signal_flag(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
|
||||
@ -444,7 +445,7 @@ enum externalCommunicationMode{
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&ret,sizeof(ret));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
/*return ok/fail*/
|
||||
@ -527,7 +528,7 @@ int get_id(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
/*return ok/fail*/
|
||||
@ -617,7 +618,7 @@ int digital_test(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
/*return ok/fail*/
|
||||
@ -669,7 +670,7 @@ int write_register(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
/*return ok/fail*/
|
||||
@ -720,7 +721,7 @@ int read_register(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
/*return ok/fail*/
|
||||
@ -814,7 +815,7 @@ int set_dac(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
/* Maybe this is done inside the initialization funcs */
|
||||
@ -900,7 +901,7 @@ int get_adc(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
/*return ok/fail*/
|
||||
@ -958,7 +959,7 @@ int set_channel(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
|
||||
@ -1029,7 +1030,7 @@ int get_channel(int fnum) {
|
||||
/* send return argument */
|
||||
ret=sendChannel(&retval);
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
|
||||
@ -1092,7 +1093,7 @@ int set_chip(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
|
||||
@ -1150,7 +1151,7 @@ int get_chip(int fnum) {
|
||||
/* send return argument */
|
||||
ret=sendChip(&retval);
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
|
||||
@ -1244,7 +1245,7 @@ int set_module(int fnum) {
|
||||
/* send return argument */
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
free(myChip);
|
||||
free(myChan);
|
||||
@ -1330,7 +1331,7 @@ int get_module(int fnum) {
|
||||
#endif
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Returning module %d\n", imod);
|
||||
printf("Returning module %d of register %x\n", imod, myModule.reg);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -1341,7 +1342,7 @@ int get_module(int fnum) {
|
||||
/* send return argument */
|
||||
ret=sendModule(&myModule);
|
||||
} else {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
|
||||
@ -1393,7 +1394,7 @@ int get_threshold_energy(int fnum) {
|
||||
/* send answer */
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
} else
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
|
||||
@ -1447,7 +1448,7 @@ int set_threshold_energy(int fnum) {
|
||||
/* send answer */
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
} else
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
|
||||
@ -1499,7 +1500,7 @@ int set_settings(int fnum) {
|
||||
/* send answer */
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
} else
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
|
||||
@ -1528,7 +1529,7 @@ int start_acquisition(int fnum) {
|
||||
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
return ret;
|
||||
|
||||
@ -1552,7 +1553,7 @@ int stop_acquisition(int fnum) {
|
||||
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
return ret;
|
||||
|
||||
@ -1577,7 +1578,7 @@ int start_readout(int fnum) {
|
||||
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
return ret;
|
||||
|
||||
@ -1606,7 +1607,7 @@ int get_run_status(int fnum) {
|
||||
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
} else {
|
||||
n += sendDataOnly(&retval,sizeof(retval));
|
||||
}
|
||||
@ -1630,23 +1631,30 @@ int read_frame(int fnum) {
|
||||
if (storeInRAM==0) {
|
||||
if ((dataretval=(char*)fifo_read_event())) {
|
||||
dataret=OK;
|
||||
#ifdef VERYVERBOSE
|
||||
printf("Sending ptr %x %d\n",dataretval, dataBytes);
|
||||
#endif
|
||||
sendDataOnly(&dataret,sizeof(dataret));
|
||||
sendDataOnly(dataretval,dataBytes);
|
||||
return OK;
|
||||
} else {
|
||||
dataret=FAIL;
|
||||
sendDataOnly(&dataret,sizeof(dataret));
|
||||
//might add delay????
|
||||
if(getFrames()>-2) {
|
||||
sprintf(mess,"no data and run stopped: %d frames left\n",getFrames()+2);
|
||||
} else {
|
||||
strcpy(mess,"acquisition successfully finished\n");
|
||||
}
|
||||
dataret=FAIL;
|
||||
sprintf(mess,"no data and run stopped: %d frames left\n",getFrames()+2);
|
||||
#ifdef VERBOSE
|
||||
printf(mess);
|
||||
printf("%s\n",mess);
|
||||
#endif
|
||||
sendDataOnly(mess,sizeof(mess));
|
||||
#ifdef VERBOSE
|
||||
} else {
|
||||
dataret=FINISHED;
|
||||
sprintf(mess,"acquisition successfully finished\n");
|
||||
}
|
||||
#ifdef VERYVERBOSE
|
||||
printf("%d %d %x %s\n",strlen(mess)+1,strlen(mess), mess,mess);
|
||||
#endif
|
||||
sendDataOnly(&dataret,sizeof(dataret));
|
||||
sendDataOnly(mess,strlen(mess)+1);//sizeof(mess));
|
||||
#ifdef VERYVERBOSE
|
||||
printf("message sent\n",mess);
|
||||
#endif
|
||||
return dataret;
|
||||
@ -1663,20 +1671,24 @@ int read_frame(int fnum) {
|
||||
#endif
|
||||
for (iframes=0; iframes<nframes; iframes++) {
|
||||
sendDataOnly(&dataret,sizeof(dataret));
|
||||
#ifdef VERYVERBOSE
|
||||
printf("sending pointer %x of size %d\n",dataretval,dataBytes);
|
||||
#endif
|
||||
sendDataOnly(dataretval,dataBytes);
|
||||
dataretval+=dataBytes;
|
||||
}
|
||||
if (getFrames()>-2)
|
||||
if (getFrames()>-2) {
|
||||
dataret=FAIL;
|
||||
sprintf(mess,"no data and run stopped: %d frames left\n",getFrames()+2);
|
||||
else
|
||||
} else {
|
||||
dataret=FINISHED;
|
||||
sprintf(mess,"acquisition successfully finished\n");
|
||||
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("Frames left %d\n",getFrames());
|
||||
#endif
|
||||
dataret=FAIL;
|
||||
sendDataOnly(&dataret,sizeof(dataret));
|
||||
sendDataOnly(mess,sizeof(mess));
|
||||
sendDataOnly(mess,strlen(mess)+1);
|
||||
return dataret;
|
||||
}
|
||||
|
||||
@ -1719,7 +1731,7 @@ int start_and_read_all(int fnum) {
|
||||
if (ret!=OK) {
|
||||
sprintf(mess,"could not start state machine\n");
|
||||
sendDataOnly(&ret,sizeof(ret));
|
||||
sendDataOnly(mess,sizeof(mess));
|
||||
sendDataOnly(mess,strlen(mess)+1);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("could not start state machine\n");
|
||||
@ -1747,7 +1759,6 @@ int set_timer(int fnum) {
|
||||
|
||||
sprintf(mess,"can't set timer\n");
|
||||
|
||||
|
||||
n = receiveDataOnly(&ind,sizeof(ind));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
@ -1760,6 +1771,9 @@ int set_timer(int fnum) {
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
if (ret!=OK) {
|
||||
printf(mess);
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("setting timer %d to %lld ns\n",ind,tns);
|
||||
@ -1792,15 +1806,18 @@ int set_timer(int fnum) {
|
||||
sprintf(mess,"timer index unknown %d\n",ind);
|
||||
}
|
||||
}
|
||||
|
||||
if (tns>=0 && retval!=tns && (retval+1)!=tns) {
|
||||
printf("wrote %lld, read %lld\n",tns,retval);
|
||||
ret=FAIL;
|
||||
}
|
||||
if (ret!=OK) {
|
||||
printf(mess);
|
||||
}
|
||||
//if (tns>=0 && retval!=tns && (retval+1)!=tns) {
|
||||
// printf("wrote %lld, read %lld\n",tns,retval);
|
||||
// ret=FAIL;
|
||||
// }
|
||||
if (ret!=OK) {
|
||||
printf(mess);
|
||||
printf("set timer failed\n");
|
||||
sprintf(mess, "set timer %d failed\n", ind);
|
||||
} else if (ind==FRAME_NUMBER){
|
||||
} else if (ind==FRAME_NUMBER) {
|
||||
ret=allocateRAM();
|
||||
if (ret!=OK)
|
||||
sprintf(mess, "could not allocate RAM for %lld frames\n", tns);
|
||||
@ -1812,7 +1829,7 @@ int set_timer(int fnum) {
|
||||
printf("returning error\n");
|
||||
#endif
|
||||
|
||||
n = sendDataOnly(mess,sizeof(mess));
|
||||
n = sendDataOnly(mess,strlen(mess)+1);
|
||||
} else {
|
||||
#ifdef VERBOSE
|
||||
printf("returning ok %d\n",sizeof(retval));
|
||||
@ -1888,7 +1905,7 @@ int get_time_left(int fnum) {
|
||||
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n += sendDataOnly(mess,sizeof(mess));
|
||||
n += sendDataOnly(mess,strlen(mess)+1);
|
||||
} else {
|
||||
n = sendDataOnly(&retval,sizeof(retval));
|
||||
}
|
||||
@ -1963,7 +1980,7 @@ int set_dynamic_range(int fnum) {
|
||||
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n = sendDataOnly(mess,sizeof(mess));
|
||||
n = sendDataOnly(mess,strlen(mess)+1);
|
||||
} else {
|
||||
n = sendDataOnly(&retval,sizeof(retval));
|
||||
}
|
||||
@ -2004,8 +2021,8 @@ int set_readout_flags(int fnum) {
|
||||
printf("setting readout flags to %d\n",arg);
|
||||
#endif
|
||||
|
||||
ret=setStoreInRAM(0);
|
||||
initChipWithProbes(0,0,0, ALLMOD);
|
||||
//ret=setStoreInRAM(0);
|
||||
// initChipWithProbes(0,0,0, ALLMOD);
|
||||
switch(arg) {
|
||||
case STORE_IN_RAM:
|
||||
ret=setStoreInRAM(1);
|
||||
@ -2013,10 +2030,9 @@ int set_readout_flags(int fnum) {
|
||||
case PUMP_PROBE_MODE:
|
||||
//set number of probes
|
||||
initChipWithProbes(0,0,2, ALLMOD);
|
||||
// setExtSignal(0,GATE_IN_ACTIVE_HIGH);
|
||||
// setExtSignal(0,TRIGGER_IN_RISING_EDGE);
|
||||
break;
|
||||
default:
|
||||
ret=setStoreInRAM(0);
|
||||
ret=OK;
|
||||
}
|
||||
if (storeInRAM)
|
||||
@ -2032,7 +2048,7 @@ int set_readout_flags(int fnum) {
|
||||
}
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n = sendDataOnly(mess,sizeof(mess));
|
||||
n = sendDataOnly(mess,strlen(mess)+1);
|
||||
} else {
|
||||
n = sendDataOnly(&retval,sizeof(retval));
|
||||
}
|
||||
@ -2115,7 +2131,7 @@ int execute_trimming(int fnum) {
|
||||
}
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=OK) {
|
||||
n = sendDataOnly(mess,sizeof(mess));
|
||||
n = sendDataOnly(mess,strlen(mess)+1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -164,7 +164,7 @@ int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) {
|
||||
int *trim;
|
||||
int ich, imod, ichan;
|
||||
int nvalid=0;
|
||||
int *scan;
|
||||
u_int32_t *scan;
|
||||
int ithr;
|
||||
|
||||
|
||||
@ -307,7 +307,8 @@ int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) {
|
||||
|
||||
int trim_with_level(int countlim, int im) {
|
||||
int ich, itrim, ichan, ichip, imod;
|
||||
int *scan, *inttrim;
|
||||
u_int32_t *scan;
|
||||
int *inttrim;
|
||||
int modma, modmi, nm;
|
||||
int retval=OK;
|
||||
|
||||
@ -349,12 +350,15 @@ int trim_with_level(int countlim, int im) {
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++) {
|
||||
ich=ichan+imod*nChans*nChips;
|
||||
if (scan[ich]>countlim){
|
||||
if (inttrim[ich]==-1) {
|
||||
if (inttrim[ich]==-1) {
|
||||
if (scan[ich]>countlim){
|
||||
inttrim[ich]=itrim;
|
||||
if (scan[ich]>2*countlim || itrim==0) {
|
||||
#ifdef VERBOSE
|
||||
printf("Channel %d trimbit %d counted %d countlim %d\n",ich,itrim,scan[ich],countlim);
|
||||
#endif
|
||||
inttrim[ich]=itrim-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
@ -375,10 +379,14 @@ int trim_with_level(int countlim, int im) {
|
||||
nextStrip(imod);
|
||||
ich=ichan+imod*nChans*nChips+ichip*nChans;
|
||||
if (*(inttrim+ich)==-1) {
|
||||
*(inttrim+ich)=itrim-1;
|
||||
*(inttrim+ich)=TRIM_DR;
|
||||
printf("could not trim channel %d chip %d module %d - set to %d\n", ichan, ichip, imod, *(inttrim+ich) );
|
||||
retval=FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
else
|
||||
printf("channel %d trimbit %d\n",ich,*(inttrim+ich) );
|
||||
#endif
|
||||
initChannel(inttrim[ich],0,0,1,0,0,imod);
|
||||
}
|
||||
nextChip(imod);
|
||||
@ -435,7 +443,8 @@ int choose_vthresh() {
|
||||
int retval=OK;
|
||||
#ifdef MCB_FUNCS
|
||||
int imod, ichan;
|
||||
int *scan, olddiff[nModX], direction[nModX];
|
||||
u_int32_t *scan;
|
||||
int olddiff[nModX], direction[nModX];
|
||||
int med[nModX], diff, media;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
@ -554,7 +563,8 @@ int trim_with_median(int stop, int im) {
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
int ichan, imod, ichip, ich;
|
||||
int *scan, *olddiff, *direction;
|
||||
u_int32_t *scan;
|
||||
int *olddiff, *direction;
|
||||
int med, diff;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
@ -576,7 +586,16 @@ int trim_with_median(int stop, int im) {
|
||||
|
||||
olddiff=malloc(4*nModX*nChips*nChans);
|
||||
direction=malloc(4*nModX*nChips*nChans);
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
direction[ichan]=0;
|
||||
olddiff[ichan]=0xffffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
/********
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
@ -595,7 +614,7 @@ int trim_with_median(int stop, int im) {
|
||||
med=median(me,nm);
|
||||
printf("median is %d\n",med);
|
||||
free(scan);
|
||||
|
||||
**************/
|
||||
while(change_flag && iteration<stop) {
|
||||
|
||||
fifoReset();
|
||||
@ -609,9 +628,19 @@ int trim_with_median(int stop, int im) {
|
||||
}
|
||||
usleep(500);
|
||||
scan=decode_data(fifo_read_event());
|
||||
|
||||
|
||||
|
||||
/********* calculates median every time ***********/
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
me[imod]=median(scan+imod*nChans*nChips,nChans*nChips);
|
||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
||||
}
|
||||
med=median(me,nm);
|
||||
printf("median is %d\n",med);
|
||||
|
||||
change_flag=0;
|
||||
printf("Trimbits iteration %3d 0f %3d\n",iteration, stop);
|
||||
printf("Trimbits iteration %d of %d\n",iteration, stop);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
selChip(ichip,imod);
|
||||
@ -621,15 +650,16 @@ int trim_with_median(int stop, int im) {
|
||||
nextStrip(imod);
|
||||
diff=scan[ichan]-med;
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0)
|
||||
if (diff>0) {
|
||||
direction[ichan]=1;
|
||||
else
|
||||
} else {
|
||||
direction[ichan]=-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( direction[ichan]!=-3) {
|
||||
if (abs(diff)>abs(olddiff[ichan])) {
|
||||
printf("%d old diff %d < new diff %d %d\n",ichan, olddiff[ichan], diff, direction[ichan]);
|
||||
trim=getTrimbit(imod,ichip,ich)+direction[ichan];
|
||||
printf("%d old diff %d < new diff %d %d - trimbit %d\n",ichan, olddiff[ichan], diff, direction[ichan], trim);
|
||||
direction[ichan]=-3;
|
||||
} else {
|
||||
trim=getTrimbit(imod,ichip,ich)-direction[ichan];
|
||||
@ -638,12 +668,12 @@ int trim_with_median(int stop, int im) {
|
||||
}
|
||||
if (trim>TRIM_DR) {
|
||||
trim=63;
|
||||
printf("can't trim channel %d chip %d module %d\n",ich, ichip, imod);
|
||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
||||
retval=FAIL;
|
||||
}
|
||||
if (trim<0) {
|
||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
||||
trim=0;
|
||||
printf("can't trim channel %d chip %d module %d\n",ich, ichip, imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
initChannel(trim,0,0,1,0,0,imod);
|
||||
|
Reference in New Issue
Block a user