diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 5f6ba08bd..c60dce35b 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -117,7 +117,7 @@ enum detectorType { PILATUS, /**< pilatus */ EIGER, /**< eiger */ GOTTHARD, /**< gotthard */ - PICASSO, /**< mythen */ + PICASSO, /**< picasso */ AGIPD /**< agipd */ }; @@ -267,7 +267,7 @@ enum detectorSettings{ \see ::sls_detector_channel */ enum channelRegisterBit { - TRIMBIT_OFF, /**< offset of trimbit value in the channel register */ + TRIMBIT_OFF=0, /**< offset of trimbit value in the channel register */ COMPARATOR_ENABLE=0x100, /**< mask of the comparator enable bit */ ANALOG_SIGNAL_ENABLE=0x200, /**< mask of the analogue output enable bit */ CALIBRATION_ENABLE=0x300, /**< mask of the calibration input enable bit */ @@ -307,6 +307,8 @@ enum timerIndex { enum speedVariable { CLOCK_DIVIDER, /**< readout clock divider */ WAIT_STATES, /**< wait states for bus read */ + TOT_CLOCK_DIVIDER, /**< wait states for bus read */ + TOT_DUTY_CYCLE, /**< wait states for bus read */ SET_SIGNAL_LENGTH /**< set/clear signal length */ }; @@ -332,7 +334,9 @@ enum readOutFlags { READ_HITS=0x2, /**< return only the number of the channel which counted ate least one */ ZERO_COMPRESSION=0x4,/**< returned data are 0-compressed */ PUMP_PROBE_MODE=0x8,/**> ival; - externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG; + externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG, ret; if (action==PUT_ACTION) { - sval=string(args[1]); + sval=string(args[1]); #ifdef VERBOSE std::cout<< "sig " << ival << " flag " << sval; #endif @@ -389,10 +390,11 @@ string mythenDetector::executeLine(int narg, char *args[], int action) { else if (sval=="trigger_out_falling_edge") flag=TRIGGER_OUT_FALLING_EDGE; else if (sval=="ro_trigger_out_rising_edge") flag=RO_TRIGGER_OUT_RISING_EDGE; else if (sval=="ro_trigger_out_falling_edge") flag=RO_TRIGGER_OUT_FALLING_EDGE; - setExternalSignalFlags(flag,ival); + - } - switch (setExternalSignalFlags( GET_EXTERNAL_SIGNAL_FLAG,ival)) { + } + ret= setExternalSignalFlags(flag,ival); + switch (ret) { case SIGNAL_OFF: return string( "off"); case GATE_IN_ACTIVE_HIGH: @@ -473,18 +475,19 @@ string mythenDetector::executeLine(int narg, char *args[], int action) { sprintf(answer,"%x",digitalTest(DETECTOR_BUS_TEST)); return string(answer); } else if (var=="settings") { + detectorSettings sett=GET_SETTINGS; if (action==PUT_ACTION) { sval=string(args[1]); - detectorSettings sett=GET_SETTINGS; if (sval=="standard") sett=STANDARD; else if (sval=="fast") sett=FAST; else if (sval=="highgain") sett=HIGHGAIN; - setSettings(sett); + //setSettings(sett); } - switch (setSettings( GET_SETTINGS)) { + //switch (setSettings( GET_SETTINGS)) { + switch (setSettings(sett)) { case STANDARD: return string("standard"); case FAST: @@ -516,7 +519,6 @@ string mythenDetector::executeLine(int narg, char *args[], int action) { sscanf(args[1],"%f",&fval);// in seconds! setTimer(ACQUISITION_TIME,fval*1E+9); } - sprintf(answer,"%f",(float)setTimer(ACQUISITION_TIME)*1E-9); return string(answer); } else if (var=="period") { @@ -578,10 +580,14 @@ string mythenDetector::executeLine(int narg, char *args[], int action) { readOutFlags flag=GET_READOUT_FLAGS; if (sval=="none") flag=NORMAL_READOUT; - else if (sval=="pumpprobe") - flag=PUMP_PROBE_MODE; + //else if (sval=="pumpprobe") + // flag=PUMP_PROBE_MODE; else if (sval=="storeinram") flag=STORE_IN_RAM; + else if (sval=="tot") + flag=TOT_MODE; + else if (sval=="continous") + flag=CONTINOUS_RO; setReadOutFlags(flag); } @@ -591,6 +597,10 @@ string mythenDetector::executeLine(int narg, char *args[], int action) { return string("none"); case STORE_IN_RAM: return string("storeinram"); + case TOT_MODE: + return string("tot"); + case CONTINOUS_RO: + return string("continous"); default: return string("unknown"); } @@ -694,7 +704,21 @@ string mythenDetector::executeLine(int narg, char *args[], int action) { sprintf(answer,"%d", setSpeed(WAIT_STATES)); return string(answer); - } + } else if (var=="totdivider") { + if (action==PUT_ACTION) { + sscanf(args[1],"%d",&ival); + setSpeed(TOT_CLOCK_DIVIDER,ival); + } + sprintf(answer,"%d", setSpeed(TOT_CLOCK_DIVIDER)); + return string(answer); + } else if (var=="totdutycycle") { + if (action==PUT_ACTION) { + sscanf(args[1],"%d",&ival); + setSpeed(TOT_DUTY_CYCLE,ival); + } + sprintf(answer,"%d", setSpeed(TOT_DUTY_CYCLE)); + return string(answer); + } return ("Unknown command"); } @@ -973,8 +997,8 @@ int mythenDetector::readConfigurationFile(string const fname){ string::size_type pos; int iargval; int interrupt=0; - char *args[2]; - for (int ia=0; ia<2; ia++) { + char *args[100]; + for (int ia=0; ia<100; ia++) { args[ia]=new char[1000]; } @@ -1055,8 +1079,8 @@ int mythenDetector::writeConfigurationFile(string const fname){ int nvar=14; ofstream outfile; int iv=0; - char *args[2]; - for (int ia=0; ia<2; ia++) { + char *args[100]; + for (int ia=0; ia<100; ia++) { args[ia]=new char[1000]; } @@ -1218,8 +1242,9 @@ int mythenDetector::retrieveDetectorSetup(string fname1, int level){ if (level==2) { fname=fname1+string(".config"); readConfigurationFile(fname); - fname=fname+string(".det"); - } + fname=fname1+string(".det"); + } else + fname=fname1; infile.open(fname.c_str(), ios_base::in); if (infile.is_open()) { while (infile.good() and interrupt==0) { @@ -1241,10 +1266,13 @@ int mythenDetector::retrieveDetectorSetup(string fname1, int level){ iargval=0; while (ssstr.good()) { ssstr >> sargname; - if (ssstr.good()) { + // if (ssstr.good()) { strcpy(args[iargval],sargname.c_str()); +#ifdef VERBOSE + std::cout<< args[iargval] << std::endl; +#endif iargval++; - } + // } } if (level==2) { executeLine(iargval,args,PUT_ACTION); @@ -1467,7 +1495,7 @@ int mythenDetector::writeTrimFile(string fname, sls_detector_module mod){ outfile.close(); return OK; } else { - std::cout<< "could not open file " << fname << std::endl; + std::cout<< "could not open trim file " << fname << std::endl; return FAIL; } @@ -1492,16 +1520,14 @@ int mythenDetector::writeDataFile(string fname, float *data, float *err, float * int idata; if (data==NULL) return FAIL; -#ifdef VERBOSE - std::cout<< "writing data to file " << fname << std::endl; -#endif + // args|=0x10; // one line per channel! outfile.open (fname.c_str(),ios_base::out); if (outfile.is_open()) { #ifdef VERBOSE - std::cout<< "Writing to file " << fname << std::endl; + std::cout<< "writeDataFile Writing to file " << fname << std::endl; #endif for (int ichan=0; ichanprogressIndex=0; + resetFinalDataQueue(); + resetDataQueue(); + + jointhread=0; queuesize=0; if (thisDetector->threadedProcessing) { @@ -2037,7 +2067,7 @@ void mythenDetector::acquire(int delflag){ } else if (ip<(np-1)) thisDetector->fileIndex=thisDetector->fileIndex-thisDetector->timerValue[FRAME_NUMBER]; #ifdef VERBOSE - cout << "Setting file index to " << thisDetector->fileIndex << endl; + cout << "------------------------------------------------------Setting file index to " << thisDetector->fileIndex << endl; #endif } @@ -2108,10 +2138,20 @@ void* mythenDetector::processData(int delflag) { //delete [] myData; // myData=NULL; /** write raw data file */ - - if (thisDetector->correctionMask!=0 || delflag==0) { + if (thisDetector->correctionMask==0 && delflag==1) { +#ifdef ACQVERBOSE + std::cout<< "------------------------------------no processing "<< delflag <correctionMask!=0 || delflag==0) { writing raw data file " << createFileName() <<" " << thisDetector->correctionMask<< " " << delflag << endl; +#endif /** rate correction */ if (thisDetector->correctionMask&(1<nChans*thisDetector->nChips*thisDetector->nMods]; @@ -2172,13 +2212,16 @@ void* mythenDetector::processData(int delflag) { } if (thisDetector->correctionMask!=0) - writeDataFile (createFileName().append(".dat"), ffcdata, ffcerr,ang); +#ifdef VERBOSE + std::cout << "********************** writing dat data file if (thisDetector->correctionMask!=0) { " << createFileName() <<" " << thisDetector->correctionMask << endl; +#endif + writeDataFile (createFileName().append(".dat"), ffcdata, ffcerr,ang); addToMerging(ang, ffcdata, ffcerr, mergingBins, mergingCounts,mergingErrors, mergingMultiplicity); - + if ((currentPositionIndex==thisDetector->numberOfPositions) || (currentPositionIndex==0)) { @@ -2187,6 +2230,9 @@ void* mythenDetector::processData(int delflag) { /** file writing */ currentPositionIndex++; if (thisDetector->correctionMask!=0) +#ifdef VERBOSE + std::cout << "********************** writing dat data file if ((currentPositionIndex==thisDetector->numberOfPositions) || (currentPositionIndex==0))" << createFileName() << endl; +#endif writeDataFile (createFileName().append(".dat"),mergingCounts, mergingErrors, mergingBins,'f',np); if (delflag) { delete [] mergingBins; @@ -2198,10 +2244,10 @@ void* mythenDetector::processData(int delflag) { thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(createFileName().append(".dat")).c_str(),np); else thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(createFileName().append(".raw")).c_str(),np); - + finalDataQueue.push(thisData); #ifdef ACQVERBOSE - std::cout<< "------------------------------------pushing final data queue " << finalDataQueue.size() << std::endl; + std::cout<< "------------------------------------pushing final data queue " << finalDataQueue.size() << " " << createFileName() << std::endl; #endif } } @@ -2214,8 +2260,12 @@ void* mythenDetector::processData(int delflag) { delete [] ang; //} } else { - if (thisDetector->correctionMask!=0) + if (thisDetector->correctionMask!=0) { writeDataFile (createFileName().append(".dat"), ffcdata, ffcerr); +#ifdef VERBOSE + std::cout << "********************** if (thisDetector->correctionMask!=0) writing dat data file " << createFileName() << endl; +#endif + } if (delflag) { if (ffcdata) delete [] ffcdata; @@ -2224,25 +2274,17 @@ void* mythenDetector::processData(int delflag) { if (ang) delete [] ang; } else { - if (thisDetector->correctionMask!=0) + if (thisDetector->correctionMask!=0) { thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(createFileName().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); - else + } else { thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(createFileName().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); + } finalDataQueue.push(thisData); -#ifdef ACQVERBOSE - std::cout<< "------------------------------------pushing final data queue " << finalDataQueue.size() << std::endl; +#ifdef VERBOSE + std::cout<< "------------------------------------pushing final data queue with " << createFileName() << " " <fileIndex++; #ifdef VERBOSE @@ -2279,11 +2321,11 @@ void* mythenDetector::processData(int delflag) { if (jointhread) { -#ifdef ACQVERBOSE - std::cout<< "acquisition finished " << dataQueue.size() << " empty " << !dataQueue.empty() << std::endl; +#ifdef VERBOSE + std::cout<< "acquisition finished " << dataQueue.size() << " empty " << !dataQueue.empty() << "final data queue size: " << finalDataQueue.size() </dev/null diff --git a/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.c b/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.c index c2183db05..c820ffbe2 100755 --- a/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.c @@ -1,5 +1,9 @@ - +#ifndef PICASSOD #include "server_defs.h" +#else +#include "picasso_defs.h" +#endif + #include "firmware_funcs.h" #include "mcb_funcs.h" #include "registers.h" @@ -207,14 +211,28 @@ u_int32_t getTotClockDivider() { } +u_int32_t setTotDutyCycle(int d) { + u_int32_t c; + c=bus_r(SPEED_REG); + bus_w(SPEED_REG,(d<>TOTCLK_DUTYCYCLE_OFFSET); +} + +u_int32_t getTotDutyCycle() { + u_int32_t clk_div; + clk_div=((bus_r(SPEED_REG)&TOTCLK_DUTYCYCLE_MASK)>>TOTCLK_DUTYCYCLE_OFFSET); + return clk_div; +} + + u_int32_t setExtSignal(int d, enum externalSignalFlag mode) { - int modes[]={-1,EXT_SIG_OFF, EXT_GATE_IN_ACTIVEHIGH, EXT_GATE_IN_ACTIVELOW,EXT_TRIG_IN_RISING,EXT_TRIG_IN_FALLING,EXT_RO_TRIG_IN_RISING, EXT_RO_TRIG_IN_FALLING,EXT_GATE_OUT_ACTIVEHIGH, EXT_GATE_OUT_ACTIVELOW, EXT_TRIG_OUT_RISING, EXT_TRIG_OUT_FALLING, EXT_RO_TRIG_OUT_RISING, EXT_RO_TRIG_OUT_FALLING}; + int modes[]={EXT_SIG_OFF, EXT_GATE_IN_ACTIVEHIGH, EXT_GATE_IN_ACTIVELOW,EXT_TRIG_IN_RISING,EXT_TRIG_IN_FALLING,EXT_RO_TRIG_IN_RISING, EXT_RO_TRIG_IN_FALLING,EXT_GATE_OUT_ACTIVEHIGH, EXT_GATE_OUT_ACTIVELOW, EXT_TRIG_OUT_RISING, EXT_TRIG_OUT_FALLING, EXT_RO_TRIG_OUT_RISING, EXT_RO_TRIG_OUT_FALLING}; u_int32_t c; int off=d*SIGNAL_OFFSET; c=bus_r(EXT_SIGNAL_REG); - if (mode<=RO_TRIGGER_OUT_FALLING_EDGE) + if (mode<=RO_TRIGGER_OUT_FALLING_EDGE && mode>=0) bus_w(EXT_SIGNAL_REG,((modes[mode])<=0) { + bus_w(CONFIG_REG,d); + } +#ifdef VERBOSE + printf("configuration register is %x", bus_r(CONFIG_REG)); +#endif + return bus_r(CONFIG_REG); +} + +int setToT(int d) { + int ret=0; + int reg; +#ifdef VERBOSE + printf("Setting ToT to %d\n",d); +#endif + reg=bus_r(CONFIG_REG); +#ifdef VERBOSE + printf("Before: ToT is %x\n", reg); +#endif + if (d>0) { + bus_w(CONFIG_REG,reg|TOT_ENABLE_BIT); + } else if (d==0) { + bus_w(CONFIG_REG,reg&(~TOT_ENABLE_BIT)); + } + reg=bus_r(CONFIG_REG); +#ifdef VERBOSE + printf("ToT is %x\n", reg); +#endif + if (reg&TOT_ENABLE_BIT) + return 1; + else + return 0; +} + +int setContinousReadOut(int d) { + int ret=0; + int reg; +#ifdef VERBOSE + printf("Setting Continous readout to %d\n",d); +#endif + reg=bus_r(CONFIG_REG); +#ifdef VERBOSE + printf("Before: Continous readout is %x\n", reg); +#endif + if (d>0) { + bus_w(CONFIG_REG,reg|CONT_RO_ENABLE_BIT); + } else if (d==0) { + bus_w(CONFIG_REG,reg&(~CONT_RO_ENABLE_BIT)); + } + reg=bus_r(CONFIG_REG); +#ifdef VERBOSE + printf("Continous readout is %x\n", reg); +#endif + if (reg&CONT_RO_ENABLE_BIT) + return 1; + else + return 0; +} + + u_int64_t getMcsNumber() { FILE *fp=NULL; @@ -353,29 +435,112 @@ int getNModBoard() { int setNMod(int n) { int fifo; - int ifsta, ifsto, ifste; - if (n>0 && n<=getNModBoard()) { - nModX=n; - dataBytes=nModX*nModY*NCHIP*NCHAN*dynamicRange/8; - allocateRAM(); + // int ifsta, ifsto, ifste; + int imod; + int rval; + int reg; + + int shiftfifo=SHIFTFIFO; + int ntot=getNModBoard(); + + switch (dynamicRange) { + case 16: + shiftfifo=SHIFTFIFO-1; + break; + case 8: + shiftfifo=SHIFTFIFO-2; + break; + case 4: + shiftfifo=SHIFTFIFO-3; + break; + case 1: + shiftfifo=SHIFTFIFO-5; + break; + default: + shiftfifo=SHIFTFIFO; } - /* should enable all fifos*/ - bus_w(FIFO_CNTRL_REG_OFF+(ALLFIFO<0 && n<=ntot) { + nModX=n; + // dataBytes=nModX*nModY*NCHIP*NCHAN*dynamicRange/8; + //allocateRAM(); + + /* should enable all fifos*/ + /* // bus_w(FIFO_CNTRL_REG_OFF+(ALLFIFO<=0 && val>off)&0x3ff; +#ifdef VERBOSE + printf("Dac %d module %d register is %d\n",idac,imod,val); +#endif + return val; +} @@ -624,10 +815,28 @@ u_int32_t getNBits() u_int32_t fifoReadCounter(int fifonum) { - int rval=0; - rval=bus_r(FIFO_COUNTR_REG_OFF+(fifonum<0) { - if (dr<=1) { + nm=setNMod(-1); + if (dr==1) { dynamicRange=1; ow=5; - } else if (dr<=4) { + } else if (dr<=4) { dynamicRange=4; ow=4; } else if (dr<=8) { @@ -785,7 +1007,7 @@ int setDynamicRange(int dr) { setCSregister(ALLMOD); initChipWithProbes(0, ow,np, ALLMOD); putout("0000000000000000",ALLMOD); - + setNMod(nm); } diff --git a/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.h b/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.h index 89365558e..9523f5206 100755 --- a/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.h +++ b/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.h @@ -33,11 +33,16 @@ u_int32_t setWaitStates(int d); u_int32_t getWaitStates(); u_int32_t setTotClockDivider(int d); u_int32_t getTotClockDivider(); +u_int32_t setTotClockDutyCycle(int d); +u_int32_t getTotClockDutyCycle(); u_int32_t setExtSignal(int d, enum externalSignalFlag mode); int getExtSignal(int d); +int setConfigurationRegister(int d); +int setToT(int d); +int setContinousReadOut(int d); - +int setDACRegister(int idac, int val, int imod); u_int64_t getMcsNumber(); diff --git a/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c b/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c index d85629619..665a96584 100755 --- a/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c +++ b/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c @@ -5,9 +5,13 @@ #include #include #include +#include "registers.h" - +#ifndef PICASSOD #include "server_defs.h" +#else +#include "picasso_defs.h" +#endif #include "firmware_funcs.h" #include "mcb_funcs.h" @@ -48,7 +52,9 @@ int initDetector() { int imod; // sls_detector_module *myModule; int n=getNModBoard(); - +#ifdef VERBOSE + printf("Board is for %d modules\n",n); +#endif detectorModules=malloc(n*sizeof(sls_detector_module)); detectorChips=malloc(n*NCHIP*sizeof(int)); @@ -92,10 +98,14 @@ int initDetector() { putout("0000000000000000",ALLMOD); /* initialize dynamic range etc. */ - nModX=n; - dataBytes=nModX*NCHIP*NCHAN*4; - dynamicRange=32; - initChip(0, 1,ALLMOD); + dynamicRange=getDynamicRange(); + nModX=setNMod(-1); + + //dataBytes=nModX*NCHIP*NCHAN*4; + // dynamicRange=32; + // initChip(0, 0,ALLMOD); + //nModX=n; + // // allocateRAM(); @@ -419,6 +429,8 @@ int program_one_dac(int addr, int value, int imod) { int im; int idac; int v=value; + int reg, mask; + // sls_detector_module *myMod; control=9+addr; @@ -472,15 +484,109 @@ int program_one_dac(int addr, int value, int imod) { //(detectorModules+imod)->dacs[idac]=v; detectorDacs[idac+NDAC*imod]=v; //#ifdef VERBOSE +#ifdef VERBOSE printf("module=%d index=%d, val=%d addr=%x\n",imod, idac, v, detectorDacs+idac+NDAC*imod); +#endif + + setDACRegister(idac,v,imod); + + /* + + reg=bus_r(MOD_DACS1_REG+(imod<dacs[idac]=v; + + + + reg=bus_r(MOD_DACS1_REG+(imod<=0 && imod=0 && imod0 && myo>0) - ethr=(myo-detectorDacs[VTHRESH+imod*NDAC])*1000/myg; - // else + if (myg>0 && myo>0) { + //ethr=(myo-detectorDacs[VTHRESH+imod*NDAC])*1000/myg; + + ethr=(myo-setDACRegister(VTHRESH,-1,imod))*1000/myg; + // else // ethr=-1; + } #ifdef VERBOSE - printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo, detectorDacs[VTHRESH+imod*NDAC]); + //printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo, detectorDacs[VTHRESH+imod*NDAC]); + printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo,setDACRegister(VTHRESH,-1,imod)); printf("Threshold energy of module %d is %d eV\n", imod, ethr); #endif @@ -688,13 +815,15 @@ int setThresholdEnergy(int ethr) { float getDACbyIndexDACU(int ind, int imod) { - + /* if (detectorDacs) { if (imodndac) return (detectorDacs[ind+imod*NDAC]); } return FAIL; + */ + return setDACRegister(ind, -1, imod); } @@ -782,10 +911,15 @@ int setSettings(int i) { } //else { imod=0; /* check settings for module 0 */ - isett=UNDEFINED; + isett=UNDEFINED;/* irgpr=detectorDacs[4+imod*NDAC]; irgsh1=detectorDacs[imod*NDAC+RGSH1]; irgsh2=detectorDacs[imod*NDAC+RGSH2]; + */ + + irgpr=setDACRegister(4,-1,imod); + irgsh1=setDACRegister(RGSH1,-1,imod); + irgsh2=setDACRegister(RGSH2,-1,imod); for (is=STANDARD; is>(NTRIMBITS+1))&1; - int ae=(reg>>(NTRIMBITS+2))&1; - int coe=(reg>>(NTRIMBITS+3))&1; - int ocoe=(reg>>(NTRIMBITS+4))&1; - int counts=(reg>>(NTRIMBITS+5)); - + 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); @@ -845,6 +993,13 @@ int initChannelbyNumber(sls_detector_channel myChan) { 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; } @@ -938,9 +1093,10 @@ int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts, int imod) #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)); + 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 addr=%x reg=%x\n",im,ichip,ichan,detectorChans+im*NCHAN*NCHIP+ichip*NCHAN+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]); + // 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 } } @@ -1307,13 +1463,13 @@ int initChipWithProbes(int obe, int ow,int nprobes, int imod){ omask=16; break; default: - omask=1; + omask=0;//1; break; } regval=(omask<-2) { dataret=FAIL; sprintf(mess,"no data and run stopped: %d frames left\n",getFrames()+2); - printf("%s\n",mess); + printf("%s\n",mess); } else { dataret=FINISHED; sprintf(mess,"acquisition successfully finished\n"); printf("%s\n",mess); } #ifdef VERYVERBOSE - printf("%d %d %x %s\n",strlen(mess)+1,strlen(mess), mess,mess); + printf("%d %d %x %s\n",sizeof(mess),strlen(mess), mess,mess); #endif sendDataOnly(&dataret,sizeof(dataret)); - sendDataOnly(mess,strlen(mess)+1);//sizeof(mess)); + sendDataOnly(mess,sizeof(mess));//sizeof(mess));//sizeof(mess)); #ifdef VERYVERBOSE printf("message sent\n",mess); #endif @@ -1707,7 +1724,7 @@ int read_frame(int fnum) { printf("Frames left %d\n",getFrames()); #endif sendDataOnly(&dataret,sizeof(dataret)); - sendDataOnly(mess,strlen(mess)+1); + sendDataOnly(mess,sizeof(mess)); return dataret; } @@ -1750,7 +1767,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,strlen(mess)+1); + sendDataOnly(mess,sizeof(mess)); #ifdef VERBOSE printf("could not start state machine\n"); @@ -1848,7 +1865,7 @@ int set_timer(int fnum) { printf("returning error\n"); #endif - n = sendDataOnly(mess,strlen(mess)+1); + n = sendDataOnly(mess,sizeof(mess)); } else { #ifdef VERBOSE printf("returning ok %d\n",sizeof(retval)); @@ -1924,7 +1941,7 @@ int get_time_left(int fnum) { n = sendDataOnly(&ret,sizeof(ret)); if (ret!=OK) { - n += sendDataOnly(mess,strlen(mess)+1); + n += sendDataOnly(mess,sizeof(mess)); } else { n = sendDataOnly(&retval,sizeof(retval)); } @@ -1999,7 +2016,7 @@ int set_dynamic_range(int fnum) { n = sendDataOnly(&ret,sizeof(ret)); if (ret!=OK) { - n = sendDataOnly(mess,strlen(mess)+1); + n = sendDataOnly(mess,sizeof(mess)); } else { n = sendDataOnly(&retval,sizeof(retval)); } @@ -2045,30 +2062,42 @@ int set_speed(int fnum) { if (ret==OK) { switch (arg) { case CLOCK_DIVIDER: - if (val>0) + if (val>=0) retval=setClockDivider(val); else retval=getClockDivider(); break; case WAIT_STATES: - if (val>0) + if (val>=0) retval=setWaitStates(val); else retval=getWaitStates(); break; case SET_SIGNAL_LENGTH: - if (val>0) + if (val>=0) retval=setSetLength(val); else retval=getSetLength(); break; + case TOT_CLOCK_DIVIDER: + if (val>=0) + retval=setTotClockDivider(val); + else + retval=getTotClockDivider(); + break; + case TOT_DUTY_CYCLE: + if (val>=0) + retval=setTotDutyCycle(val); + else + retval=getTotDutyCycle(); + break; default: ret=FAIL; } } n = sendDataOnly(&ret,sizeof(ret)); if (ret!=OK) { - n = sendDataOnly(mess,strlen(mess)+1); + n = sendDataOnly(mess,sizeof(mess)); } else { n = sendDataOnly(&retval,sizeof(retval)); } @@ -2083,6 +2112,7 @@ int set_readout_flags(int fnum) { enum readOutFlags arg; int n; int ret=OK; + int regret=OK; sprintf(mess,"can't set readout flags\n"); @@ -2105,30 +2135,50 @@ int set_readout_flags(int fnum) { case GET_READOUT_FLAGS: break; case STORE_IN_RAM: - ret=setStoreInRAM(1); + if (setStoreInRAM(1)==OK) + ret=OK; + else + ret=FAIL; break; - case PUMP_PROBE_MODE: + case TOT_MODE: + if(setToT(1)) + ret=OK; + else + ret=FAIL; + break; + case CONTINOUS_RO: + if (setContinousReadOut(1)) + ret=OK; + else + ret=FAIL; + break; + // case PUMP_PROBE_MODE: //set number of probes - initChipWithProbes(0,0,2, ALLMOD); - break; + //initChipWithProbes(0,0,2, ALLMOD); + //break; default: ret=setStoreInRAM(0); + regret=setConfigurationRegister(0); ret=OK; - } + } + retval=NORMAL_READOUT; + if (storeInRAM) retval=STORE_IN_RAM; - else if (getProbes()) - retval=PUMP_PROBE_MODE; - else - retval=NORMAL_READOUT; - + //else if (getProbes()) + // retval=PUMP_PROBE_MODE; + //else + if (setToT(-1)) + retval|=TOT_MODE; + if (setContinousReadOut(-1)) + retval|=CONTINOUS_RO; if (ret!=OK) { printf("set readout flags failed\n"); sprintf(mess,"Could not allocate RAM\n"); } n = sendDataOnly(&ret,sizeof(ret)); if (ret!=OK) { - n = sendDataOnly(mess,strlen(mess)+1); + n = sendDataOnly(mess,sizeof(mess)); } else { n = sendDataOnly(&retval,sizeof(retval)); } @@ -2211,7 +2261,7 @@ int execute_trimming(int fnum) { } n = sendDataOnly(&ret,sizeof(ret)); if (ret!=OK) { - n = sendDataOnly(mess,strlen(mess)+1); + n = sendDataOnly(mess,sizeof(mess)); } return ret; diff --git a/slsDetectorSoftware/mythenDetectorServer/trimming_funcs.c b/slsDetectorSoftware/mythenDetectorServer/trimming_funcs.c index e9d6f31e2..1495deb70 100755 --- a/slsDetectorSoftware/mythenDetectorServer/trimming_funcs.c +++ b/slsDetectorSoftware/mythenDetectorServer/trimming_funcs.c @@ -1,5 +1,8 @@ - +#ifndef PICASSOD #include "server_defs.h" +#else +#include "picasso_defs.h" +#endif #include "trimming_funcs.h" #include "mcb_funcs.h" #include "firmware_funcs.h" @@ -155,7 +158,9 @@ int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) { #ifdef MCB_FUNCS int modma, modmi, nm; int thr, thrstep=5, nthr=31; - + + int *fifodata; + float vthreshmean, vthreshSTDev; int *thrmi, *thrma; float c; @@ -166,6 +171,8 @@ int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) { int nvalid=0; u_int32_t *scan; int ithr; + sls_detector_channel myChan; + setFrames(1); @@ -195,7 +202,11 @@ int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) { clearSSregister(im); usleep(500); */ - + myChan.chan=-1; + myChan.chip=-1; + myChan.module=ALLMOD; + myChan.reg=COMPARATOR_ENABLE; + initChannelbyNumber(myChan); for (ithr=0; ithrcountlim){ 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; + if (scan[ich]>2*countlim && itrim>0) { + //if (scan[ich]>2*countlim || itrim==0) { + inttrim[ich]=itrim-1; } +#ifdef VERBOSE + printf("Channel %d trimbit %d counted %d (%08x) countlim %d\n",ich,itrim,scan[ich],fifodata[ich],countlim); +#endif } } #ifdef VERBOSE @@ -380,12 +413,12 @@ int trim_with_level(int countlim, int im) { ich=ichan+imod*nChans*nChips+ichip*nChans; if (*(inttrim+ich)==-1) { *(inttrim+ich)=TRIM_DR; - printf("could not trim channel %d chip %d module %d - set to %d\n", ichan, ichip, imod, *(inttrim+ich) ); + // 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) ); + // else + // printf("channel %d trimbit %d\n",ich,*(inttrim+ich) ); #endif initChannel(inttrim[ich],0,0,1,0,0,imod); } @@ -453,7 +486,7 @@ int choose_vthresh() { int vthresh; int im=ALLMOD; int modma, modmi, nm; - + int *fifodata; setFrames(1); // setNMod(getNModBoard()); @@ -469,6 +502,8 @@ int choose_vthresh() { + setDynamicRange(32); + setCSregister(ALLMOD); setSSregister(ALLMOD); counterClear(ALLMOD); @@ -480,7 +515,8 @@ int choose_vthresh() { } usleep(500); - scan=decode_data(fifo_read_event()); + fifodata=fifo_read_event(); + scan=decode_data(fifodata); for (imod=modmi; imodnModsMax; } @@ -1426,19 +1426,19 @@ int slsDetector::setChannel(int64_t reg, int ichan, int ichip, int imod){ if (ichan==-1) { chamin=0; chamax=thisDetector->nChans; - } + }*/ - for (int im=mmin; imonlineFlag==ONLINE_FLAG) { if (controlSocket) { @@ -1475,7 +1475,39 @@ int slsDetector::setChannel(sls_detector_channel chan){ if (ret==OK) { if (chanregs) { - *(chanregs+im*thisDetector->nChans*thisDetector->nChips+ichi*thisDetector->nChips+icha)=retval; + +int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1, chamin=ichan, chamax=ichan+1; + + if (imod==-1) { + mmin=0; + mmax=thisDetector->nModsMax; + } + + if (ichip==-1) { + chimin=0; + chimax=thisDetector->nChips; + } + + if (ichan==-1) { + chamin=0; + chamax=thisDetector->nChans; + } + + + + + + + for (int im=mmin; imnChans*thisDetector->nChips+ichi*thisDetector->nChips+icha)=retval; + + } + } +} + } } #ifdef VERBOSE @@ -2122,15 +2154,26 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti oscfn << thisDetector->calDir << ssettings << "/calibration.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10); // trimfname=ostfn.str(); +#ifdef VERBOSE + cout << trimfname << endl; +#endif if (readTrimFile(trimfname,myMod)) { calfname=oscfn.str(); +#ifdef VERBOSE + cout << calfname << endl; +#endif readCalibrationFile(calfname,myMod->gain, myMod->offset); setModule(*myMod); } else { ostringstream ostfn,oscfn; ostfn << thisDetector->trimDir << ssettings << ssettings << ".trim"; oscfn << thisDetector->calDir << ssettings << ssettings << ".cal"; + calfname=oscfn.str(); trimfname=ostfn.str(); +#ifdef VERBOSE + cout << trimfname << endl; + cout << calfname << endl; +#endif if (readTrimFile(trimfname,myMod)) { calfname=oscfn.str(); readCalibrationFile(calfname,myMod->gain, myMod->offset); @@ -2468,6 +2511,26 @@ detectorData* slsDetector::popFinalDataQueue() { return retval; } +void slsDetector::resetDataQueue() { + int *retval=NULL; + while( !dataQueue.empty() ) { + retval=dataQueue.front(); + dataQueue.pop(); + delete [] retval; + } + +} + +void slsDetector::resetFinalDataQueue() { + detectorData *retval=NULL; + while( !finalDataQueue.empty() ) { + retval=finalDataQueue.front(); + finalDataQueue.pop(); + delete retval; + } + +} + /* set or read the acquisition timers enum timerIndex { @@ -2707,19 +2770,19 @@ int slsDetector::setReadOutFlags(readOutFlags flag){ if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { - if (controlSocket->Connect()>=0) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&flag,sizeof(flag)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=OK) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - thisDetector->roFlags=retval; - } - controlSocket->Disconnect(); - } + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&flag,sizeof(flag)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=OK) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->roFlags=retval; + } + controlSocket->Disconnect(); + } } } else { if (flag!=GET_READOUT_FLAGS) diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 36bdc2d7a..142c88ead 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -946,6 +946,30 @@ typedef struct sharedSlsDetector { \sa finalDataQueue */ detectorData* popFinalDataQueue(); + + + + + /** + resets the raw data queue + \sa dataQueue + */ + void resetDataQueue(); + + /** + resets the postprocessed data queue + \sa finalDataQueue + */ + void resetFinalDataQueue(); + + + + + + + + + /** set/get timer value \param index timer index