#ifdef MCB_FUNCS #include #include #include #include #include #include "registers_m.h" #ifndef PICASSOD #include "server_defs.h" #else #include "picasso_defs.h" #endif #include "firmware_funcs.h" #include "mcb_funcs.h" /* global variables */ #undef DEBUG #undef DEBUGOUT extern int nModX; //extern int dataBytes; extern int dynamicRange; enum detectorSettings thisSettings; int sChan, sChip, sMod, sDac, sAdc; const int allSelected=-2; const int noneSelected=-1; sls_detector_module *detectorModules=NULL; int *detectorChips=NULL; int *detectorChans=NULL; int *detectorDacs=NULL; int *detectorAdcs=NULL; //int numberOfProbes; ROI rois[MAX_ROIS]; int nROI=0; extern enum detectorType myDetectorType; /** for jungfrau reinitializing macro later in server_funcs.c in initDetector*/ extern int N_CHAN; extern int N_CHIP; extern int N_DAC; extern int N_ADC; extern int N_CHANS; extern int nChans; extern int nChips; int nDacs; int nAdcs; int initDetector() { int imod; // sls_detector_module *myModule; int n=getNModBoard(); nModX=n; #ifdef VERBOSE printf("Board is for %d modules\n",n); #endif // nChans=N_CHAN; // nChips=N_CHIP; nDacs=N_DAC; // nAdcs=N_ADC; detectorModules=malloc(n*sizeof(sls_detector_module)); detectorDacs=malloc(n*N_DAC*sizeof(int)); detectorAdcs=malloc(n*N_ADC*sizeof(int)); detectorChips=NULL; detectorChans=NULL; detectorAdcs=NULL; if(myDetectorType != JUNGFRAU){ detectorChips=malloc(n*N_CHIP*sizeof(int)); detectorChans=malloc(n*N_CHIP*N_CHAN*sizeof(int)); } #ifdef VERBOSE printf("modules from 0x%x to 0x%x\n",(unsigned int)(detectorModules), (unsigned int)(detectorModules+n)); printf("dacs from 0x%x to 0x%x\n",(unsigned int)(detectorDacs), (unsigned int)(detectorDacs+n*N_DAC)); printf("adcs from 0x%x to 0x%x\n",(unsigned int)(detectorAdcs), (unsigned int)(detectorAdcs+n*N_ADC)); if(myDetectorType != JUNGFRAU){ printf("chips from 0x%x to 0x%x\n",(unsigned int)(detectorChips), (unsigned int)(detectorChips+n*N_CHIP)); printf("chans from 0x%x to 0x%x\n",(unsigned int)(detectorChans), (unsigned int)(detectorChans+n*N_CHIP*N_CHAN)); } #endif for (imod=0; imoddacs=detectorDacs+imod*N_DAC; (detectorModules+imod)->adcs=detectorAdcs+imod*N_ADC; if(myDetectorType != JUNGFRAU){ (detectorModules+imod)->chipregs=detectorChips+imod*N_CHIP; (detectorModules+imod)->chanregs=detectorChans+imod*N_CHIP*N_CHAN; } (detectorModules+imod)->ndac=N_DAC; (detectorModules+imod)->nadc=N_ADC; (detectorModules+imod)->nchip=N_CHIP; (detectorModules+imod)->nchan=N_CHIP*N_CHAN; (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; sChan=noneSelected; sChip=noneSelected; sMod=noneSelected; sDac=noneSelected; sAdc=noneSelected; /* setCSregister(ALLMOD); //commented out by dhanya setSSregister(ALLMOD); counterClear(ALLMOD); clearSSregister(ALLMOD); putout("0000000000000000",ALLMOD); */ /* initialize dynamic range etc. */ /* dynamicRange=getDynamicRange(); //always 16 not required commented out nModX=setNMod(-1);*/ // dynamicRange=32; // initChip(0, 0,ALLMOD); //nModX=n; // allocateRAM(); return OK; } int copyChannel(sls_detector_channel *destChan, sls_detector_channel *srcChan) { destChan->chan=srcChan->chan; destChan->chip=srcChan->chip; destChan->module=srcChan->module; destChan->reg=srcChan->reg; return OK; } int copyChip(sls_detector_chip *destChip, sls_detector_chip *srcChip) { int ichan; int ret=OK; if ((srcChip->nchan)>(destChip->nchan)) { printf("Number of channels of source is larger than number of channels of destination\n"); return FAIL; } destChip->nchan=srcChip->nchan; destChip->reg=srcChip->reg; destChip->chip=srcChip->chip; destChip->module=srcChip->module; for (ichan=0; ichan<(srcChip->nchan); ichan++) { *((destChip->chanregs)+ichan)=*((srcChip->chanregs)+ichan); } return ret; } int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) { int ichip, idac, ichan, iadc; int ret=OK; #ifdef VERBOSE printf("Copying module %x to module %x\n",(unsigned int)(srcMod),(unsigned int)(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; } if ((srcMod->nchan)>(destMod->nchan)) { printf("Number of channels of source is larger than number of channels of destination\n"); return FAIL; } if ((srcMod->ndac)>(destMod->ndac)) { printf("Number of dacs of source is larger than number of dacs of destination\n"); return FAIL; } if ((srcMod->nadc)>(destMod->nadc)) { 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) destMod->offset=srcMod->offset; // printf("copying gain and offset %f %f to %f %f\n",srcMod->gain,srcMod->offset,destMod->gain,destMod->offset); if(myDetectorType != JUNGFRAU){ for (ichip=0; ichip<(srcMod->nchip); ichip++) { if (*((srcMod->chipregs)+ichip)>=0) *((destMod->chipregs)+ichip)=*((srcMod->chipregs)+ichip); } for (ichan=0; ichan<(srcMod->nchan); ichan++) { if (*((srcMod->chanregs)+ichan)>=0) *((destMod->chanregs)+ichan)=*((srcMod->chanregs)+ichan); } } for (idac=0; idac<(srcMod->ndac); idac++) { if (*((srcMod->dacs)+idac)>=0) *((destMod->dacs)+idac)=*((srcMod->dacs)+idac); } for (iadc=0; iadc<(srcMod->nadc); iadc++) { if (*((srcMod->adcs)+iadc)>=0) *((destMod->adcs)+iadc)=*((srcMod->adcs)+iadc); } return ret; } /* Register commands */ /* int clearDACSregister(int imod) { */ /* putout("1111111111111111",imod);//reset */ /* putout("1111111111111110",imod);//cs down */ /* /\* commented out by dhanya */ /* putout("0000000001000000",imod); */ /* putout("0000000101000000",imod); */ /* putout("0000000101000000",imod); */ /* putout("0000000001000000",imod); */ /* *\/ */ /* #ifdef DEBUG */ /* fprintf(stdout, "Clearing DAC shiftregister\n"); */ /* #endif */ /* // sDac=0; */ /* sMod=imod; */ /* if (imod==ALLMOD) */ /* sMod=allSelected; */ /* return OK; */ /* } */ /* int nextDAC(int imod) { */ /* putout("1111111111111011",imod);//cs up */ /* putout("1111111111111001",imod);//clk down */ /* putout("1111111111111111",imod);//reset */ /* /\*commented out by dhanya */ /* putout("0000000001000000",imod); */ /* putout("0000000001001000",imod); */ /* putout("0000000001000000",imod); */ /* *\/ */ /* #ifdef DEBUG */ /* fprintf(stdout, "Next DAC\n"); */ /* #endif */ /* // sDac++; */ /* sMod=imod; */ /* if (imod==ALLMOD) */ /* sMod=allSelected; */ /* return OK; */ /* } */ int clearCSregister(int imod) { putout("0000000001000000",imod); putout("0000100001000000",imod); putout("0000100001000000",imod); putout("0000000001000000",imod); #ifdef DEBUG fprintf(stdout, "Clearing CS shiftregister\n"); #endif /* sChan=noneSelected; sMod=noneSelected; sDac=noneSelected; sAdc=noneSelected; */ sChip=noneSelected; sMod=imod; if (imod==ALLMOD) sMod=allSelected; //putout("0000000000000000",imod); return 0; } int setCSregister(int imod){ putout("0000000001000000",imod); putout("0001000001000000",imod); putout("0001000001000000",imod); putout("0000000001000000",imod); #ifdef DEBUG fprintf(stdout, "Setting CS shiftregister\n"); #endif putout("0000000000000000",imod); sChip=allSelected; sMod=imod; if (imod==ALLMOD) sMod=allSelected; return 0; } int nextChip(int imod){ putout("0000000001000000",imod); putout("0010000001000000",imod); putout("0000000001000000",imod); #ifdef DEBUG fprintf(stdout, "Next Chip\n"); #endif sChip++; sMod=imod; if (imod==ALLMOD) sMod=allSelected; return 0; } int firstChip(int imod){ putout("0100000001000000",imod); putout("0110000001000000",imod); putout("0100000001000000",imod); #ifdef DEBUG fprintf(stdout, "First Chip\n"); #endif sChip=0; sMod=imod; if (imod==ALLMOD) sMod=allSelected; return 0; } int clearSSregister(int imod){ int i; putout("0000011000000000",imod); for (i=0; i<10; i++) putout("0000111000000000",imod); putout("0000011000000000",imod); #ifdef DEBUG fprintf(stdout,"Clearing SS shiftregister\n"); #endif putout("0000000000000000",imod); sChan=noneSelected; sMod=imod; if (imod==ALLMOD) sMod=allSelected; return 0; } int setSSregister(int imod){ int i; putout("0000011000000000",imod); for (i=0; i<10; i++) putout("0001011000000000",imod); putout("0000011000000000",imod); #ifdef DEBUG fprintf(stdout,"Setting SS shiftregister\n"); #endif putout("0000000000000000",imod); sChan=allSelected; sMod=imod; if (imod==ALLMOD) sMod=allSelected; return 0; } int nextStrip(int imod){ putout("0000011000000000",imod); putout("0010011000000000",imod); putout("0000011000000000",imod); #ifdef DEBUG fprintf(stdout,"|-"); #endif sChan++; sMod=imod; if (imod==ALLMOD) sMod=allSelected; return 0; } int selChannel(const int strip,int imod) { int istrip; clearSSregister(imod); nextStrip(imod); for (istrip=0; istrip=0 && imod=0) */ /* initDAC(ind,val, imod); */ /* if (imod>=0 && imodgain,(detectorModules+imod)->offset); */ /* #endif */ /* if ((detectorModules+imod)->gain>0) */ /* myg=(detectorModules+imod)->gain; */ /* else { */ /* if (thisSettings>=0 && thisSettings<3) */ /* myg=g[thisSettings]; */ /* // else */ /* //myg=-1; */ /* } */ /* if ((detectorModules+imod)->offset>0) */ /* myo=(detectorModules+imod)->offset; */ /* else { */ /* if (thisSettings>=0 && thisSettings<3) */ /* myo=o[thisSettings]; */ /* // else */ /* //myo=-1; */ /* } */ /* if (myg>0 && myo>0) { */ /* //ethr=(myo-detectorDacs[VTHRESH+imod*N_DAC])*1000/myg; */ /* ethr=(myo-setDACRegister(VDAC0,-1,imod))*1000/myg;//edited by dhanya */ /* // else */ /* // ethr=-1; */ /* } */ /* #ifdef VERBOSE */ /* //printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo, detectorDacs[VTHRESH+imod*N_DAC]); */ /* printf("module=%d gain=%f, offset=%f, dacu=%d\n",imod, myg, myo,(int)(setDACRegister(VDAC0,-1,imod)));//edited by dhanya */ /* printf("Threshold energy of module %d is %d eV\n", imod, ethr); */ /* #endif */ /* if (imod==0) */ /* ret=ethr; */ /* else { */ /* if (ethr>(ret+100) || ethr<(ret-100)) */ /* return FAIL; */ /* } */ /* } */ /* } */ /* return ret; */ /* } */ /* int setThresholdEnergy(int ethr) { */ /* double g[3]=DEFAULTGAIN; */ /* double o[3]=DEFAULTOFFSET; */ /* double myg=-1, myo=-1; */ /* int dacu; */ /* int imod; */ /* int ret=ethr; */ /* setSettings(GET_SETTINGS,-1);//-1 added by dhanya */ /* if (thisSettings>=0 || thisSettings<3){ */ /* myg=g[thisSettings]; */ /* myo=o[thisSettings]; */ /* } */ /* for (imod=0; imodgain>0) */ /* myg=(detectorModules+imod)->gain; */ /* else */ /* if (thisSettings>=0 && thisSettings<3) */ /* myg=g[thisSettings]; */ /* else */ /* myg=-1; */ /* if ((detectorModules+imod)->offset>0) */ /* myo=(detectorModules+imod)->offset; */ /* else */ /* if (thisSettings>=0 && thisSettings<3) */ /* myo=o[thisSettings]; */ /* else */ /* myo=-1; */ /* } else { */ /* if (thisSettings>=0 && thisSettings<3) */ /* myo=o[thisSettings]; */ /* else */ /* myo=-1; */ /* if (thisSettings>=0 && thisSettings<3) */ /* myg=g[thisSettings]; */ /* else */ /* myg=-1; */ /* } */ /* if (myg>0 && myo>0) { */ /* dacu=myo-myg*((double)ethr)/1000.; */ /* #ifdef VERBOSE */ /* printf("module %d (%x): gain %f, off %f, energy %d eV, dac %d\n",imod,(unsigned int)((detectorModules+imod)),(detectorModules+imod)->gain,(detectorModules+imod)->offset, ethr,dacu); */ /* #endif */ /* } else { */ /* dacu=ethr; */ /* #ifdef VERBOSE */ /* printf("could not set threshold energy for module %d, settings %d (offset is %f; gain is %f)\n",imod,thisSettings,myo,myg); */ /* #endif */ /* } */ /* initDACbyIndexDACU(VDAC0, dacu, imod); ///needs to be fixed dhanya */ /* } */ /* return ret; */ /* } */ /* int getDACbyIndexDACU(int ind, int imod) { */ /* /\* */ /* if (detectorDacs) { */ /* if (imodndac) */ /* return (detectorDacs[ind+imod*N_DAC]); */ /* } */ /* return FAIL; */ /* *\/ */ /* return setDACRegister(ind, -1, imod); */ /* } */ /* int initDAC(int dac_addr, int value, int imod) { */ /* // int i; */ /* #ifdef VERBOSE */ /* printf("Programming dac %d with value %d\n", dac_addr, value); */ /* #endif */ /* clearDACSregister(imod); */ /* program_one_dac(dac_addr,value,imod); */ /* nextDAC(imod); */ /* clearDACSregister(imod); */ /* return 0; */ /* } */ int getTemperatureByModule(int tempSensor, int imod) { int im; //for the particular module if (imod>=0 && imod=0 && imod=0 && imod=0) { */ /* #ifdef VERBOSE */ /* fprintf(stdout, "voltage %d\n", *(v+iaddr)); */ /* #endif */ /* program_one_dac(iaddr, *(v+iaddr),imod); */ /* } */ /* nextDAC(imod); */ /* } */ /* clearDACSregister(imod); */ /* return 0; */ /* } */ int setSettings(int i, int imod) { /* #ifdef VERBOSE */ /* if(i==-1) */ /* printf("\nReading settings of detector...\n"); */ /* else */ /* printf("\ninside set settings wit settings=%d...\n",i); */ /* #endif */ /* int isett=-1,val=-1,retval=-1; */ /* enum conf_gain { */ /* dynamic = 0x0f00, //dynamic */ /* dynamichighgain0 = 0x0f01, //dynamichighgain0 */ /* fixgain1 = 0x0f02, //fixgain1 */ /* fixgain2 = 0x0f06, //fixgain2 */ /* forceswitchgain1 = 0x1f00, //forceswitchgain1 */ /* forceswitchgain2 = 0x3f00 //forceswitchgain2 */ /* }; */ /* //determine conf value to write */ /* if(i!=GET_SETTINGS){ */ /* switch(i){ */ /* case DYNAMICGAIN: val = dynamic;break; */ /* case DYNAMICHG0: val = dynamichighgain0;break; */ /* case FIXGAIN1: val = fixgain1;break; */ /* case FIXGAIN2: val = fixgain2;break; */ /* case FORCESWITCHG1: val = forceswitchgain1;break; */ /* case FORCESWITCHG2: val = forceswitchgain2;break; */ /* default: */ /* printf("Error: This settings is not defined for this detector %d\n",i); */ /* return GET_SETTINGS; */ /* } */ /* } */ /* retval=initConfGainByModule(i,val,imod); */ /* switch(retval){ */ /* case dynamic: isett=DYNAMICGAIN; break; */ /* case dynamichighgain0: isett=DYNAMICHG0; break; */ /* case fixgain1: isett=FIXGAIN1; break; */ /* case fixgain2: isett=FIXGAIN2; break; */ /* case forceswitchgain1: isett=FORCESWITCHG1; break; */ /* case forceswitchgain2: isett=FORCESWITCHG2; break; */ /* default: */ /* isett=UNDEFINED; */ /* printf("Error:Wrong settings read out from Gain Reg 0x%x\n",retval); */ /* break; */ /* } */ /* thisSettings=isett; */ /* //#ifdef VERBOSE */ /* printf("detector settings are %d\n",thisSettings); */ /* //#endif */ return thisSettings; } /* Initialization*/ int initChannelbyNumber(sls_detector_channel myChan) {printf("in init channel by number\n"); /* int reg=myChan.reg; */ /* int ft=reg & TRIM_DR; */ /* int cae=(reg>>(NTRIMBITS))&1; */ /* int ae=(reg>>(NTRIMBITS+1))&1; */ /* int coe=(reg>>(NTRIMBITS+2))&1; */ /* int ocoe=(reg>>(NTRIMBITS+3))&1; */ /* int counts=(reg>>(NTRIMBITS+4)); */ /* #ifdef VERBOSE */ /* printf("Initializing channel %d chip %d module %d reg %x\n",myChan.chan,myChan.chip,myChan.module, reg); */ /* printf("trim %d, cae %d, ae %d, coe %d, ocoe %d, counts %d\n",ft, cae, ae, coe, ocoe, counts); */ /* #endif */ /* if (myChan.chip<0) */ /* setCSregister(myChan.module); */ /* else */ /* selChip(myChan.chip,myChan.module); */ /* if (myChan.chan<0) */ /* setSSregister(myChan.module); */ /* else */ /* selChannel(myChan.chan,myChan.module); */ /* initChannel(ft,cae,ae, coe, ocoe, counts,myChan.module); */ /* setDynamicRange(dynamicRange); */ /* setCSregister(ALLMOD); */ /* clearSSregister(ALLMOD); */ /* putout("0000000000000000",ALLMOD); */ return myChan.reg; } int getChannelbyNumber(sls_detector_channel* myChan) { /* int imod, ichip, ichan; */ /* imod=myChan->module; */ /* ichip=myChan->chip; */ /* ichan=myChan->chan; */ /* if (detectorChans) { */ /* if (imod=0) { */ /* if (ichip<(detectorModules+imod)->nchip && ichan<(detectorModules+imod)->nchan/(detectorModules+imod)->nchip) */ /* myChan->reg=detectorChans[imod*N_CHAN*N_CHIP+ichip*N_CHAN+ichan]; */ /* return OK; */ /* } */ /* } */ return FAIL; } int getTrimbit(int imod, int ichip, int ichan) { /* if (detectorChans) { */ /* if (imod=0) */ /* if (ichip<(detectorModules+imod)->nchip && ichan<(detectorModules+imod)->nchan/(detectorModules+imod)->nchip) */ /* return (detectorChans[imod*N_CHAN*N_CHIP+ichip*N_CHAN+ichan] & TRIM_DR); */ /* } */ return -1; } int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts, int imod){ /* int ibit, bit, i, im, ichip, ichan; */ /* int chanmi, chanma, chipmi, chipma, modmi, modma; */ /* sMod=imod; */ /* // printf("initializing module %d\n",sMod); */ /* if (imod==ALLMOD) { */ /* sMod=allSelected; */ /* // printf("initializing all modules\n"); */ /* } */ /* if (sChan==allSelected) { */ /* // printf("initializing all channels ft=%d coe=%d\n",ft,coe); */ /* chanmi=0; */ /* chanma=N_CHAN; */ /* } else if (sChan==noneSelected || sChan>N_CHAN || sChan<0) { */ /* // printf("initializing no channels ft=%d coe=%d\n",ft,coe); */ /* chanmi=0; */ /* chanma=-1; */ /* } else { */ /* // printf("initializing channel %d ft=%d coe=%d\n",sChan, ft,coe); */ /* chanmi=sChan; */ /* chanma=sChan+1; */ /* } */ /* if (sChip==allSelected) { */ /* // printf("initializing all chips\n"); */ /* chipmi=0; */ /* chipma=N_CHIP; */ /* } else if (sChip==noneSelected || sChip>N_CHIP || sChip<0) { */ /* // printf("initializing no chips\n"); */ /* chipmi=0; */ /* chipma=-1; */ /* } else { */ /* // printf("initializing chip %d\n",sChip); */ /* chipmi=sChip; */ /* chipma=sChip+1; */ /* } */ /* if (sMod==allSelected) { */ /* modmi=0; */ /* modma=nModX;//getNModBoard(); */ /* } else if (sMod==noneSelected || sMod>nModX || sMod<0) {//(sMod==noneSelected || sMod>getNModBoard() || sMod<0) { */ /* modmi=0; */ /* modma=-1; */ /* return 1; */ /* } else { */ /* modmi=sMod; */ /* modma=sMod+1; */ /* } */ /* if (detectorChans) { */ /* for (im=modmi; im63 || ft<0) { */ /* fprintf(stdout,"Fine Threshold is %d while should be between 0 and 63!",ft); */ /* return 1; */ /* } */ /* /\*cal_enable*\/ */ /* if (cae) { */ /* putout("0100000000000000",imod); */ /* putout("0110000000000000",imod); */ /* } else { */ /* putout("0000000000000000",imod); */ /* putout("0010000000000000",imod); */ /* } */ /* /\*n_an_enable*\/ */ /* if (ae) { */ /* putout("0000000000000000",imod); */ /* putout("0010000000000000",imod); */ /* putout("0000000000000000",imod); */ /* } else { */ /* putout("0100000000000000",imod); */ /* putout("0110000000000000",imod); */ /* putout("0100000000000000",imod); */ /* } */ /* /\*trb5*\/ */ /* ibit=5; */ /* bit=ft & (1<>1; */ /* int nchan, ichan; */ /* int ft, cae, ae, coe, ocoe, counts, chanreg; */ /* nchan=myChip.nchan; */ /* if (ichip<0) */ /* setCSregister(imod); */ /* else */ /* selChip(ichip,imod); */ /* clearSSregister(imod); */ /* for (ichan=0; ichan>(NTRIMBITS+1))&1; */ /* ae=(chanreg>>(NTRIMBITS+2))&1; */ /* coe=((chanreg)>>(NTRIMBITS+3))&1; */ /* ocoe=((chanreg)>>(NTRIMBITS+4))&1; */ /* counts=((chanreg)>>(NTRIMBITS+5)); */ /* nextStrip(imod); */ /* initChannel(ft,cae,ae, coe, ocoe, counts,imod); */ /* } */ /* initChip(obe,ow,imod); */ return myChip.reg; } int getChipbyNumber(sls_detector_chip* myChip){ /* int imod, ichip; */ /* imod=myChip->module; */ /* ichip=myChip->chip; */ /* if (detectorChips) { */ /* if (imodnchip) { */ /* myChip->reg=detectorChips[ichip+imod*N_CHIP]; */ /* myChip->nchan=N_CHAN; */ /* myChip->chanregs=detectorChans+imod*N_CHAN*N_CHIP+ichip*N_CHIP; */ /* return OK; */ /* } */ /* } */ return FAIL; } int initChip(int obe, int ow,int imod){ /* int i; */ /* int im, ichip; */ /* int chipmi, chipma, modmi, modma; */ /* switch (ow) { case 0:; case 1: setDynamicRange(32); break; case 2: setDynamicRange(16); break; case 3: setDynamicRange(8); break; case 4: setDynamicRange(4); break; case 5: setDynamicRange(1); break; default: setDynamicRange(32); break; } */ /* #ifdef DEBUGOUT */ /* printf("Initializing chip\n"); */ /* #endif */ /* putout("0000000000000000",imod); */ /* #ifdef DEBUGOUT */ /* printf("Output mode= %d\n", ow); */ /* #endif */ /* /\* clearing shift in register *\/ */ /* for (i=0; i<10; i++) */ /* putout("0000100000000000",imod); */ /* putout("0000000000000000",imod); */ /* if (ow>0) { */ /* putout("0100000000000000",imod); */ /* putout("0110000000000000",imod); */ /* putout("0100000000000000",imod); */ /* for (i=0; i<(OUTMUX_OFFSET-1); i++) { */ /* putout("0000000000000000",imod); */ /* putout("0010000000000000",imod); */ /* putout("0000000000000000",imod); */ /* } */ /* if (ow>1) { */ /* putout("0000000000000000",imod); */ /* putout("0010000000000000",imod); */ /* putout("0000000000000000",imod); */ /* } */ /* if (ow>2) { */ /* putout("0000000000000000",imod); */ /* putout("0010000000000000",imod); */ /* putout("0000000000000000",imod); */ /* } */ /* if (ow>3) { */ /* putout("0000000000000000",imod); */ /* putout("0010000000000000",imod); */ /* putout("0000000000000000",imod); */ /* } */ /* if (ow>4) { */ /* putout("0000000000000000",imod); */ /* putout("0010000000000000",imod); */ /* putout("0000000000000000",imod); */ /* } */ /* } */ /* #ifdef DEBUGOUT */ /* printf("Output buffer enable= %d\n", obe); */ /* #endif */ /* if (obe) { */ /* putout("0100000000000000",imod); */ /* putout("0110000000000000",imod); */ /* putout("0100000000000000",imod); */ /* } else { */ /* putout("0000000000000000",imod); */ /* putout("0010000000000000",imod); */ /* putout("0000000000000000",imod); */ /* } */ /* /\*}*\/ */ /* putout("0000000000000000",imod); */ /* sMod=imod; */ /* if (imod==ALLMOD) */ /* sMod=allSelected; */ /* if (sChip==allSelected) { */ /* chipmi=0; */ /* chipma=N_CHIP; */ /* } else if (sChip==noneSelected || sChip>N_CHIP || sChip<0) { */ /* chipmi=0; */ /* chipma=-1; */ /* } else { */ /* chipmi=sChip; */ /* chipma=sChip+1; */ /* } */ /* if (sMod==allSelected) { */ /* modmi=0; */ /* modma=nModX;//getNModBoard(); */ /* } else if (sMod==noneSelected || sMod>nModX || sMod<0) {//(sMod==noneSelected || sMod>getNModBoard() || sMod<0) { */ /* modmi=0; */ /* modma=-1; */ /* } else { */ /* modmi=sMod; */ /* modma=sMod+1; */ /* } */ /* if (detectorChips) { */ /* for (im=modmi; imN_CHIP || sChip<0) { */ /* chipmi=0; */ /* chipma=-1; */ /* } else { */ /* chipmi=sChip; */ /* chipma=sChip+1; */ /* } */ /* if (sMod==allSelected) { */ /* modmi=0; */ /* modma=nModX;//getNModBoard(); */ /* } else if (sMod==noneSelected || sMod>nModX || sMod<0) {//(sMod==noneSelected || sMod>getNModBoard() || sMod<0) { */ /* modmi=0; */ /* modma=-1; */ /* } else { */ /* modmi=sMod; */ /* modma=sMod+1; */ /* } */ /* if (detectorChips) { */ /* for (im=modmi; imnModX || sMod<0) {//(sMod==noneSelected || sMod>getNModBoard() || sMod<0) { modmi=0; modma=-1; } else { modmi=sMod; modma=sMod+1; } if (detectorModules) { for (im=modmi; imreg)=cm; #ifdef VERBOSE printf("imod=%d reg=%d (%x)\n",im,(detectorModules+im)->reg,(unsigned int)((detectorModules+im))); #endif } } return 0; } int initModulebyNumber(sls_detector_module myMod) { printf("\ninside initmoduleynumberrrr..\n"); printf("000\n"); int nchip,nchan;//int ichip, nchip, ichan, nchan; int im, modmi,modma; // int ft, cae, ae, coe, ocoe, counts, chanreg; int imod; // int obe; // int ow; /* int v[N_DAC];*/ int retval =-1, idac; nchip=myMod.nchip; nchan=(myMod.nchan)/nchip; imod=myMod.module; sMod=imod; if (sMod==ALLMOD) sMod=allSelected; if (sMod==allSelected) { modmi=0; modma=nModX;//getNModBoard(); } else if (sMod==noneSelected || sMod>nModX || sMod<0) {// (sMod==noneSelected || sMod>getNModBoard() || sMod<0) { modmi=0; modma=-1; } else { modmi=sMod; modma=sMod+1; } printf("222\n"); /* for (idac=0; idacmodule; #ifdef VERBOSE printf("Getting module %d\n",imod); #endif if (detectorModules) { copyModule(myMod,detectorModules+imod); ; } else return FAIL; return OK; } /* To chips */ int clearCounter(int imod){ int i; #ifdef DEBUG printf("Clearing counter with contclear\n"); #endif putout("0000000000000000",imod); for (i=0; i<10; i++) putout("0000000000010000",imod); putout("0000000000000000",imod); return 0; } int clearOutReg(int imod){ int i; #ifdef DEBUG printf("Clearing output register\n"); #endif putout("0000010000000000",imod); for (i=0; i<10; i++) putout("0000110000000000",imod); putout("0000010000000000",imod); return 0; } int setOutReg(int imod){ int i; #ifdef DEBUG printf("Setting output register\n"); #endif putout("0000010000000000",imod); for (i=0; i<10; i++) putout("0001010000000000",imod); putout("0000010000000000",imod); return 0; } int extPulse(int ncal, int imod) { int ical; #ifdef DEBUG printf("Giving a clock pulse to the counter\n"); #endif for (ical=0; ical0 && i%2==0) { printf("Shift in: module %d chip %i bit %d read %d instead of %d \n",k,j,i,val & 1<< j, i%2); result++; } if (i%2>0 && (val & 1<0 && (dum & (1<0) { printf("Shift out: module %d chip %i bit %d read %d instead of %d \n",k,j,i,val & 1<< j, (dum &1<0 && i%2==0) { printf("Shift stsel: module %d chip %i bit %d read %d instead of %d \n",k,j,i,val & 1<< j, i%2); result++; } if (i%2>0 && (val & 1<> 1; putout("0000000000000000",ALLMOD); putout("0010000000000000",ALLMOD); //change mux setting putout("0000000000000000",ALLMOD); } printf("Test FpgaMux module %d : %d errors\n", imod,result); if (result) return 1; else return 0; } int calibration_sensor(int num, int *v, int *dacs) { int ich, ichip, imod; int val[10]; printf("calibrating sensor..."); for (imod=0; imod=0){ */ /* //clear rois */ /* for(i=0;i=0) && (adc<=4)); */ /* else { */ /* printf("warning:adc value greater than 5. deleting roi\n"); */ /* adc=-1; */ /* } */ /* } */ /* } */ /* //set rois for just 1 adc - take only 1st roi */ /* if(adc!=-1){ */ /* rois[0].xmin=adc*(GOTTHARDNCHAN*NCHIPS_PER_ADC); */ /* rois[0].xmax=(adc+1)*(GOTTHARDNCHAN*NCHIPS_PER_ADC)-1; */ /* rois[0].ymin=-1; */ /* rois[0].ymax=-1; */ /* nROI = 1; */ /* }else */ /* nROI = 0; */ /* if((arg[0].xmin!=rois[0].xmin)||(arg[0].xmax!=rois[0].xmax)||(arg[0].ymin!=rois[0].ymin)||(arg[0].ymax!=rois[0].ymax)) */ /* *ret=FAIL; */ /* if(n!=nROI) */ /* *ret=FAIL; */ /* //set adc of interest */ /* setADC(adc); */ /* } */ /* //#ifdef VERBOSE */ /* printf("Rois:\n"); */ /* for( i=0;i