diff --git a/slsDetectorSoftware/commonFiles/communication_funcs.c b/slsDetectorSoftware/commonFiles/communication_funcs.c index 54ee6bb14..48aae9d30 100755 --- a/slsDetectorSoftware/commonFiles/communication_funcs.c +++ b/slsDetectorSoftware/commonFiles/communication_funcs.c @@ -328,20 +328,20 @@ int receiveData(int file_des, void* buf,int length, intType itype){ int nreceiving; int nreceived; if (file_des<0) return -1; -#ifdef VERY_VERBOSE + //#ifdef VERY_VERBOSE printf("want to receive %d Bytes\n", length); -#endif + //#endif while(length>0){ nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length; -#ifdef VERY_VERBOSE - printf("want to receive %d Bytes\n", nreceiving); -#endif + //#ifdef VERY_VERBOSE + // printf("want to receive %d Bytes\n", nreceiving); + //#endif nreceived = read(file_des,(char*)buf+total_received,nreceiving); -#ifdef VERY_VERBOSE - printf("read %d \n", nreceived); -#endif + //#ifdef VERY_VERBOSE + // printf("read %d \n", nreceived); + //#endif if(!nreceived) break; // if(nreceived<0) break; length-=nreceived; @@ -349,9 +349,9 @@ int receiveData(int file_des, void* buf,int length, intType itype){ // cout<<"nrec: "<0) strcpy(thisClientIP,dummyClientIP); diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index df7e34c53..ae9ed32a4 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -372,7 +372,8 @@ enum dacIndex { V_POWER_C = 102, /**new chiptest board */ V_POWER_D = 103, /**new chiptest board */ V_POWER_IO =104, /**new chiptest board */ - V_POWER_CHIP=105 /**new chiptest board */ + V_POWER_CHIP=105 ,/**new chiptest board */ + V_LIMIT=106 /**new chiptest board */ }; /** @@ -439,7 +440,10 @@ enum speedVariable { OVERSAMPLING, /**< oversampling for analog detectors */ ADC_CLOCK, /**< adc clock divider */ ADC_PHASE, /**< adc clock phase */ - ADC_PIPELINE /**< adc pipeline */ + ADC_PIPELINE, /**< adc pipeline */ + DBIT_CLOCK, /**< adc clock divider */ + DBIT_PHASE, /**< adc clock phase */ + DBIT_PIPELINE /**< adc pipeline */ }; @@ -454,11 +458,14 @@ enum readOutFlags { ZERO_COMPRESSION=0x4,/**< returned data are 0-compressed */ PUMP_PROBE_MODE=0x8,/**>16)>0){ - //bus_w(addr,0x0); //clear the reg - - if(reg==0){ - printf("\nImplementing phase shift of %d\n",phase_shift); - for (i=1;i3) + return -1; + + if (val>65535 || val<-65535) + return clkPhase[i]; + + // printf("PLL reconfig reset\N"); bus_w(PLL_CNTRL_REG,(1<0) { + inv=0; + phase=val&0xffff; + } else { + inv=0; + val=-1*val; + phase=(~val)&0xffff; + } + + + vv=phase | (i<<16);// | (inv<<21); + + setPllReconfigReg(PLL_PHASE_SHIFT_REG,vv,0); + + clkPhase[i]=val; + return clkPhase[i]; +} + + +int configureFrequency(int val, int i) { + + + u_int32_t l=0x0c; + u_int32_t h=0x0d; + u_int32_t vv; int32_t phase=0, inv=0; u_int32_t tot; u_int32_t odd=1;//0; // printf("PLL reconfig reset\N"); bus_w(PLL_CNTRL_REG,(1<2*l) { - h=l+1; - odd=1; - } - printf("Counter %d: Low is %d, High is %d\n",i, l,h); - - - val= (i<<18)| (odd<<17) | l | (h<<8); - - printf("Counter %d, val: %08x\n", i, val); - setPllReconfigReg(PLL_C_COUNTER_REG, val,0); - // usleep(20); - //change sync at the same time as - if (i>0) { - val= (2<<18)| (odd<<17) | l | (h<<8); - - printf("Counter %d, val: %08x\n", i, val); - setPllReconfigReg(PLL_C_COUNTER_REG, val,0); - - } - - } else { - // if (mode==1) { - // } else { - printf("phase in %d\n",clkPhase[1]); - - if (clkPhase[1]>0) { - inv=0; - phase=clkPhase[1]; - } else { - inv=1; - phase=-1*clkPhase[1]; - } - - printf("phase out %d %08x\n",phase,phase); - if (inv) { - val=phase | (1<<16);// | (inv<<21); - printf("**************** phase word %08x\n",val); - - // printf("Phase, val: %08x\n", val); - setPllReconfigReg(PLL_PHASE_SHIFT_REG,val,0); //shifts counter 0 - } else { - - - val=phase ;// | (inv<<21); - printf("**************** phase word %08x\n",val); - - // printf("Phase, val: %08x\n", val); - setPllReconfigReg(PLL_PHASE_SHIFT_REG,val,0); //shifts counter 0 -#ifndef NEW_PLL_RECONFIG - printf("Start reconfig\n"); setPllReconfigReg(PLL_START_REG, 1,0); - - // bus_w(PLL_CNTRL_REG, 0); - printf("Status register\n"); getPllReconfigReg(PLL_STATUS_REG,0); - // sleep(1); + if (i<0 || i>3) + return -1; - printf("PLL mode\n"); setPllReconfigReg(PLL_MODE_REG,1,0); - // usleep(10000); + if (val<=0) + return clkDivider[i]; -#endif - printf("**************** phase word %08x\n",val); - - val=phase | (2<<16);// | (inv<<21); - // printf("Phase, val: %08x\n", val); - setPllReconfigReg(PLL_PHASE_SHIFT_REG,val,0); //shifts counter 0 + if (i==1 || i==2){ + if (val>40) printf("Too high frequency %d MHz for these ADCs!\n", val); } - - - } - -#ifndef NEW_PLL_RECONFIG - printf("Start reconfig\n"); setPllReconfigReg(PLL_START_REG, 1,0); - - // bus_w(PLL_CNTRL_REG, 0); - printf("Status register\n"); getPllReconfigReg(PLL_STATUS_REG,0); - // sleep(1); -#endif - // printf("PLL mode\n"); setPllReconfigReg(PLL_MODE_REG,0,0); - usleep(10000); - if (i<2) { - printf("reset pll\n"); - bus_w(PLL_CNTRL_REG,((1<2*l) { + h=l+1; + odd=1; } -} - - - - - - - - - -u_int32_t setClockDivider(int d, int ic) { - - - //u_int32_t l=0x0c; - //u_int32_t h=0x0d; - - u_int32_t tot= PLL_VCO_FREQ_MHZ/d; - - // int ic=0 is run clk; ic=1 is adc clk - printf("set clk divider %d to %d\n", ic, d); - if (ic>1) - return -1; - - if (ic==1 && d>40) - return -1; - - if (d>160) - return -1; - - if (tot>510) - return -1; - - if (tot<1) - return -1; - - - - clkDivider[ic]=d; - configurePll(ic); - + else + { + odd=0; + } + + printf("Counter %d: Low is %d, High is %d\n",i, l,h); - return clkDivider[ic]; -} - - -int phaseStep(int st){ + vv= (i<<18)| (odd<<17) | l | (h<<8); - if (st>65535 || st<-65535) - return clkPhase[0]; -#ifdef NEW_PLL_RECONFIG - printf("reset pll\n"); - bus_w(PLL_CNTRL_REG,((1<0) { */ + /* val= (2<<18)| (odd<<17) | l | (h<<8); */ + + /* printf("Counter %d, val: %08x\n", i, val); */ + /* setPllReconfigReg(PLL_C_COUNTER_REG, val,0); */ - clkPhase[1]=st; -#else - clkPhase[1]=st-clkPhase[0]; -#endif - - printf("phase %d\n", clkPhase[1] ); + /* } */ - configurePll(2); - - clkPhase[0]=st; - return clkPhase[0]; + usleep(10000); + + printf("reset pll\n"); + bus_w(PLL_CNTRL_REG,((1<2) */ +/* return -1; */ + +/* if (ic==2) { */ +/* printf("dbit clock is the same as adc clk\n"); */ +/* ic=1; */ + +/* } */ + +/* if (ic==1 && d>40) */ +/* return -1; */ + +/* if (d>160) */ +/* return -1; */ + +/* if (tot>510) */ +/* return -1; */ + +/* if (tot<1) */ +/* return -1; */ + + + +/* clkDivider[ic]=d; */ +/* configurePll(ic); */ + + + +/* return clkDivider[ic]; */ +/* } */ + + +/* int phaseStep(int st){ */ + +/* if (st>65535 || st<-65535) */ +/* return clkPhase[0]; */ +/* #ifdef NEW_PLL_RECONFIG */ +/* printf("reset pll\n"); */ +/* bus_w(PLL_CNTRL_REG,((1<=0 && i<4) + return clkPhase[i]; + else + return -1; }; -u_int32_t getClockDivider(int ic) { - if (ic>1) - return -1; - return clkDivider[ic]; +/* int getDbitPhase() { */ + +/* printf("dbit clock is the same as adc clk\n"); */ +/* return getPhase(); */ + +/* }; */ + + +/* u_int32_t getClockDivider(int ic) { */ + +/* if (ic>2) */ +/* return -1; */ + +/* if (ic==2) { */ +/* printf("dbit clock is the same as adc clk\n"); */ +/* ic=1; */ + +/* } */ +/* return clkDivider[ic]; */ -/* int ic=0; */ -/* u_int32_t val; */ -/* u_int32_t l,h; */ +/* /\* int ic=0; *\/ */ +/* /\* u_int32_t val; *\/ */ +/* /\* u_int32_t l,h; *\/ */ -/* printf("get clk divider\n"); */ +/* /\* printf("get clk divider\n"); *\/ */ -/* setPllReconfigReg(PLL_MODE_REG,1,0); */ -/* getPllReconfigReg(PLL_MODE_REG,0); */ +/* /\* setPllReconfigReg(PLL_MODE_REG,1,0); *\/ */ +/* /\* getPllReconfigReg(PLL_MODE_REG,0); *\/ */ -/* u_int32_t addr=0xa; //c0 */ -/* if (ic>0) */ -/* addr=0xb; //c1 */ +/* /\* u_int32_t addr=0xa; //c0 *\/ */ +/* /\* if (ic>0) *\/ */ +/* /\* addr=0xb; //c1 *\/ */ -/* val=getPllReconfigReg(PLL_N_COUNTER_REG,0); */ -/* printf("Getting N counter %08x\n",val); */ +/* /\* val=getPllReconfigReg(PLL_N_COUNTER_REG,0); *\/ */ +/* /\* printf("Getting N counter %08x\n",val); *\/ */ -/* l=val&0xff; */ -/* h=(val>>8)&0xff; */ +/* /\* l=val&0xff; *\/ */ +/* /\* h=(val>>8)&0xff; *\/ */ -/* //getPllReconfigReg(PLL_STATUS_REG,0); */ -/* val=getPllReconfigReg(addr,0); */ -/* printf("Getting C counter %08x\n",val); */ +/* /\* //getPllReconfigReg(PLL_STATUS_REG,0); *\/ */ +/* /\* val=getPllReconfigReg(addr,0); *\/ */ +/* /\* printf("Getting C counter %08x\n",val); *\/ */ -/* return 800/(l+h); */ +/* /\* return 800/(l+h); *\/ */ -} +/* } */ u_int32_t adcPipeline(int d) { - if (d>=0) - bus_w(DAQ_REG, d); - return bus_r(DAQ_REG)&0xff; + u_int32_t v; + if (d>=0) { + v=bus_r(ADC_PIPELINE_REG)&0x00ff0000; + bus_w(ADC_PIPELINE_REG, d|v); + } + return bus_r(ADC_PIPELINE_REG)&0xff; +} + + +u_int32_t dbitPipeline(int d) { + u_int32_t v; + if (d>=0) { + v=bus_r(ADC_PIPELINE_REG)&0x000000ff; + bus_w(ADC_PIPELINE_REG, v|(d<<16)); + + } + v=bus_r(ADC_PIPELINE_REG)>>16; + return v&0xff; } @@ -672,11 +701,11 @@ u_int32_t getSetLength() { } u_int32_t setOversampling(int d) { + return 0; + /* if (d>=0 && d<=255) */ + /* bus_w(OVERSAMPLING_REG, d); */ - if (d>=0 && d<=255) - bus_w(OVERSAMPLING_REG, d); - - return bus_r(OVERSAMPLING_REG); + /* return bus_r(OVERSAMPLING_REG); */ } @@ -689,23 +718,6 @@ u_int32_t getWaitStates() { } -u_int32_t setTotClockDivider(int d) { - return 0; -} - -u_int32_t getTotClockDivider() { - return 0; -} - - -u_int32_t setTotDutyCycle(int d) { - return 0; -} - -u_int32_t getTotDutyCycle() { - return 0; -} - u_int32_t setExtSignal(int d, enum externalSignalFlag mode) { @@ -1002,6 +1014,51 @@ int setToT(int d) { return 0; } +/* int setOutputMode(int d) { */ +/* //int ret=0; */ +/* int reg; */ +/* int v; */ +/* //#ifdef VERBOSE */ +/* printf("Setting readout flags to to %d\n",d); */ +/* //#endif */ +/* reg=bus_r(CONFIG_REG); */ +/* //#ifdef VERBOSE */ +/* printf("Before: config reg is %x\n", reg); */ +/* //#endif */ +/* if (d>=0) { */ +/* reg=reg & ~(3<<8); */ +/* if (d==DIGITAL_ONLY) */ +/* reg=reg | (3<<8); */ +/* else if (d==ANALOG_AND_DIGITAL) */ +/* reg=reg | (2<<8); */ + +/* bus_w(CONFIG_REG,reg); */ + +/* } */ + +/* reg=bus_r(CONFIG_REG); */ +/* //#ifdef VERBOSE */ +/* printf("After: config reg is %x\n", reg); */ +/* //#endif */ +/* if ((reg&(2<<8))) { */ +/* if (reg&(1<<8)) { */ +/* digitalEnable=1; */ +/* analogEnable=0; */ +/* return DIGITAL_ONLY; */ +/* } else { */ +/* digitalEnable=1; */ +/* analogEnable=0; */ +/* return ANALOG_AND_DIGITAL; */ +/* } */ +/* } else */ +/* if (reg&(1<<8)) */ +/* return -1; */ +/* else */ +/* return NORMAL_READOUT; */ + + +/* } */ + int setContinousReadOut(int d) { //int ret=0; int reg; @@ -1012,6 +1069,9 @@ int setContinousReadOut(int d) { #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) { @@ -1030,12 +1090,12 @@ int setContinousReadOut(int d) { int startReceiver(int start) { u_int32_t addr=CONFIG_REG; -#ifdef VERBOSE + //#ifdef VERBOSE if(start) printf("Setting up detector to send to Receiver\n"); else printf("Setting up detector to send to CPU\n"); -#endif + //#endif int reg=bus_r(addr); //for start recever, write 0 and for stop, write 1 if (!start) @@ -1049,10 +1109,13 @@ int startReceiver(int start) { //#endif int d =reg&GB10_NOT_CPU_BIT; if(d!=0) d=1; + + printf("Value is %d expected %d\n", d, start); + if(d!=start) - return OK; - else return FAIL; + else + return OK; } @@ -1159,10 +1222,8 @@ u_int32_t testRAM(void) { int getNModBoard() { -if(myDetectorType == JUNGFRAU) - return 1; -else - return 32;//nModX; + + return 1; } int setNMod(int n) { @@ -1212,7 +1273,7 @@ int64_t set64BitReg(int64_t value, int aLSB, int aMSB){ v64=value>> 32; vMSB=v64&(0xffffffff); bus_w(aMSB,vMSB); - printf("Wreg64(%x,%x) %08x %08x %016llx\n", aLSB>>11, aMSB>>11, vLSB, vMSB, value); + // printf("Wreg64(%x,%x) %08x %08x %016llx\n", aLSB>>11, aMSB>>11, vLSB, vMSB, value); } return get64BitReg(aLSB, aMSB); @@ -1226,7 +1287,7 @@ int64_t get64BitReg(int aLSB, int aMSB){ v64=vMSB; v64=(v64<<32) | vLSB; - printf("reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, v64); + // printf("reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, v64); return v64; } @@ -1276,11 +1337,24 @@ int64_t setPeriod(int64_t value){ printf("Period already even is %08llx\n ", value); - return set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ); + return set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-3*clkDivider[1]);//(1E-9*CLK_FREQ); } + + + int64_t getPeriod(){ - return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ); + return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-3*clkDivider[1]);//(1E-9*CLK_FREQ); +} +int64_t setSamples(int64_t value){ + if (value>=0) { + nSamples=value; + bus_w(NSAMPLES_REG,nSamples); + } + getDynamicRange(); + allocateRAM(); + //printf("Setting dataBytes to %d: dr %d; samples %d\n",dataBytes, dynamicRange, nSamples); + return nSamples; } int64_t setDelay(int64_t value){ @@ -1362,16 +1436,13 @@ int64_t getFramesFromStart(){ } -ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret) { +int setROI(int nroi,ROI* arg,int *retvalsize, int *ret) { - if(myDetectorType == JUNGFRAU) - cprintf(RED,"ROI Not implemented for Jungfrau yet\n"); - return NULL; + - - ROI retval[MAX_ROIS]; + // ROI retval[MAX_ROIS]; int i, ich; - adcDisableMask=0xfffffffff; /*warning: integer constant is too large for ‘long’ type,warning: large integer implicitly truncated to unsigned type*/ + adcDisableMask=0xffffffff; printf("Setting ROI\n"); if (nroi>=0) { @@ -1398,9 +1469,11 @@ ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret) { printf("read adc disable mask %08x\n",adcDisableMask); *retvalsize=0; - retval[0].xmin=0; - retval[0].xmax=0; + if (adcDisableMask==0) return *retvalsize; + arg[0].xmin=0; + arg[0].xmax=0; for (ich=0 ; ichMAX_ROIS) { *retvalsize-=1; break; } - retval[*retvalsize-1].xmin=ich; + arg[*retvalsize-1].xmin=ich; } - retval[*retvalsize-1].xmax=ich; + arg[*retvalsize-1].xmax=ich; } } } + + for (ich=0; ich<*retvalsize; ich++) { + printf("%d xmin %d xmax %d\n", ich, arg[ich].xmin, arg[ich].xmax); + } + getDynamicRange(); - return retval;/*warning: function returns address of local variable*/ + return *retvalsize;/*warning: function returns address of local variable*/ } @@ -1565,10 +1644,10 @@ int initHighVoltage(int val, int imod){ u_int32_t offw,codata; u_int16_t valw, dacvalue; - int iru,i,ddx,csdx,cdx; - float alpha=0.55, fval=val; + int i,ddx,csdx,cdx;//iru, + float alpha=0.55;//, fval=val; - if (val>=0) { + if (val!=-1) { if (val<60) { dacvalue=0; @@ -1579,35 +1658,43 @@ int initHighVoltage(int val, int imod){ } else { dacvalue=1.+(200.-val)/alpha; val=200.-(dacvalue-1)*alpha; - } + } printf ("****************************** setting val %d, dacval %d\n",val, dacvalue); - offw=DAC_REG; - - ddx=8; csdx=10; cdx=9; - codata=((dacvalue)&0xff); - + if (val>=0) { + + offw=DAC_REG; + + ddx=8; csdx=10; cdx=9; + codata=((dacvalue)&0xff); + - - valw=0xffff; bus_w(offw,(valw)); // start point - valw=((valw&(~(0x1<>(7-i))&0x1)< 1 ) { sum += *addr++; count -= 2; @@ -1849,7 +1936,7 @@ volatile u_int32_t conf= bus_r(CONFIG_REG); usleep(10000); bus_w(CONFIG_REG,conf | GB10_NOT_CPU_BIT); printf("System status register is %08x\n",bus_r(SYSTEM_STATUS_REG)); - return; + return OK; } @@ -2032,21 +2119,11 @@ u_int32_t fifo_full(void) u_int16_t* fifo_read_event(int ns) { - int i=0;//, j=0; -/* volatile u_int16_t volatile *dum; */ - volatile u_int16_t a; - /*volatile u_int32_t val;*/ - // volatile u_int32_t volatile *dum; - // volatile u_int32_t a; - - bus_w16(DUMMY_REG,0); // -/* #ifdef TIMEDBG */ -/* gettimeofday(&tse,NULL); */ -/* #endif */ + int i=0, mask=1;//j, + volatile u_int16_t a; + bus_w16(DUMMY_REG,0); if (ns==0) { a=bus_r16(LOOK_AT_ME_REG); - // volatile u_int32_t t = bus_r16(LOOK_AT_ME_REG); - // bus_w(DUMMY_REG,0); while(a==0) { if (runBusy()==0) { a = bus_r(LOOK_AT_ME_REG); @@ -2055,13 +2132,12 @@ u_int16_t* fifo_read_event(int ns) printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); return NULL; } else { - // printf("status idle, look at me %x status %x\n", bus_r(LOOK_AT_ME_REG),runState()); break; } } a = bus_r(LOOK_AT_ME_REG); //#ifdef VERBOSE - printf("."); + //printf("."); //#endif } /* #ifdef TIMEDBG */ @@ -2073,80 +2149,41 @@ u_int16_t* fifo_read_event(int ns) // printf("LAM: %08x\n",a); } - // printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); -/* dma_memcpy(now_ptr,values ,dataBytes); */ -/* #else */ + // printf("."); a = bus_r(LOOK_AT_ME_REG); - //#ifdef VERBOSE - // printf("%d %08x\n",ns,a); - bus_w16(DUMMY_REG,1<<8); // read strobe to all fifos - bus_w16(DUMMY_REG,0); - - /* for (i=0; i<32; i++) { */ - /* bus_w16(DUMMY_REG,i); */ - /* printf("%04x ",bus_r16(FIFO_STATUS_REG)); */ - /* // a = bus_r(LOOK_AT_ME_REG); */ - /* // printf("%d %08x\n",i,a); */ - /* } */ - /* printf("\n"); */ - // i=0;// -/* for (i=0; i<32; i++) { */ - -/* /\* while (((adcDisableMask&(3<<((i)*2)))>>((i)*2))==3) { *\/ */ -/* /\* i++; *\/ */ -/* /\* if (i>15) *\/ */ -/* /\* break; *\/ */ -/* /\* } *\/ */ -/* /\* if (i<16) { *\/ */ -/* bus_w16(DUMMY_REG,i); */ -/* } */ -/* val=*values; */ - - - // bus_w16(DUMMY_REG,0); // + if (analogEnable) { + printf("*"); + bus_w16(DUMMY_REG,1<<8); // read strobe to all fifos + bus_w16(DUMMY_REG,0); for (i=0; i<32; i++) { - - - // bus_w16(DUMMY_REG,i); - // bus_r16(DUMMY_REG); -/* dum=(((u_int16_t*)(now_ptr))+i); */ -/* *dum=bus_r16(FIFO_DATA_REG); */ -/* a=bus_r16(FIFO_DATA_REG); */ - //dum=(((u_int32_t*)(now_ptr))+i); - - // a=*values;//bus_r(FIFO_DATA_REG); - // if ((adcDisableMask&(3<<(i*2)))==0) { - *((u_int16_t*)now_ptr)=bus_r16(FIFO_DATA_REG);//*values;//bus_r(FIFO_DATA_REG); - - - if (i!=0 || ns!=0) { - a=0; + if (~(mask&adcDisableMask)) { + *((u_int16_t*)now_ptr)=*values;//bus_r16(FIFO_DATA_REG); + if (i!=0 || ns!=0) { + a=0; while (*((u_int16_t*)now_ptr)==*((u_int16_t*)(now_ptr)-1) && a++<10) { - - // printf("******************** %d: fifo %d: new %08x old %08x\n ",ns, i, *((u_int32_t*)now_ptr),*((u_int32_t*)(now_ptr)-1)); - *((u_int16_t*)now_ptr)=bus_r16(FIFO_DATA_REG);//*values; - // printf("%d-",i); - + *((u_int16_t*)now_ptr)=*values; } } - now_ptr+=2;//4; - // } -/* while (((adcDisableMask&(3<<((i+1)*2)))>>((i+1)*2))==3) { */ -/* i++; */ -/* } */ - - // if (((adcDisableMask&(3<<((i+1)*2)))>>((i+1)*2))!=3) { - - bus_w16(DUMMY_REG,i+1); - - // a = bus_r(LOOK_AT_ME_REG); - // printf("%d %08x\n",i,a); - //#ifdef VERBOSE - // } - // *(((u_int16_t*)(now_ptr))+i)=bus_r16(FIFO_DATA_REG); + now_ptr+=2; + } + mask=mask<<1; + // if (~(mask&adcDisableMask) + bus_w16(DUMMY_REG,i+1); } + } + if (digitalEnable) { + // printf("+"); + + bus_w16(DUMMY_REG,1<<9); // read strobe to digital fifo + bus_w16(DUMMY_REG,0<<9); // read strobe to digital fifo + *((u_int64_t*)now_ptr)=get64BitReg(FIFO_DIGITAL_DATA_LSB_REG,FIFO_DIGITAL_DATA_MSB_REG); + //bit17 is clkout + printf("%d",(*((u_int64_t*)now_ptr)>>17)&1); + now_ptr+=8; + + } // bus_w16(DUMMY_REG,0); // /* #ifdef TIMEDBG */ @@ -2157,6 +2194,7 @@ u_int16_t* fifo_read_event(int ns) //#ifdef VERBOSE // printf("*"); //#endif + // printf("\n"); return ram_values; } @@ -2296,14 +2334,15 @@ int setDynamicRange(int dr) { int getDynamicRange() { if(myDetectorType == JUNGFRAU){ - dynamicRange=16; + dynamicRange=16; return dynamicRange; } nSamples=bus_r(NSAMPLES_REG); getChannels(); - dataBytes=nModX*N_CHIP*getChannels()*2; - return dynamicRange*bus_r(NSAMPLES_REG);//nSamples; + dataBytes=nModX*N_CHIP*getChannels()*2*nSamples; + printf("data bytes is:%d\n",dataBytes); + return dynamicRange;//nSamples; } int testBus() { @@ -2349,11 +2388,17 @@ int setStoreInRAM(int b) { } int getChannels() { - int nch=32; + int nch=0; int i; - for (i=0; i> (13-ibit)) & 1); + // printf("%d",obit); + valw = obit << sdi_bit; + + bus_w(ADC_WRITE_REG,valw); + + usleep(20); + + bus_w(ADC_WRITE_REG,valw|(1<> (13-ibit)) & 1); + // printf("%d",obit); + valw = obit << sdi_bit; + + bus_w(ADC_WRITE_REG,valw); + + usleep(20); + + bus_w(ADC_WRITE_REG,valw|(1<7) + return -1; + prepareSlowADC(ichan); - for (ichan=0; ichan<8; ichan++) { + /* printf("Codata is %04x\n",codata); */ + + /* /\* //convert *\/ */ + /* valw=(1<> (13-ibit)) & 1); */ + /* // printf("%d",obit); */ + /* valw = obit << sdi_bit; */ + + /* bus_w(ADC_WRITE_REG,valw); */ + + /* usleep(20); */ + + /* bus_w(ADC_WRITE_REG,valw|(1<>(24-i))&0x1)<>(24-i))&0x1)); - - - valw=((valw&(~(0x1<>(24-i))&0x1)<>(24-i))&0x1)); + valw=((valw&(~(0x1<=0) { printf("vpower\n"); - dacval=((vmax-val)*4095)/(vmax-vmin); - if (dacval<0) - dacval=0; - if (dacval>4095) - dacval=-100; - if (val==-100) - dacval=-100; + dacval=((vmax-val)*4095)/(vmax-vmin); + if (dacval<0) + dacval=0; + if (dacval>4095) + dacval=-100; + if (val==-100) + dacval=-100; + - } else { + } else if (dacindex>=0) { printf("vchip\n"); - dacval=((2700-val)*4095)/1000; - if (dacval<0) - dacval=0; - if (dacval>4095) - dacval=4095; + dacval=((2700-val)*4095)/1000; + if (dacval<0) + dacval=0; + if (dacval>4095) + dacval=4095; + + } else { + vLimit=val; + printf("vlimit %d\n",vLimit ); } + } if (pwrindex>=0 && val!=-1) { @@ -3502,7 +3710,9 @@ int setPower(int ind, int val) { if (pwrindex>=0) { if (bus_r(POWER_ON_REG)&(1<<(16+pwrindex))){ vmax=2700-(getDacRegister(19)*1000)/4095-200; + printf("Vchip id %d mV\n",vmax+200); retval1=vmax-(retval*(vmax-vmin))/4095; + printf("Vdac id %d mV\n",retval1); if (retval1>vmax) retval1=vmax; if (retval1=0) + } else if (dacindex>=0) { + if (retval>=0) { retval1=2700-(retval*1000)/4095; - else + printf("Vchip is %d mV\n",vmax); + } else retval1=-1; + } else { + printf("Get vlimit %d\n",vLimit); + retval=vLimit; + retval1=vLimit; } /* switch (ind) { */ @@ -3543,14 +3758,72 @@ int setPower(int ind, int val) { +int powerChip(int arg) { + //#ifndef CTB + + u_int32_t preg=bus_r(POWER_ON_REG); + if (myDetectorType!=JUNGFRAUCTB) { + if (arg>=0) { + if (arg) + bus_w(POWER_ON_REG,preg|0xffff0000); + else + bus_w(POWER_ON_REG,preg&0x0000ffff); + preg=bus_r(POWER_ON_REG); + } + } + printf("Power register is %08x\n",preg); + if (preg&0xffff0000) + return 1; + else + return 0; +} +int vLimitCompliant(int val_mV) { + int ret=0; + + if (vLimit>0) { + if (val_mV<=vLimit) ret=1; + } else ret=1; + + return ret; + + +} +int dacSPI(int codata) { + u_int32_t offw; + int valw, vv; + int i, ddx,cdx; + ddx=0; cdx=1; + offw=DAC_REG; + valw=bus_r(offw); + // codata=((cmd&0xf)<>(24-i)))&0x1); - - valw=(valw&(~(0x1<>(24-i))&0x1)<>(24-i))&0x1)); - - - valw=((valw&(~(0x1<=0) { + cmd=0x3; - - // printf("data bit=%d, clkbit=%d, csbit=%d",ddx,cdx,csdx); - - //modified to power down single channels - - // codata=((((0x2)<<4)+((dacch)&0xf))<<16)+((dacvalue<<4)&0xfff0); - codata=(0x3)<>(24-i)))&0x1); - valw=(valw&(~(0x1<>(24-i))&0x1)<>(24-i))&0x1)); - - - valw=((valw&(~(0x1<>(24-i)))&0x1); */ + /* valw=(valw&(~(0x1<>(24-i))&0x1)<>(24-i))&0x1)); */ + + + /* valw=((valw)|(0x1<>8)&0x3) { + case 0: + analogEnable=1; + digitalEnable=0; + v1=NORMAL_READOUT; + break; + case 3: + analogEnable=0; + digitalEnable=1; + v1=DIGITAL_ONLY; + break; + case 2: + analogEnable=1; + digitalEnable=1; + v1=ANALOG_AND_DIGITAL; + break; + default: + printf("Unknown readout mode for analog and digital fifos %d\n",(bus_r(CONFIG_REG)>>8)&0x3); + v1=GET_READOUT_FLAGS; + } + getDynamicRange(); + allocateRAM(); + printf("dataBytes is %d\n",dataBytes); + return v1; + +} diff --git a/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.h b/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.h index 001e3b38c..3e91dc9ef 100755 --- a/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.h +++ b/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.h @@ -28,16 +28,20 @@ u_int16_t bus_w16(u_int32_t offset, u_int16_t data);//aldos function u_int32_t bus_w(u_int32_t offset, u_int32_t data); u_int32_t bus_r(u_int32_t offset); -int setPhaseShiftOnce(); -int phaseStep(int st); -int getPhase(); +//int setPhaseShiftOnce(); +//int phaseStep(int st); +//int dbitPhaseStep(int st); +//int getDbitPhase(); +int getPhase(int i); int cleanFifo(); int setDAQRegister(); +int configurePhase(int val, int i); +int configureFrequency(int val, int i); u_int32_t putout(char *s, int modnum); u_int32_t readin(int modnum); -u_int32_t setClockDivider(int d, int ic); -u_int32_t getClockDivider(int ic); +//u_int32_t setClockDivider(int d, int ic); +//u_int32_t getClockDivider(int ic); void resetPLL(); u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val, int trig); @@ -47,12 +51,13 @@ u_int32_t setSetLength(int d); u_int32_t getSetLength(); u_int32_t setWaitStates(int d); u_int32_t getWaitStates(); -u_int32_t setTotClockDivider(int d); -u_int32_t getTotClockDivider(); -u_int32_t setTotDutyCycle(int d); -u_int32_t getTotDutyCycle(); +//u_int32_t setTotClockDivider(int d); +//u_int32_t getTotClockDivider(); +//u_int32_t setTotDutyCycle(int d); +//u_int32_t getTotDutyCycle(); u_int32_t setOversampling(int d); u_int32_t adcPipeline(int d); +u_int32_t dbitPipeline(int d); u_int32_t setExtSignal(int d, enum externalSignalFlag mode); int getExtSignal(int d); @@ -184,7 +189,7 @@ int setDac(int dacnum,int dacvalue); int setPower(int ind, int val); -ROI *setROI(int nroi,ROI* arg,int *retvalsize, int *ret); +int setROI(int nroi,ROI* arg,int *retvalsize, int *ret); int getChannels(); /* @@ -211,5 +216,11 @@ int calibration_sensor(int num, int *values, int *dacs) ; int calibration_chip(int num, int *values, int *dacs); */ +int64_t setSamples(int64_t value); +//int setOutputMode(int d); +int prepareSlowADCSeq(); +int readSlowADC(int ichan); +int setReadOutMode(int arg); +int vLimitCompliant(int val_mV) #endif diff --git a/slsDetectorSoftware/jctbDetectorServer/jungfrauDetectorServerTest b/slsDetectorSoftware/jctbDetectorServer/jungfrauDetectorServerTest index fa9c626d8..4af0472db 100755 Binary files a/slsDetectorSoftware/jctbDetectorServer/jungfrauDetectorServerTest and b/slsDetectorSoftware/jctbDetectorServer/jungfrauDetectorServerTest differ diff --git a/slsDetectorSoftware/jctbDetectorServer/mcb_funcs.c b/slsDetectorSoftware/jctbDetectorServer/mcb_funcs.c index edf99652a..b67b8fef4 100755 --- a/slsDetectorSoftware/jctbDetectorServer/mcb_funcs.c +++ b/slsDetectorSoftware/jctbDetectorServer/mcb_funcs.c @@ -50,8 +50,8 @@ extern int N_CHANS; extern int nChans; extern int nChips; -extern int nDacs; -extern int nAdcs; +int nDacs; +int nAdcs; int initDetector() { @@ -64,18 +64,11 @@ int initDetector() { printf("Board is for %d modules\n",n); #endif - if(myDetectorType == JUNGFRAU){ - N_CHAN=JUNGFRAU_NCHAN; - N_CHIP=JUNGFRAU_NCHIP; - N_DAC=JUNGFRAU_NDAC; - N_ADC=JUNGFRAU_NADC; - N_CHANS=JUNGFRAU_NCHANS; - - nChans=N_CHAN; - nChips=N_CHIP; - nDacs=N_DAC; - nAdcs=N_ADC; - } + + // 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)); @@ -84,8 +77,8 @@ int initDetector() { detectorChans=NULL; detectorAdcs=NULL; if(myDetectorType != JUNGFRAU){ - detectorChips=malloc(n*N_CHIP*sizeof(int)); - detectorChans=malloc(n*N_CHIP*N_CHAN*sizeof(int)); + detectorChips=malloc(n*N_CHIP*sizeof(int)); + detectorChans=malloc(n*N_CHIP*N_CHAN*sizeof(int)); } #ifdef VERBOSE @@ -101,7 +94,7 @@ int initDetector() { for (imod=0; imoddacs=detectorDacs+imod*N_DAC; - (detectorModules+imod)->adcs=detectorAdcs+imod*N_ADC; + (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; @@ -935,284 +928,285 @@ int setSettings(int i, int imod) { /* 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 +/* 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.chip<0) */ +/* setCSregister(myChan.module); */ +/* else */ +/* selChip(myChan.chip,myChan.module); */ - if (myChan.chan<0) - setSSregister(myChan.module); - else - selChannel(myChan.chan,myChan.module); +/* if (myChan.chan<0) */ +/* setSSregister(myChan.module); */ +/* else */ +/* selChannel(myChan.chan,myChan.module); */ - initChannel(ft,cae,ae, coe, ocoe, counts,myChan.module); +/* initChannel(ft,cae,ae, coe, ocoe, counts,myChan.module); */ - setDynamicRange(dynamicRange); +/* setDynamicRange(dynamicRange); */ - setCSregister(ALLMOD); - clearSSregister(ALLMOD); - putout("0000000000000000",ALLMOD); +/* 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; + /* 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; - } - } + /* 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); - } + /* 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; +/* 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; +/* sMod=imod; */ +/* // printf("initializing module %d\n",sMod); */ +/* if (imod==ALLMOD) { */ +/* sMod=allSelected; */ - // printf("initializing all modules\n"); - } +/* // 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 (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 (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 (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<63 || 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; + /* int imod, ichip; */ + /* imod=myChip.module; */ + /* ichip=myChip.chip; */ + /* int obe=(myChip.reg)&1; */ + /* int ow=(myChip.reg)>>1; */ + /* int nchan, ichan; */ + /* int ft, cae, ae, coe, ocoe, counts, chanreg; */ - nchan=myChip.nchan; - if (ichip<0) - setCSregister(imod); - else - selChip(ichip,imod); + /* 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); + /* 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; + /* 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; - } - } + /* 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; } @@ -1275,9 +1269,9 @@ int getChipbyNumber(sls_detector_chip* myChip){ int initChip(int obe, int ow,int imod){ - int i; - int im, ichip; - int chipmi, chipma, modmi, modma; + /* int i; */ + /* int im, ichip; */ + /* int chipmi, chipma, modmi, modma; */ /* switch (ow) { case 0:; case 1: @@ -1301,208 +1295,208 @@ int initChip(int obe, int ow,int imod){ } */ -#ifdef DEBUGOUT - printf("Initializing chip\n"); -#endif - putout("0000000000000000",imod); -#ifdef DEBUGOUT - printf("Output mode= %d\n", ow); -#endif +/* #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); +/* /\* 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); +/* 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; +/* 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 (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 (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 (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 (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; im>DETECTOR_TYPE_OFFSET); + N_DAC=8; + N_PWR=0; break; } @@ -116,102 +127,25 @@ int init_detector(int b, int checkType) { //control server only-- if (b) { - resetPLL(); - bus_w16(CONTROL_REG, SYNC_RESET); - bus_w16(CONTROL_REG, 0); - bus_w16(CONTROL_REG, GB10_RESET_BIT); - bus_w16(CONTROL_REG, 0); - + resetPLL(); + bus_w16(CONTROL_REG, SYNC_RESET); + bus_w16(CONTROL_REG, 0); + bus_w16(CONTROL_REG, GB10_RESET_BIT); + bus_w16(CONTROL_REG, 0); + #ifdef MCB_FUNCS - printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK)); - if(myDetectorType == JUNGFRAU) - initDetector(); /*allocating detectorModules, detectorsDacs etc for "settings", also does allocate RAM*/ - dataBytes=NMAXMOD*N_CHIP*N_CHAN*2; /**Nchip and Nchan real values get assigned in initDetector()*/ + printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK)); + // if(myDetectorType == JUNGFRAU) + initDetector(); /*allocating detectorModules, detectorsDacs etc for "settings", also does allocate RAM*/ + dataBytes=NMAXMOD*N_CHIP*N_CHAN*2; /**Nchip and Nchan real values get assigned in initDetector()*/ printf("Initializing Detector\n"); //bus_w16(CONTROL_REG, SYNC_RESET); // reset registers #endif - - prepareSlowADC(); - // testFpga(); - // testRAM(); - // printf("ADC_SYNC_REG:%x\n",bus_r(ADC_SYNC_REG)); - //moench specific - // setPhaseShiftOnce(); - /*some registers set, which is in common with jungfrau, please check */ + if (myDetectorType==JUNGFRAUCTB) prepareSlowADCSeq(); + prepareADC(); - //setADC(-1); //already does setdaqreg and clean fifo - // setSettings(GET_SETTINGS,-1); - /*some registers set, which is in common with jungfrau, please check */ - initDac(0); initDac(8); //initializes the two dacs - - if(myDetectorType==JUNGFRAU){ - /** for jungfrau reinitializing macro */ - N_CHAN=JUNGFRAU_NCHAN; - N_CHIP=JUNGFRAU_NCHIP; - N_DAC=JUNGFRAU_NDAC; - N_ADC=JUNGFRAU_NADC; - N_CHANS=JUNGFRAU_NCHANS; - - - //set dacs - int retval = -1; - int dacvalues[14][2]={ - {0, 1250}, //vout_cm - {10, 1053}, //vin_com - {1, 600}, //vb_sda - {11, 1000}, //vb_colbuf - {2, 3000}, //vb_test_cur - {3, 830}, //vcascp_pixbuf - {4, 1630}, //vcascn_pixbuf - {12, 750}, //vb_pixbuf - {6, 480}, //vref_ds - {5, 1000}, //vb_ds - {7, 400}, //vref_comp - {13, 1220}, //vb_comp - {8, 1500}, //vref_prech - {9, 3000}, //vdd_prot - }; - for(i=0;i<14;++i){ - retval=setDac(dacvalues[i][0], dacvalues[i][1]); - if(retval!=dacvalues[i][1]) - printf("Error: Setting dac %d failed, wrote %d, read %d\n",dacvalues[i][0],dacvalues[i][1],retval); - } - - //power on the chips - bus_w(POWER_ON_REG,0x1); - - //reset adc - writeADC(ADCREG1,0x3); writeADC(ADCREG1,0x0); - writeADC(ADCREG2,0x40); - writeADC(ADCREG3,0xf); - writeADC(ADCREG4,0x3f); - //vrefs - configurable? - writeADC(ADCREG_VREFS,0x2); - - - //set ADCINVERSionreg (by trial and error) - bus_w(ADC_INVERSION_REG,0x453b2a9c); - - //set adc_pipeline - bus_w(ADC_PIPELINE_REG,0x20); //same as ADC_OFFSET_REG - - //set dbit_pipeline - bus_w(DBIT_PIPELINE_REG,0x100e); - usleep(1000000);//1s - - //reset mem machine fifos fifos - bus_w(MEM_MACHINE_FIFOS_REG,0x4000); - bus_w(MEM_MACHINE_FIFOS_REG,0x0); - - //reset run control - bus_w(MEM_MACHINE_FIFOS_REG,0x0400); - bus_w(MEM_MACHINE_FIFOS_REG,0x0); - - //set default setting - setSettings(DYNAMICGAIN,-1); - } - - + + //Initialization of acquistion parameters setFrames(-1); setTrains(-1); @@ -219,7 +153,7 @@ int init_detector(int b, int checkType) { setPeriod(-1); setDelay(-1); setGates(-1); - + setTiming(GET_EXTERNAL_COMMUNICATION_MODE); setMaster(GET_MASTER); setSynchronization(GET_SYNCHRONIZATION_MODE); @@ -236,12 +170,13 @@ int init_detector(int b, int checkType) { // getDynamicRange(); /* both these functions setROI and allocateRAM should go into the control server part. */ - if(myDetectorType!=JUNGFRAU){ - int retvalsize,ret; - setROI(-1,NULL,&retvalsize,&ret); - allocateRAM(); - } + int retvalsize,ret; + setROI(-1,NULL,&retvalsize,&ret); + allocateRAM(); + + setSamples(1); + bus_w(DAC_REG,0xffff); return OK; } @@ -332,6 +267,7 @@ int function_table() { flist[F_CALIBRATE_PEDESTAL]=&calibrate_pedestal; flist[F_SET_CTB_PATTERN]=&set_ctb_pattern; flist[F_WRITE_ADC_REG]=&write_adc_register; + flist[F_POWER_CHIP]=&power_chip; return OK; } @@ -418,7 +354,7 @@ int get_detector_type(int file_des) { /* receive arguments */ /* execute action */ - ret=myDetectorType; + ret=JUNGFRAUCTB;//myDetectorType; #ifdef VERBOSE printf("Returning detector type %d\n",ret); @@ -1045,6 +981,7 @@ int set_dac(int file_des) { int n; int val; int mV=0; + int v; sprintf(mess,"Can't set DAC\n"); n = receiveDataOnly(file_des,arg,sizeof(arg)); @@ -1081,27 +1018,35 @@ int set_dac(int file_des) { -#ifdef MCB_FUNCS if (ret==OK) { if (differentClients==1 && lockStatus==1) { ret=FAIL; sprintf(mess,"Detector locked by %s\n",lastClientIP); } else{ - if (ind2500) + + v=val; + + if (val>2500) val=-1; printf("%d mV is ",val); if (val>0) val=val/2500*4095; printf("%d DACu\n", val); - } else if (val>4095) - val=-1; + } else { + v=val*2500/4095; + if (val>4095) { + val=-1; + } + } - - retval=setDac(ind,val); + if (vLimitCompliant(v)) + retval=setDac(ind,val); + + } else { switch (ind) { case ADC_VPP: @@ -1126,23 +1071,36 @@ int set_dac(int file_des) { case V_POWER_D: case V_POWER_IO: case V_POWER_CHIP: + if (mV) { + if (vLimitCompliant(val)) + retval=setPower(ind,val); + else + printf("********power %d exceeds voltage limits", ind); + + } else + printf("********power %d should be set in mV instead od DACu", ind); + break; + + case V_LIMIT: if (mV) { retval=setPower(ind,val); } else printf("********power %d should be set in mV instead od DACu", ind); break; - default: printf("**********No dac with index %d\n",ind); + printf("**********%d %d\n",N_DAC,N_PWR); ret=FAIL; } } } } + + if(ret==OK){ - if (ind=0) { + ret=OK; + } + + } + + #endif #ifdef VERBOSE @@ -2066,7 +2032,7 @@ int get_run_status(int file_des) { } int read_frame(int file_des) { - + int n; u_int16_t* p=NULL; if (differentClients==1 && lockStatus==1) { @@ -2087,14 +2053,15 @@ int read_frame(int file_des) { nframes++; dataretval=(char*)ram_values; dataret=OK; -#ifdef VERBOSE + //#ifdef VERBOSE printf("sending data of %d frames\n",nframes); -#endif + //#endif sendDataOnly(file_des,&dataret,sizeof(dataret)); -#ifdef VERYVERBOSE - printf("sending pointer %x of size %d\n",(unsigned int)(dataretval),dataBytes*nSamples); -#endif - sendDataOnly(file_des,dataretval,dataBytes*nSamples); + //#ifdef VERYVERBOSE + printf("sending pointer %x of size %d\n",(unsigned int)(dataretval),dataBytes); + //#endif + n=sendDataOnly(file_des,dataretval,dataBytes); + printf("Sent %d bytes\n",n); } else { if (getFrames()>-1) { dataret=FAIL; @@ -2242,6 +2209,9 @@ int set_timer(int file_des) { case CYCLES_NUMBER: retval=setTrains(tns); break; + case SAMPLES_JCTB: + retval=setSamples(tns); + break; default: ret=FAIL; sprintf(mess,"timer index unknown %d\n",ind); @@ -2343,6 +2313,9 @@ int get_time_left(int file_des) { case FRAMES_FROM_START_PG: retval=getFramesFromStart(); break; + case SAMPLES_JCTB: + retval=setSamples(-1); + break; default: ret=FAIL; sprintf(mess,"timer index unknown %d\n",ind); @@ -2433,7 +2406,7 @@ int set_roi(int file_des) { int n=0; int retvalsize=0; ROI arg[MAX_ROIS]; - ROI* retval=0; + int retval; strcpy(mess,"Could not set/get roi\n"); // u_int32_t disable_reg=0; @@ -2443,43 +2416,33 @@ int set_roi(int file_des) { ret=FAIL; } - if(myDetectorType == JUNGFRAU){ - ret = FAIL; - strcpy(mess,"Not applicable/implemented for this detector\n"); - printf("Error:Set ROI-%s",mess); + + if(nroi>=0){ + n = receiveDataOnly(file_des,arg,nroi*sizeof(ROI)); + if (n != (nroi*sizeof(ROI))) { + sprintf(mess,"Received wrong number of bytes for ROI\n"); + ret=FAIL; + } + + printf("Setting ROI to:"); + for( i=0;i=0){ - n = receiveDataOnly(file_des,arg,nroi*sizeof(ROI)); - if (n != (nroi*sizeof(ROI))) { - sprintf(mess,"Received wrong number of bytes for ROI\n"); - ret=FAIL; - } - - printf("Setting ROI to:"); - for( i=0;i=0){//necessary??? + sprintf(mess,"Detector locked by %s\n", lastClientIP); + ret=FAIL; + } else{ + retval=setROI(nroi,arg,&retvalsize,&ret); + if (ret==FAIL){ + printf("mess:%s\n",mess); + sprintf(mess,"Could not set all roi, should have set %d rois, but only set %d rois\n",nroi,retvalsize); + } } - if(ret==OK && differentClients){ printf("Force update\n"); ret=FORCE_UPDATE; @@ -2491,7 +2454,7 @@ int set_roi(int file_des) { n = sendDataOnly(file_des,mess,sizeof(mess)); else{ sendDataOnly(file_des,&retvalsize,sizeof(retvalsize)); - sendDataOnly(file_des,retval,retvalsize*sizeof(ROI)); + sendDataOnly(file_des,arg,retvalsize*sizeof(ROI)); } /*return ok/fail*/ return ret; @@ -2525,15 +2488,17 @@ int set_speed(int file_des) { if (ret==OK) { - if (arg==PHASE_SHIFT || arg==ADC_PHASE) { + /* if (arg==PHASE_SHIFT || arg==ADC_PHASE) { */ - retval=phaseStep(val); + /* retval=phaseStep(val); */ - } else { + /* } else if ( arg==DBIT_PHASE) { */ + /* retval=dbitPhaseStep(val); */ + /* } else { */ - if (val!=-1) { + /* if (val!=-1) { */ if (differentClients==1 && lockStatus==1 && val>=0) { @@ -2541,8 +2506,23 @@ int set_speed(int file_des) { sprintf(mess,"Detector locked by %s\n",lastClientIP); } else { switch (arg) { + case PHASE_SHIFT: + case ADC_PHASE: + if (val==-1) + retval=getPhase(run_clk_c); + else + retval=configurePhase(val,run_clk_c); + break; + + case DBIT_PHASE: + if (val==-1) + retval=getPhase(dbit_clk_c); + else + retval=configurePhase(val,dbit_clk_c); + break; + case CLOCK_DIVIDER: - retval=setClockDivider(val,0); + retval=configureFrequency(val,run_clk_c);//setClockDivider(val,0); break; /* case PHASE_SHIFT: */ @@ -2554,12 +2534,14 @@ int set_speed(int file_des) { break; case ADC_CLOCK: - retval=setClockDivider(val,1); + retval=configureFrequency(val,adc_clk_c);//setClockDivider(val,1); + configureFrequency(val,sync_clk_c); + break; + + case DBIT_CLOCK: + retval=configureFrequency(val,dbit_clk_c);//setClockDivider(val,2); break; -/* case ADC_PHASE: */ -/* retval=phaseStep(val,1); */ -/* break; */ case ADC_PIPELINE: @@ -2567,54 +2549,21 @@ int set_speed(int file_des) { break; + case DBIT_PIPELINE: + retval=dbitPipeline(val); + break; default: ret=FAIL; sprintf(mess,"Unknown speed parameter %d",arg); } } - } + // } - } - - - switch (arg) { - case CLOCK_DIVIDER: - retval=getClockDivider(0); - break; - - case PHASE_SHIFT: - retval=getPhase(); - // retval=phaseStep(-1); - //ret=FAIL; - //sprintf(mess,"Cannot read phase",arg); - break; - - case OVERSAMPLING: - retval=setOversampling(-1); - break; - - case ADC_CLOCK: - retval=getClockDivider(1); - break; - - case ADC_PHASE: - retval=getPhase(); - break; - - - case ADC_PIPELINE: - retval=adcPipeline(-1); - break; - - - default: - ret=FAIL; - sprintf(mess,"Unknown speed parameter %d",arg); - } } + n = sendDataOnly(file_des,&ret,sizeof(ret)); @@ -2631,15 +2580,34 @@ int set_speed(int file_des) { int set_readout_flags(int file_des) { enum readOutFlags arg; - int ret=FAIL; - + int ret=OK; + enum readOutFlags v=-1; receiveDataOnly(file_des,&arg,sizeof(arg)); - sprintf(mess,"can't set readout flags for moench\n"); + switch (arg) { + case NORMAL_READOUT: + case DIGITAL_ONLY: + case ANALOG_AND_DIGITAL: + case GET_READOUT_FLAGS: + break; + default: + sprintf(mess,"unknown readout flags for jctb\n"); + ret=FAIL; + } + if (ret==OK) + v=setReadOutMode(arg); + if (v<0) { + ret=FAIL; + sprintf(mess,"found non valid readout mode (neither analog nor digital)\n"); + } sendDataOnly(file_des,&ret,sizeof(ret)); - sendDataOnly(file_des,mess,sizeof(mess)); + if (ret==OK) + sendDataOnly(file_des,&v,sizeof(v)); + else + sendDataOnly(file_des,mess,sizeof(mess)); + // sendDataOnly(file_des,mess,sizeof(mess)); return ret; } @@ -2786,6 +2754,7 @@ int send_update(int file_des) { int n;//int thr, n; //int it; int64_t retval, tns=-1; + enum readOutFlags v=-1; n = sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP)); n = sendDataOnly(file_des,&nModX,sizeof(nModX)); n = sendDataOnly(file_des,&nModY,sizeof(nModY)); @@ -2809,7 +2778,12 @@ int send_update(int file_des) { n = sendDataOnly(file_des,&retval,sizeof(int64_t));*/ retval=setTrains(tns); n = sendDataOnly(file_des,&retval,sizeof(int64_t)); + retval=setSamples(tns); + n = sendDataOnly(file_des,&retval,sizeof(int64_t)); + v=setReadOutMode(-1); + sendDataOnly(file_des,&v,sizeof(v)); + if (lockStatus==0) { strcpy(lastClientIP,thisClientIP); } @@ -3179,13 +3153,14 @@ int reset_counter_block(int file_des) { + int start_receiver(int file_des) { int ret=OK; int n=0; strcpy(mess,"Could not start receiver\n"); /* execute action if the arguments correctly arrived*/ -#ifdef MCB_FUNCS + //#ifdef MCB_FUNCS if (lockStatus==1 && differentClients==1){//necessary??? sprintf(mess,"Detector locked by %s\n", lastClientIP); ret=FAIL; @@ -3193,7 +3168,7 @@ int start_receiver(int file_des) { else ret = startReceiver(1); -#endif + //#endif if(ret==OK && differentClients){ @@ -3513,3 +3488,51 @@ int write_adc_register(int file_des) { return ret; } + +int power_chip(int file_des) { + + int retval=-1; + int ret=OK; + int arg=-1; + int n; + + n = receiveDataOnly(file_des,&arg,sizeof(arg)); + if (n < 0) { + sprintf(mess,"Error reading from socket\n"); + ret=FAIL; + } + + +#ifdef VERBOSE + printf("Power chip to %d\n", arg); +#endif + + if (differentClients==1 && lockStatus==1 && arg!=-1) { + ret=FAIL; + sprintf(mess,"Detector locked by %s\n",lastClientIP); + } else { + retval=powerChip(arg); +#ifdef VERBOSE + printf("Chip powered: %d\n",retval); +#endif + + if (retval==arg || arg<0) { + ret=OK; + } else { + ret=FAIL; + printf("Powering chip failed, wrote %d but read %d\n", arg, retval); + } + + } + if (ret==OK && differentClients==1) + ret=FORCE_UPDATE; + + /* send answer */ + n = sendDataOnly(file_des,&ret,sizeof(ret)); + if (ret==FAIL) { + n += sendDataOnly(file_des,mess,sizeof(mess)); + } else + n += sendDataOnly(file_des,&retval,sizeof(retval)); + + return ret; +} diff --git a/slsDetectorSoftware/jctbDetectorServer/server_funcs.h b/slsDetectorSoftware/jctbDetectorServer/server_funcs.h index 2d674a1d0..8d131d83b 100755 --- a/slsDetectorSoftware/jctbDetectorServer/server_funcs.h +++ b/slsDetectorSoftware/jctbDetectorServer/server_funcs.h @@ -94,5 +94,6 @@ int calibrate_pedestal(int); int set_roi(int); int set_ctb_pattern(int); -int write_adc_register(int);; +int write_adc_register(int); +int power_chip(int); #endif diff --git a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c index 845972a73..20b9e97fb 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c @@ -1032,6 +1032,35 @@ int setContinousReadOut(int d) { } +<<<<<<< HEAD +int startReceiver(int start) { + u_int32_t addr=CONFIG_REG; + //#ifdef VERBOSE + if(start) + printf("Setting up detector to send to Receiver\n"); + else + printf("Setting up detector to send to CPU\n"); + //#endif + int reg=bus_r(addr); + //for start recever, write 0 and for stop, write 1 + if (!start) + bus_w(CONFIG_REG,reg&(~GB10_NOT_CPU_BIT)); + else + bus_w(CONFIG_REG,reg|GB10_NOT_CPU_BIT); + + reg=bus_r(addr); +//#ifdef VERBOSE + printf("Config Reg %x\n", reg); +//#endif + int d =reg&GB10_NOT_CPU_BIT; + if(d!=0) d=1; + if(d!=start) + return OK; + else + return FAIL; +} +======= +>>>>>>> f24459bee05f373e2830bb24388e40f0b2983d5a u_int64_t getDetectorNumber() { @@ -1261,6 +1290,17 @@ int64_t getTrains(){ } +int64_t setSamples(int64_t value){ + if (value>=0) + bus_w(NSAMPLES_REG,value); + return bus_r(NSAMPLES_REG); +} + +int64_t getSamples(){ + return bus_r(NSAMPLES_REG);//get64BitReg(GET_CYCLES_LSB_REG, GET_CYCLES_MSB_REG); +} + + int64_t setProbes(int64_t value){ return 0; } @@ -1835,8 +1875,123 @@ u_int32_t fifoReadStatus(){ return bus_r(STATUS_REG)&(SOME_FIFO_FULL_BIT | ALL_FIFO_EMPTY_BIT); } +<<<<<<< HEAD + +u_int16_t* fifo_read_event(int ns) +{ + int i=0;//, j=0; +/* volatile u_int16_t volatile *dum; */ + volatile u_int16_t a; + /*volatile u_int32_t val;*/ + // volatile u_int32_t volatile *dum; + // volatile u_int32_t a; + + bus_w16(DUMMY_REG,0); // +/* #ifdef TIMEDBG */ +/* gettimeofday(&tse,NULL); */ +/* #endif */ + if (ns==0) { + a=bus_r16(LOOK_AT_ME_REG); + // volatile u_int32_t t = bus_r16(LOOK_AT_ME_REG); + // bus_w(DUMMY_REG,0); + while(a==0) { + if (runBusy()==0) { + a = bus_r(LOOK_AT_ME_REG); + if (a==0) { + printf("no frame found and acquisition finished - exiting\n"); + printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); + return NULL; + } else { + // printf("status idle, look at me %x status %x\n", bus_r(LOOK_AT_ME_REG),runState()); + break; + } + } + a = bus_r(LOOK_AT_ME_REG); + //#ifdef VERBOSE + // printf("."); + //#endif + } +/* #ifdef TIMEDBG */ +/* // tsss=tss; */ +/* gettimeofday(&tss,NULL); */ +/* printf("look for data = %ld usec\n", (tss.tv_usec) - (tse.tv_usec)); */ + +/* #endif */ + + } + // printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); +/* dma_memcpy(now_ptr,values ,dataBytes); */ +/* #else */ + + bus_w16(DUMMY_REG,1<<8); // read strobe to all fifos + bus_w16(DUMMY_REG,0); + // i=0;// +/* for (i=0; i<32; i++) { */ + +/* /\* while (((adcDisableMask&(3<<((i)*2)))>>((i)*2))==3) { *\/ */ +/* /\* i++; *\/ */ +/* /\* if (i>15) *\/ */ +/* /\* break; *\/ */ +/* /\* } *\/ */ +/* /\* if (i<16) { *\/ */ +/* bus_w16(DUMMY_REG,i); */ +/* } */ +/* val=*values; */ + + + // bus_w16(DUMMY_REG,0); // + for (i=0; i<32; i++) { + + + // bus_w16(DUMMY_REG,i); + // bus_r16(DUMMY_REG); +/* dum=(((u_int16_t*)(now_ptr))+i); */ +/* *dum=bus_r16(FIFO_DATA_REG); */ +/* a=bus_r16(FIFO_DATA_REG); */ + //dum=(((u_int32_t*)(now_ptr))+i); + + // a=*values;//bus_r(FIFO_DATA_REG); + // if ((adcDisableMask&(3<<(i*2)))==0) { + *((u_int32_t*)now_ptr)=*values;//bus_r(FIFO_DATA_REG); + + + if (i!=0 || ns!=0) { + a=0; + while (*((u_int32_t*)now_ptr)==*((u_int32_t*)(now_ptr)-1) && a++<10) { + + // printf("******************** %d: fifo %d: new %08x old %08x\n ",ns, i, *((u_int32_t*)now_ptr),*((u_int32_t*)(now_ptr)-1)); + *((u_int32_t*)now_ptr)=*values; + // printf("%d-",i); + + } + } + now_ptr+=4; + // } +/* while (((adcDisableMask&(3<<((i+1)*2)))>>((i+1)*2))==3) { */ +/* i++; */ +/* } */ + + // if (((adcDisableMask&(3<<((i+1)*2)))>>((i+1)*2))!=3) { + printf("sample %d fifo %d status %08x\n",ns,i,bus_r16(FIFO_STATUS_REG)); + bus_w16(DUMMY_REG,i+1); + // } + // *(((u_int16_t*)(now_ptr))+i)=bus_r16(FIFO_DATA_REG); + } + // bus_w16(DUMMY_REG,0); // +/* #ifdef TIMEDBG */ + +/* gettimeofday(&tss,NULL); */ +/* printf("read data loop = %ld usec\n",(tss.tv_usec) - (tse.tv_usec)); */ + +/* #endif */ +#ifdef VERBOSE + printf("*"); +#endif + return ram_values; +======= u_int32_t fifo_full(void){ return bus_r(STATUS_REG)&SOME_FIFO_FULL_BIT; +>>>>>>> f24459bee05f373e2830bb24388e40f0b2983d5a } @@ -1921,12 +2076,36 @@ return dataout; int setDynamicRange(int dr) { +<<<<<<< HEAD + if (dr%16==0 && dr>0) { + dynamicRange=16; + // nSamples=dr/16; + // bus_w(NSAMPLES_REG,nSamples); + } + getDynamicRange(); + allocateRAM(); + printf("Setting dataBytes to %d: dr %d; samples %d\n",dataBytes, dynamicRange, nSamples); + return getDynamicRange(); +======= return dynamicRange; +>>>>>>> f24459bee05f373e2830bb24388e40f0b2983d5a } int getDynamicRange() { +<<<<<<< HEAD + if(myDetectorType == JUNGFRAU){ + dynamicRange=16; + return dynamicRange; + } + + nSamples=bus_r(NSAMPLES_REG); + getChannels(); + dataBytes=nModX*N_CHIP*getChannels()*2*nSamples; + return dynamicRange;//*bus_r(NSAMPLES_REG);//nSamples; +======= return dynamicRange; +>>>>>>> f24459bee05f373e2830bb24388e40f0b2983d5a } int testBus() { diff --git a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h index 2dc493559..6b51cd66c 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h @@ -120,9 +120,13 @@ int64_t getPeriod(); int64_t setTrains(int64_t value); int64_t getTrains(); + int64_t setProbes(int64_t value); int64_t getProbes(); +int64_t setSamples(int64_t value); +int64_t getSamples(); + int64_t getProgress(); int64_t setProgress(); diff --git a/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h b/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h index 9e4889e53..f468f5bb4 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h @@ -71,7 +71,7 @@ #define CONTROL_REG 79<<11//0x24<<11 #define STATUS_REG 2<<11 //0x25<<11 #define CONFIG_REG 77<<11//0x26<<11 -#define EXT_SIGNAL_REG 78<<11// 0x27<<11 +#define EXT_SIGNAL_REG 78<<11// 0x4E<<11 #define FPGA_SVN_REG 0x29<<11 diff --git a/slsDetectorSoftware/jungfrauDetectorServer/server_funcs.c b/slsDetectorSoftware/jungfrauDetectorServer/server_funcs.c index 1aa941a7b..24eef1a62 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/server_funcs.c +++ b/slsDetectorSoftware/jungfrauDetectorServer/server_funcs.c @@ -1850,13 +1850,38 @@ int set_timer(int file_des) { ret=FAIL; } - if (ret!=OK) { - printf(mess); - } +int set_timer(int file_des) { + enum timerIndex ind; + int64_t tns; + int n; + int64_t retval; + int ret=OK; + + + printf("set\n"); + sprintf(mess,"can't set timer\n"); + + n = receiveDataOnly(file_des,&ind,sizeof(ind)); + if (n < 0) { + sprintf(mess,"Error reading from socket\n"); + ret=FAIL; + } + + n = receiveDataOnly(file_des,&tns,sizeof(tns)); + if (n < 0) { + sprintf(mess,"Error reading from socket\n"); + ret=FAIL; + } + + if (ret!=OK) { + printf(mess); + } + #ifdef VERBOSE printf("setting timer %d to %lld ns\n",ind,tns); #endif + if (ret==OK) { if (differentClients==1 && lockStatus==1 && tns!=-1) { diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index de97a2cea..a6092aac1 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1463,7 +1463,8 @@ int* multiSlsDetector::getDataFromDetector() { if(!nodatadetectortype) retval=new int[nel]; - + p=retval; + // cout << "multi: " << thisMultiDetector->dataBytes << endl; for (int id=0; idnumberOfDetectors; id++) { if (detectors[id]) { @@ -1807,6 +1808,8 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t){ } } + if (index==SAMPLES_JCTB) + setDynamicRange(); // check return values!!! thisMultiDetector->timerValue[index]=ret1; @@ -2272,30 +2275,41 @@ slsDetectorDefs::ROI* multiSlsDetector::getROI(int &n){ -double* multiSlsDetector::decodeData(int *datain, double *fdata) { +double* multiSlsDetector::decodeData(int *datain, int &nn, double *fdata) { double *dataout; if (fdata) dataout=fdata; - else - dataout=new double[thisMultiDetector->numberOfChannels]; + else { + if (detectors[0]->getDetectorsType()==JUNGFRAUCTB) { + nn=thisMultiDetector->dataBytes/2; + dataout=new double[nn]; + } else { + nn=thisMultiDetector->numberOfChannels; + dataout=new double[nn]; + } + } // int ich=0; - + int n; double *detp=dataout; int *datap=datain; for (int i=0; inumberOfDetectors; i++) { if (detectors[i]) { - detectors[i]->decodeData(datap, detp); + detectors[i]->decodeData(datap, n, detp); if(detectors[i]->getErrorMask()) setErrorMask(getErrorMask()|(1<getDataBytes()/sizeof(int); - detp+=detectors[i]->getTotalNumberOfChannels(); - + detp+=n; + // if (detectors[0]->getDetectorsType()==JUNGFRAUCTB) { + // detp+=detectors[i]->getDataBytes()/2; + // } else { + // detp+=detectors[i]->getTotalNumberOfChannels(); + // } #ifdef VERBOSE cout << "done " << endl; #endif @@ -3731,6 +3745,7 @@ int multiSlsDetector::setDynamicRange(int p) { if(detectors[idet]->getErrorMask()) setErrorMask(getErrorMask()|(1<dataBytes+=detectors[idet]->getDataBytes(); + // cout << "db " << idet << " " << detectors[idet]->getDataBytes() << endl; thisMultiDetector->numberOfChannels+=detectors[idet]->getTotalNumberOfChannels(); if (ret==-100) ret=ret1; @@ -5196,6 +5211,7 @@ int multiSlsDetector::getData(const int isocket, const bool masking, int* image, + void multiSlsDetector::readFrameFromReceiver(){ //determine number of half readouts and maxX and maxY @@ -5259,7 +5275,7 @@ void multiSlsDetector::readFrameFromReceiver(){ return; } int* multiframe=new int[nel](); - + int nch; volatile uint64_t dataThreadMask = 0x0; @@ -5335,7 +5351,7 @@ void multiSlsDetector::readFrameFromReceiver(){ //send data to callback if(running){ - fdata = decodeData(multiframe); + fdata = decodeData(multiframe,nch); if ((fdata) && (dataReady)){ thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentFileName.c_str(),nx,ny); dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg); @@ -5356,8 +5372,6 @@ void multiSlsDetector::readFrameFromReceiver(){ } - - int multiSlsDetector::lockReceiver(int lock) { int ret=-100, ret1; diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index c8a0e8664..8cec304c7 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -838,7 +838,7 @@ class multiSlsDetector : public slsDetectorUtils { \param datain data from the detector \returns pointer to a double array with a data per channel */ - double* decodeData(int *datain, double *fdata=NULL); + double* decodeData(int *datain, int &nn, double *fdata=NULL); @@ -1242,8 +1242,7 @@ class multiSlsDetector : public slsDetectorUtils { /** Reads frames from receiver through a constant socket */ void readFrameFromReceiver(); - - /** Locks/Unlocks the connection to the receiver + /** Locks/Unlocks the connection to the receiver /param lock sets (1), usets (0), gets (-1) the lock /returns lock status of the receiver */ diff --git a/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c b/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c index 5efb2ae4f..70a995cd0 100755 --- a/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c +++ b/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c @@ -63,15 +63,15 @@ int initDetector() { detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int)); detectorDacs=malloc(n*NDAC*sizeof(dacs_t)); detectorAdcs=malloc(n*NADC*sizeof(dacs_t)); -#ifdef VERBOSE + //#ifdef VERBOSE printf("modules from 0x%x to 0x%x\n",detectorModules, detectorModules+n); printf("chips from 0x%x to 0x%x\n",detectorChips, detectorChips+n*NCHIP); printf("chans from 0x%x to 0x%x\n",detectorChans, detectorChans+n*NCHIP*NCHAN); printf("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs+n*NDAC); printf("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs+n*NADC); -#endif + //#endif for (imod=0; imoddacs=detectorDacs+imod*NDAC; (detectorModules+imod)->adcs=detectorAdcs+imod*NADC; @@ -87,6 +87,7 @@ int initDetector() { (detectorModules+imod)->reg=0; /* initialize registers, dacs, retrieve sn, adc values etc */ } + printf("modules done\n"); thisSettings=UNINITIALIZED; sChan=noneSelected; sChip=noneSelected; @@ -99,9 +100,12 @@ int initDetector() { clearSSregister(ALLMOD); putout("0000000000000000",ALLMOD); + printf("dr\n"); /* initialize dynamic range etc. */ dynamicRange=getDynamicRange(); + printf("nmod\n"); nModX=setNMod(-1); + printf("done\n"); @@ -115,7 +119,7 @@ int initDetector() { // allocateRAM(); - + return OK; } @@ -919,6 +923,7 @@ int setSettings(int i) { for (ind=0; inddynamicRange=16; break; case JUNGFRAUCTB: - thisDetector->nChan[X]=32; + thisDetector->nChan[X]=36; thisDetector->nChan[Y]=1; thisDetector->nChip[X]=1; thisDetector->nChip[Y]=1; thisDetector->nDacs=16; - thisDetector->nAdcs=1; + thisDetector->nAdcs=9; thisDetector->nGain=0; thisDetector->nOffset=0; thisDetector->nModMax[X]=1; @@ -686,12 +691,14 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->timerValue[FRAME_NUMBER]=1; thisDetector->timerValue[MEASUREMENTS_NUMBER]=1; thisDetector->timerValue[CYCLES_NUMBER]=1; + thisDetector->timerValue[SAMPLES_JCTB]=1; thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8; if(thisDetector->myDetectorType==JUNGFRAUCTB) { - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->dynamicRange/8; - + cout << "here1" << endl; + getTotalNumberOfChannels(); + // thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; } if(thisDetector->myDetectorType==MYTHEN){ if (thisDetector->dynamicRange==24 || thisDetector->timerValue[PROBES_NUMBER]>0) @@ -793,6 +800,15 @@ int slsDetector::initializeDetectorSize(detectorType type) { //update?!?!?!? + if(thisDetector->myDetectorType==JUNGFRAUCTB) { + // cout << "here2" << endl; + getTotalNumberOfChannels(); + //thisDetector->nChan[X]=32; + //thisDetector->nChans=thisDetector->nChan[X]*thisDetector->nChan[Y]; + + //thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; + + } } @@ -1030,7 +1046,7 @@ slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType t) na=0; break; case JUNGFRAUCTB: - nch=32;//32; + nch=36; nm=1; nc=1; nd=8; // dacs+adcs @@ -1673,8 +1689,57 @@ slsDetectorDefs::detectorType slsDetector::getDetectorsType(int pos){ } + // /** number of rois defined */ + // int nROI; + // /** list of rois */ + // ROI roiLimits[MAX_ROIS]; + + // /** readout flags */ + // readOutFlags roFlags; +int slsDetector::getTotalNumberOfChannels() { + cout << "total number of channels" << endl; + if(thisDetector->myDetectorType==JUNGFRAUCTB){ + if (thisDetector->roFlags&DIGITAL_ONLY) + thisDetector->nChan[X]=4; + else if (thisDetector->roFlags&ANALOG_AND_DIGITAL) + thisDetector->nChan[X]=36; + else + thisDetector->nChan[X]=32; + + if (thisDetector->nChan[X]>=32) { + if (thisDetector->nROI>0) { + thisDetector->nChan[X]-=32; + for (int iroi=0; iroinROI; iroi++) + thisDetector->nChan[X]+=thisDetector->roiLimits[iroi].xmax-thisDetector->roiLimits[iroi].xmin+1; + } + } + thisDetector->nChans=thisDetector->nChan[X]; + thisDetector->dataBytes=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods*2*thisDetector->timerValue[SAMPLES_JCTB]; + } else + cout << "det type is "<< thisDetector->myDetectorType << endl; + cout << "Total number of channels is "<< thisDetector->nChans*thisDetector->nChips*thisDetector->nMods << " data bytes is " << thisDetector->dataBytes << endl; + return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; +}; + +int slsDetector::getTotalNumberOfChannels(dimension d) { + getTotalNumberOfChannels(); + return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nMod[d]; +}; + + + +int slsDetector::getMaxNumberOfChannels(){ + if(thisDetector->myDetectorType==JUNGFRAUCTB) return 36*thisDetector->nChips*thisDetector->nModsMax; + return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax; +}; + +int slsDetector::getMaxNumberOfChannels(dimension d){ + if(thisDetector->myDetectorType==JUNGFRAUCTB) if (d==X) return 36*thisDetector->nChip[d]*thisDetector->nModMax[d]; else return 1*thisDetector->nChip[d]*thisDetector->nModMax[d]; + return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d]; +}; + /* needed to set/get the size of the detector */ // if n=GET_FLAG returns the number of installed modules, int slsDetector::setNumberOfModules(int n, dimension d){ @@ -1751,14 +1816,6 @@ int slsDetector::setNumberOfModules(int n, dimension d){ if (thisDetector->nModMax[Y]nMod[Y]) thisDetector->nModMax[Y]=thisDetector->nMod[Y]; - - - - - - - - int dr=thisDetector->dynamicRange; if ((thisDetector->myDetectorType==MYTHEN) && (dr==24)) dr=32; @@ -1771,8 +1828,8 @@ int slsDetector::setNumberOfModules(int n, dimension d){ } if(thisDetector->myDetectorType==JUNGFRAUCTB){ - - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*dr/8; + getTotalNumberOfChannels(); + //thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->nChans*dr/8*thisDetector->nChips*thisDetector->timerValue[SAMPLES_JCTB]; } @@ -3742,6 +3799,7 @@ int slsDetector::getChanRegs(double* retval,bool fromDetector){ int slsDetector::updateDetectorNoWait() { + enum readOutFlags ro; // int ret=OK; enum detectorSettings t; int thr, n, nm; @@ -3789,7 +3847,7 @@ int slsDetector::updateDetectorNoWait() { if((thisDetector->myDetectorType!= GOTTHARD)&& (thisDetector->myDetectorType!= PROPIX)&& (thisDetector->myDetectorType!= JUNGFRAU)&& - (thisDetector->myDetectorType!= MOENCH)){ + (thisDetector->myDetectorType!= MOENCH) && (thisDetector->myDetectorType!= JUNGFRAUCTB)){ //thr=getThresholdEnergy(); n = controlSocket->ReceiveDataOnly( &thr,sizeof(thr)); thisDetector->currentThresholdEV=thr; @@ -3823,10 +3881,26 @@ int slsDetector::updateDetectorNoWait() { thisDetector->timerValue[PROBES_NUMBER]=retval; } + //retval=setTrains(tns); n = controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); thisDetector->timerValue[CYCLES_NUMBER]=retval; + //retval=setProbes(tns); + if (thisDetector->myDetectorType == JUNGFRAUCTB){ + n = controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + if (retval>=0) + thisDetector->timerValue[SAMPLES_JCTB]=retval; + n = controlSocket->ReceiveDataOnly( &ro,sizeof(ro)); + + thisDetector->roFlags=ro; + + //retval=setProbes(tns); + getTotalNumberOfChannels(); + + // thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; + + } return OK; } @@ -4013,6 +4087,7 @@ int* slsDetector::getDataFromDetector(int *retval){ nodatadetectortype = true; } + if (!nodatadetectortype && retval==NULL) retval=new int[nel]; @@ -4057,8 +4132,13 @@ int* slsDetector::getDataFromDetector(int *retval){ } return NULL; } + // for (int ib=0; ibdataBytes/8; ib++) + // cout << ((*(((u_int64_t*)retval)+ib))>>17&1) ; + + } - // cout << "get data returning " << endl; + // cout << "get data returning " << endl; + // cout << endl; return retval; }; @@ -4073,8 +4153,8 @@ int* slsDetector::readAll(){ int fnum=F_READ_ALL; int* retval; // check what we return! - int i=0; #ifdef VERBOSE + int i=0; std::cout<< "Reading all frames "<< std::endl; #endif if (thisDetector->onlineFlag==ONLINE_FLAG) { @@ -4082,22 +4162,17 @@ int* slsDetector::readAll(){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); while ((retval=getDataFromDetector())){ +#ifdef VERBOSE i++; - //#ifdef VERBOSE std::cout<< i << std::endl; - //#else - //std::cout << "-" << flush ; - //#endif +#endif dataQueue.push(retval); - std::cout<< "pushed" << std::endl; } disconnectControl(); } } #ifdef VERBOSE std::cout<< "received "<< i<< " frames" << std::endl; - //#else - // std::cout << std::endl; #endif return dataQueue.front(); // check what we return! @@ -4132,12 +4207,14 @@ int slsDetector::readAllNoWait(){ int* slsDetector::startAndReadAll(){ - + //cout << "Start and read all "<< endl; int* retval; + //#ifdef VERBOSE #ifdef VERBOSE int i=0; #endif + //#endif startAndReadAllNoWait(); //#ifdef VERBOSE // std::cout<< "started" << std::endl; @@ -4150,6 +4227,8 @@ int* slsDetector::startAndReadAll(){ //std::cout<< "-" << flush; #endif dataQueue.push(retval); + + //std::cout<< "pushed" << std::endl; } disconnectControl(); @@ -4268,10 +4347,15 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ if (t>=0) thisDetector->timerValue[index]=t; if((thisDetector->myDetectorType==GOTTHARD)|| - (thisDetector->myDetectorType==PROPIX)|| - (thisDetector->myDetectorType==JUNGFRAU)|| - (thisDetector->myDetectorType==MOENCH)) - thisDetector->timerValue[PROBES_NUMBER]=0; + (thisDetector->myDetectorType==PROPIX)|| + (thisDetector->myDetectorType==JUNGFRAU)|| + (thisDetector->myDetectorType==MOENCH)) + thisDetector->timerValue[PROBES_NUMBER]=0; + if(thisDetector->myDetectorType==JUNGFRAUCTB && index==SAMPLES_JCTB) { + getTotalNumberOfChannels(); + // thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; + } + } } else { if (t>=0) @@ -4281,6 +4365,19 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl; #endif + if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) { + setDynamicRange(); + //cout << "Changing probes: data size = " << thisDetector->dataBytes <myDetectorType==JUNGFRAUCTB) && (index==SAMPLES_JCTB)) { + setDynamicRange(); + cout << "Changing samples: data size = " << thisDetector->dataBytes <myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) { @@ -4843,7 +4940,7 @@ int slsDetector::setDynamicRange(int n){ thisDetector->dynamicRange=n; retval=thisDetector->dynamicRange; } - + //cout << "detector returned dynamic range " << retval << endl; if (ret!=FAIL && retval>0) { /* checking the number of probes to chose the data size */ @@ -4852,9 +4949,12 @@ int slsDetector::setDynamicRange(int n){ thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8; if (thisDetector->myDetectorType==JUNGFRAUCTB) { - thisDetector->nChip[X]=retval/16; - thisDetector->nChips=thisDetector->nChip[X]*thisDetector->nChip[Y]; - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*retval/8; + // thisDetector->nChip[X]=retval/16; + // thisDetector->nChips=thisDetector->nChip[X]*thisDetector->nChip[Y]; + // cout << thisDetector->nMod[X]*thisDetector->nMod[Y] << " " << thisDetector->nChans*thisDetector->nChips << " " << retval<< " "; + getTotalNumberOfChannels(); + //thisDetector->dataBytes=getTotalNumberOfChannels()*retval/8*thisDetector->timerValue[SAMPLES_JCTB]; + //cout << "data bytes: "<< thisDetector->dataBytes << endl; } if(thisDetector->myDetectorType==MYTHEN){ if (thisDetector->timerValue[PROBES_NUMBER]!=0) @@ -4907,29 +5007,40 @@ int slsDetector::setROI(int n,ROI roiLimits[]){ int ret = FAIL; //sort ascending order int temp; + for(int i=0;imyDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels(); return ret; } slsDetectorDefs::ROI* slsDetector::getROI(int &n){ - sendROI(); - n=thisDetector->nROI; - return thisDetector->roiLimits; + sendROI(-1,NULL); + n=thisDetector->nROI; + if(thisDetector->myDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels(); + return thisDetector->roiLimits; } @@ -4941,7 +5052,8 @@ int slsDetector::sendROI(int n,ROI roiLimits[]){ int retvalsize=0; ROI retval[MAX_ROIS]; int nrec=-1; - + if (roiLimits==NULL) + roiLimits=thisDetector->roiLimits; if (thisDetector->onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ @@ -4983,10 +5095,10 @@ int slsDetector::sendROI(int n,ROI roiLimits[]){ thisDetector->nROI = retvalsize; } -#ifdef VERBOSE + //#ifdef VERBOSE for(int j=0;jnROI;j++) - cout<ReceiveDataOnly(&retval,sizeof(retval)); thisDetector->roFlags=retval; + if (thisDetector->myDetectorType==JUNGFRAUCTB) { + + getTotalNumberOfChannels(); + //thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; + } } disconnectControl(); if (ret==FORCE_UPDATE) @@ -5103,49 +5220,52 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){ }; -double* slsDetector::decodeData(int *datain, double *fdata) { +double* slsDetector::decodeData(int *datain, int &nn, double *fdata) { - double *dataout; - if (fdata) { - dataout=fdata; - // printf("not allocating fdata!\n"); - } - else { - dataout=new double[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; - // printf("allocating fdata!\n"); - } - const int bytesize=8; - int ival=0; - char *ptr=(char*)datain; - char iptr; + double *dataout; + if (fdata) { + dataout=fdata; + // printf("not allocating fdata!\n"); + if (thisDetector->myDetectorType==JUNGFRAUCTB) nn=thisDetector->dataBytes/2; + } else { + if (thisDetector->myDetectorType==JUNGFRAUCTB) { + nn=thisDetector->dataBytes/2; + dataout=new double[nn]; + + // std::cout<< "nn is "<< nn << std::endl; + } else { + dataout=new double[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; + nn=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; + } + + // printf("allocating fdata!\n"); + } + const int bytesize=8; + + int ival=0; + char *ptr=(char*)datain; + char iptr; + + int nbits=thisDetector->dynamicRange; + int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; + int ipos=0, ichan=0, ibyte; + + if (thisDetector->timerValue[PROBES_NUMBER]==0) { + if (thisDetector->myDetectorType==JUNGFRAUCTB) { + + for (ichan=0; ichandynamicRange; - int nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; - int ipos=0, ichan=0, ibyte; - - if (thisDetector->timerValue[PROBES_NUMBER]==0) { - if (thisDetector->myDetectorType==JUNGFRAUCTB) { - - for (ichan=0; ichandataBytes; ibyte++) { - iptr=ptr[ibyte]&0x1; + iptr=ptr[ibyte];//&0x1; for (ipos=0; ipos<8; ipos++) { // dataout[ibyte*2+ichan]=((iptr&((0xf)<>ichan)&0xf; ival=(iptr>>(ipos))&0x1; @@ -5156,7 +5276,7 @@ double* slsDetector::decodeData(int *datain, double *fdata) { break; case 4: for (ibyte=0; ibytedataBytes; ibyte++) { - iptr=ptr[ibyte]&0xff; + iptr=ptr[ibyte]; for (ipos=0; ipos<2; ipos++) { // dataout[ibyte*2+ichan]=((iptr&((0xf)<>ichan)&0xf; ival=(iptr>>(ipos*4))&0xf; @@ -5174,36 +5294,32 @@ double* slsDetector::decodeData(int *datain, double *fdata) { case 16: for (ichan=0; ichanmyDetectorType == MYTHEN){ - for (ichan=0; ichanmyDetectorType == MYTHEN) mask=0xffffff; + for (ichan=0; ichannMod[X]*thisDetector->nChans*thisDetector->nChips; ichan++) { + for (int ichan=0; ichannMod[Y]*thisDetector->nMod[X]*thisDetector->nChans*thisDetector->nChips; ichan++) { // #ifdef VERBOSE // std::cout<< ichan << " "<< corr[ichan] << std::endl; // #endif @@ -6271,7 +6387,7 @@ int slsDetector:: writeAngularConversion(ofstream &ofs) { int slsDetector::loadImageToDetector(imageType index,string const fname){ int ret=FAIL; - short int arg[thisDetector->nChans*thisDetector->nChips]; + short int arg[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; #ifdef VERBOSE std::cout<< std::endl<< "Loading "; @@ -6352,7 +6468,7 @@ int slsDetector::getCounterBlock(short int arg[],int startACQ){ int slsDetector::writeCounterBlockFile(string const fname,int startACQ){ int ret=FAIL; - short int counterVals[thisDetector->nChans*thisDetector->nChips]; + short int counterVals[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; #ifdef VERBOSE std::cout<< std::endl<< "Reading Counter to \""<myDetectorType != JUNGFRAU){ + if(thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != JUNGFRAUCTB ){ std::cout << "Not implemented for this detector" << std::endl; return FAIL; } @@ -7571,6 +7687,7 @@ int slsDetector::startReceiver(){ #ifdef VERBOSE std::cout << "Starting Receiver " << std::endl; #endif + if (connectData() == OK){ ret=thisReceiver->executeFunction(fnum,mess); disconnectData(); @@ -7587,7 +7704,7 @@ int slsDetector::startReceiver(){ } } //let detector prepare anyway even if receiver didnt work - if((thisDetector->myDetectorType != JUNGFRAU)) + if((thisDetector->myDetectorType !=JUNGFRAU)) ret=detectorSendToReceiver(true); return ret; @@ -7774,7 +7891,54 @@ int slsDetector::resetFramesCaught(){ } - +// int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){ +// int fnum=F_READ_RECEIVER_FRAME; +// int nel=thisDetector->dataBytes/sizeof(int); +// int* retval=new int[nel]; +// int ret=FAIL; +// int n; +// char mess[MAX_STR_LENGTH]="Nothing"; +// if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { +// #ifdef VERBOSE +// std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <SendDataOnly(&fnum,sizeof(fnum)); +// dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); +// if (ret==FAIL) { +// n= dataSocket->ReceiveDataOnly(mess,sizeof(mess)); +// std::cout<< "Detector returned: " << mess << " " << n << std::endl; +// delete [] retval; +// disconnectData(); +// return NULL; +// } else { +// n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH); +// n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); +// n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex)); +// if(thisDetector->myDetectorType == EIGER) +// n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex)); +// n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); +// #ifdef VERBOSE +// std::cout<< "Received "<< n << " data bytes" << std::endl; +// #endif +// if (n!=thisDetector->dataBytes) { +// std::cout<dataBytes << std::endl; +// ret=FAIL; +// delete [] retval; +// disconnectData(); +// return NULL; } +// //jungfrau masking adcval +// if(thisDetector->myDetectorType == JUNGFRAU){ +// for(unsigned int i=0;inModsMax;}; // - int getTotalNumberOfChannels(){return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;}; + /** number of rois defined */ + int nROI; + /** list of rois */ + ROI roiLimits[MAX_ROIS]; + + /** readout flags */ + readOutFlags roFlags; - int getTotalNumberOfChannels(dimension d){return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nMod[d];}; - int getMaxNumberOfChannels(){return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax;}; + int getTotalNumberOfChannels(); + //{return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;}; - int getMaxNumberOfChannels(dimension d){return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d];}; + int getTotalNumberOfChannels(dimension d); + //{return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nMod[d];}; + + int getMaxNumberOfChannels();//{return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax;}; + + int getMaxNumberOfChannels(dimension d);//{return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d];}; /** returns the enable if data will be flipped across x or y axis * \param d axis across which data is flipped @@ -1297,7 +1308,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion { \param datain data from the detector \returns pointer to a double array with a data per channel */ - double* decodeData(int *datain, double *fdata=NULL); + double* decodeData(int *datain, int &nn, double *fdata=NULL); @@ -1625,6 +1636,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int resetFramesCaught(); + /** Locks/Unlocks the connection to the receiver /param lock sets (1), usets (0), gets (-1) the lock /returns lock status of the receiver diff --git a/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp b/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp index 5d0b77621..a9c3616a8 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp @@ -146,6 +146,7 @@ int slsDetectorActions::getActionMode(int iaction){ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *values, string par, int precision) { if (iscan>=0 && iscansetDAC(-1,dac,mode)); #endif if(mode) - strcat(answer,"mV"); + strcat(answer," mV"); return string(answer); } @@ -4021,7 +4050,7 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) { return string("cannot set ")+cmd; if (sscanf(args[0],"adc:%d",&idac)==1) { - printf("chiptestboard!\n"); + // printf("chiptestboard!\n"); adc=(dacIndex)(idac+1000); } else if (cmd=="temp_adc") adc=TEMPERATURE_ADC; @@ -4147,6 +4176,8 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) { index=PROBES_NUMBER; else if (cmd=="measurements") index=MEASUREMENTS_NUMBER; + else if (cmd=="samples") + index=SAMPLES_JCTB; else return string("could not decode timer ")+cmd; @@ -4200,6 +4231,7 @@ string slsDetectorCommand::helpTimer(int narg, char *args[], int action) { os << "frames t \t sets the number of frames per cycle (e.g. after each trigger)" << std::endl; os << "cycles t \t sets the number of cycles (e.g. number of triggers)" << std::endl; os << "probes t \t sets the number of probes to accumulate (max 3! cycles should be set to 1, frames to the number of pump-probe events)" << std::endl; + os << "samples t \t sets the number of samples expected from the jctb" << std::endl; os << std::endl; @@ -4213,6 +4245,8 @@ string slsDetectorCommand::helpTimer(int narg, char *args[], int action) { os << "frames \t gets the number of frames per cycle (e.g. after each trigger)" << std::endl; os << "cycles \t gets the number of cycles (e.g. number of triggers)" << std::endl; os << "probes \t gets the number of probes to accumulate" << std::endl; + os << "samples t \t gets the number of samples expected from the jctb" << std::endl; + os << std::endl; } @@ -4348,9 +4382,16 @@ string slsDetectorCommand::cmdSpeed(int narg, char *args[], int action) { index=ADC_CLOCK; else if (cmd=="adcphase") { index=ADC_PHASE; - t=100000; + t=100000; } else if (cmd=="adcpipeline") index=ADC_PIPELINE; + else if (cmd=="dbitclk") + index=DBIT_CLOCK; + else if (cmd=="dbitphase") { + index=DBIT_PHASE; + t=100000; + } else if (cmd=="dbitpipeline") + index=DBIT_PIPELINE; else return string("could not decode speed variable ")+cmd; @@ -4425,50 +4466,59 @@ string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action) { readOutFlags flag=GET_READOUT_FLAGS; - if (action==PUT_ACTION) { - string sval=string(args[1]); - if (sval=="none") - flag=NORMAL_READOUT; - else if (sval=="storeinram") - flag=STORE_IN_RAM; - else if (sval=="tot") - flag=TOT_MODE; - else if (sval=="continous") - flag=CONTINOUS_RO; - else if (sval=="parallel") - flag=PARALLEL; - else if (sval=="nonparallel") - flag=NONPARALLEL; - else if (sval=="safe") - flag=SAFE; - else - return string("could not scan flag ")+string(args[1]); - } - + if (action==PUT_ACTION) { + string sval=string(args[1]); + if (sval=="none") + flag=NORMAL_READOUT; + else if (sval=="storeinram") + flag=STORE_IN_RAM; + else if (sval=="tot") + flag=TOT_MODE; + else if (sval=="continous") + flag=CONTINOUS_RO; + else if (sval=="parallel") + flag=PARALLEL; + else if (sval=="nonparallel") + flag=NONPARALLEL; + else if (sval=="safe") + flag=SAFE; + else if (sval=="digital") + flag=DIGITAL_ONLY; + else if (sval=="analog_digital") + flag=ANALOG_AND_DIGITAL; + else + return string("could not scan flag ")+string(args[1]); + } + myDet->setOnline(ONLINE_FLAG); + retval = myDet->setReadOutFlags(flag); - retval = myDet->setReadOutFlags(flag); + // cout << hex << flag << " " << retval << endl; - if(retval == NORMAL_READOUT) - return string("none"); + if(retval == NORMAL_READOUT) + return string("none"); - if(retval & STORE_IN_RAM) - strcat(answer,"storeinram "); - if(retval & TOT_MODE) - strcat(answer,"tot "); - if(retval & CONTINOUS_RO) - strcat(answer,"continous "); - if(retval & PARALLEL) - strcat(answer,"parallel "); - if(retval & NONPARALLEL) - strcat(answer,"nonparallel "); - if(retval & SAFE) - strcat(answer,"safe "); - if(strlen(answer)) - return string(answer); + if(retval & STORE_IN_RAM) + strcat(answer,"storeinram "); + if(retval & TOT_MODE) + strcat(answer,"tot "); + if(retval & CONTINOUS_RO) + strcat(answer,"continous "); + if(retval & PARALLEL) + strcat(answer,"parallel "); + if(retval & NONPARALLEL) + strcat(answer,"nonparallel "); + if(retval & SAFE) + strcat(answer,"safe "); + if (retval & DIGITAL_ONLY) + strcat(answer,"digital " ); + if (retval & ANALOG_AND_DIGITAL) + strcat(answer,"analog_digital "); + if(strlen(answer)) + return string(answer); - return string("unknown"); + return string("unknown"); } else if (cmd=="extsig") { externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG; @@ -4487,10 +4537,8 @@ string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action) { return myDet->externalSignalType(myDet->setExternalSignalFlags(flag,is)); - } - - else if (cmd=="programfpga") { + } else if (cmd=="programfpga") { if (action==GET_ACTION) return string("cannot get"); if(strstr(args[1],".pof")==NULL) @@ -4543,14 +4591,15 @@ string slsDetectorCommand::helpAdvanced(int narg, char *args[], int action) { if (action==PUT_ACTION || action==HELP_ACTION) { os << "extsig:i mode \t sets the mode of the external signal i. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl; - os << "flags mode \t sets the readout flags to mode. can be none, storeinram, tot, continous, parallel, nonparallel, safe, unknown" << std::endl; + os << "flags mode \t sets the readout flags to mode. can be none, storeinram, tot, continous, parallel, nonparallel, safe, digital, analog_digital, unknown" << std::endl; + os << "programfpga f \t programs the fpga with file f (with .pof extension)." << std::endl; os << "resetfpga f \t resets fpga, f can be any value" << std::endl; } if (action==GET_ACTION || action==HELP_ACTION) { os << "extsig:i \t gets the mode of the external signal i. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl; - os << "flags \t gets the readout flags. can be none, storeinram, tot, continous, parallel, nonparallel, safe, unknown" << std::endl; + os << "flags \t gets the readout flags. can be none, storeinram, tot, continous, parallel, nonparallel, safe, digital, analog_digital, unknown" << std::endl; } return os.str(); @@ -5261,7 +5310,26 @@ string slsDetectorCommand::cmdPattern(int narg, char *args[], int action) { os << hex << myDet->readRegister(67) << dec; + } else if (cmd=="dut_clk") { + if (action==PUT_ACTION) { + + if (sscanf(args[1],"%x",&addr)) + ; + else + return string("Could not scan dut_clk reg ")+string(args[1]); + + + myDet->writeRegister(123,addr); //0x7b + } + + + + os << hex << myDet->readRegister(123) << dec; //0x7b } else if (cmd=="adcdisable") { + + int nroi=0; + ROI roiLimits[MAX_ROIS]; + if (action==PUT_ACTION) { if (sscanf(args[1],"%x",&addr)) @@ -5269,19 +5337,69 @@ string slsDetectorCommand::cmdPattern(int narg, char *args[], int action) { else return string("Could not scan adcdisable reg ")+string(args[1]); - - myDet->writeRegister(94,addr); + /******USE ROI?!?!?!?*********/ + // roiLimits[i].xmin;roiLimits[i].xmax;roiLimits[i].ymin;roiLimits[i].ymin;roiLimits[i].ymax + //int mask=1; + int ii=0; + while (ii<32) { + nroi++; + roiLimits[nroi-1].xmin=ii; + roiLimits[nroi-1].ymin=0; + roiLimits[nroi-1].ymax=0; + while ((addr&(1<=32) + break; + } + if (ii>=32) { + break; + cout << "ROI "<< nroi << " xmin "<=32) + break; + } + roiLimits[nroi-1].xmax=ii-1; + if (ii>=32) { + cout << "ROI "<< nroi << " xmin "<setROI(nroi-1,roiLimits); + // myDet->writeRegister(94,addr); + // myDet->writeRegister(120,addr); + } + ROI *aa=myDet->getROI(nroi); + + int reg=0xffffffff; + if (nroi<1) + reg=0; + else { + for (int iroi=0; iroixmin<< " xmax "<< (aa+iroi)->xmax<< endl; + for (int ich=(aa+iroi)->xmin; ich<=(aa+iroi)->xmax; ich++) { + reg&=~(1<readRegister(94) << dec; + //os <<" "<< hex << myDet->readRegister(120) << dec; } -else return helpPattern(narg, args, action); + else return helpPattern(narg, args, action); diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 0e6d5e763..b9fde9e1a 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -151,7 +151,7 @@ int slsDetectorUtils::acquire(int delflag){ } if(receiver){ - pthread_mutex_lock(&mg); + pthread_mutex_lock(&mg); //cout << "lock"<< endl; if(getReceiverStatus()!=IDLE) stopReceiver(); //multi detectors shouldnt have different receiver read frequencies enabled/disabled @@ -161,7 +161,7 @@ int slsDetectorUtils::acquire(int delflag){ } if(setReceiverOnline()==OFFLINE_FLAG) *stoppedFlag=1; - pthread_mutex_unlock(&mg); + pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; } @@ -173,9 +173,9 @@ int slsDetectorUtils::acquire(int delflag){ //resets frames caught in receiver if(receiver){ - pthread_mutex_lock(&mg); - resetFramesCaught(); - pthread_mutex_unlock(&mg); + pthread_mutex_lock(&mg); //cout << "lock"<< endl; + resetFramesCaught(); + pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; } @@ -269,7 +269,7 @@ int slsDetectorUtils::acquire(int delflag){ aclog->addStep(getCurrentPosition(), getCurrentFileName()); if (eclog) - eclog->addStep(setDAC(-1,THRESHOLD,0), getCurrentFileName()); + eclog->addStep(setDAC(-1,THRESHOLD,0), getCurrentFileName()); if (*correctionMask&(1<< I0_NORMALIZATION)) { @@ -280,7 +280,7 @@ int slsDetectorUtils::acquire(int delflag){ setCurrentFrameIndex(0); if(receiver) - pthread_mutex_lock(&mg); + pthread_mutex_lock(&mg); //cout << "lock"<< endl; if (multiframe>1) setFrameIndex(0); else @@ -288,30 +288,33 @@ int slsDetectorUtils::acquire(int delflag){ if(receiver){ - pthread_mutex_unlock(&mg); + pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_lock(&mp); createFileName(); pthread_mutex_unlock(&mp); //send receiver file name - pthread_mutex_lock(&mg); + pthread_mutex_lock(&mg); //cout << "lock"<< endl; setFileName(fileIO::getFileName()); + //start receiver if(startReceiver() == FAIL) { + cout << "Start receiver failed " << endl; stopReceiver(); *stoppedFlag=1; - pthread_mutex_unlock(&mg); + pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; break; } - pthread_mutex_unlock(&mg); + cout << "Receiver started " << endl; + pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; } -#ifdef VERBOSE + #ifdef VERBOSE cout << "Acquiring " << endl; -#endif + #endif startAndReadAll(); -#ifdef VERBOSE - cout << "finished " << endl; + cout << "detector finished " << endl; + #ifdef VERBOSE cout << "returned! " << endl; -#endif + #endif @@ -341,17 +344,20 @@ int slsDetectorUtils::acquire(int delflag){ } else break; - - pthread_mutex_lock(&mg); + while (dataQueueSize()) usleep(100000); + // cout << "mglock " << endl;; + pthread_mutex_lock(&mg); //cout << "lock"<< endl; + // cout << "done " << endl;; //offline if(setReceiverOnline()==OFFLINE_FLAG){ - if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){ + if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU)|| (getDetectorsType()==JUNGFRAUCTB) ){ if((*correctionMask)&(1<>17&1) ; + // cout << endl; + + + fdata=decodeData(myData,nn, fdata); -#ifdef VERBOSE - cout << "decode"<< endl; -#endif + //#ifdef VERBOSE + // cout << "decode 1"<< endl; + //#endif // } else // fdata=NULL; - if (rawDataReady) { - #ifdef VERBOSE +#ifdef VERBOSE + cout << "decoded data size is "<0) { /** Pop data queue */ - //#ifdef VERBOSE + #ifdef VERBOSE cout << "data found"<< endl< finalDataQueue; - /** data queue size */ int queuesize; - + /** queue mutex */ + sem_t sem_queue; + /** set when detector finishes acquiring */ + int acquiringDone; /**