diff --git a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h index 98aadc143..8adef92ca 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h @@ -109,8 +109,6 @@ void resetPeripheral(); int adcPhase(int st); int getPhase(); -u_int32_t putout(char *s, int modnum); -u_int32_t readin(int modnum); u_int32_t setClockDivider(int d); u_int32_t getClockDivider(); diff --git a/slsDetectorSoftware/jungfrauDetectorServer/mcb_funcs.c b/slsDetectorSoftware/jungfrauDetectorServer/mcb_funcs.c index c92222f2e..d72d332d0 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/mcb_funcs.c +++ b/slsDetectorSoftware/jungfrauDetectorServer/mcb_funcs.c @@ -73,34 +73,6 @@ int initDetector() { -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) { @@ -188,143 +160,6 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) { -/* Register commands */ - -int clearCSregister(int imod) { - - putout("0000000001000000",imod); - putout("0000100001000000",imod); - putout("0000100001000000",imod); - putout("0000000001000000",imod); - - /* - 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); - - 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); - - sChip++; - sMod=imod; - if (imod==ALLMOD) - sMod=allSelected; - return 0; -} - -int firstChip(int imod){ - - putout("0100000001000000",imod); - putout("0110000001000000",imod); - putout("0100000001000000",imod); - - 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); - - 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); - - 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); - - 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>(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(DYNAMIC_RANGE); - - 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*NCHAN*NCHIP+ichip*NCHAN+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*NCHAN*NCHIP+ichip*NCHAN+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=NCHAN; - } else if (sChan==noneSelected || sChan>NCHAN || 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=NCHIP; - } else if (sChip==noneSelected || sChip>NCHIP || 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*NCHIP]; - myChip->nchan=NCHAN; - myChip->chanregs=detectorChans+imod*NCHAN*NCHIP+ichip*NCHIP; - return OK; - } - } - return FAIL; - -} - - - -int initChip(int obe, int ow,int imod){ - int i; - int im, ichip; - int chipmi, chipma, modmi, modma; - - - putout("0000000000000000",imod); - - - /* 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); - } - } - - 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=NCHIP; - } else if (sChip==noneSelected || sChip>NCHIP || 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; imNCHIP || 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("\nInitializing Module\n"); @@ -1063,129 +296,12 @@ int getModulebyNumber(sls_detector_module* myMod) { -/* To chips */ -int clearCounter(int imod){ - int i; - - putout("0000000000000000",imod); - for (i=0; i<10; i++) - putout("0000000000010000",imod); - putout("0000000000000000",imod); - - return 0; -} - -int clearOutReg(int imod){ - int i; - - putout("0000010000000000",imod); - for (i=0; i<10; i++) - putout("0000110000000000",imod); - putout("0000010000000000",imod); - return 0; -} -int setOutReg(int imod){ - int i; - - 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; - - 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= NMODX) { - ret=FAIL; - sprintf(mess,"Module %d disabled\n",imod); - break; - } - if (testShiftIn(imod)) retval|=(1<<(ibit)); - ibit++; - if (testShiftOut(imod)) retval|=(1<<(ibit)); - ibit++; - if (testShiftStSel(imod)) retval|=(1<<(ibit)); - ibit++; - //if ( testDataInOut(0x123456, imod)) retval|=(1<<(ibit++)); - //if ( testExtPulse(imod)) retval|=(1<<(ibit++)); - // for (ow=0; ow<6; ow++) - // ow=1; - //#ifndef PICASSOD - for (ow=0; ow<5; ow++) { - //#endif - if (testDataInOutMux(imod, ow, 0x789abc)) retval|=(1< +#define GOODBYE (-200) + + int sockfd;