diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index e2f10656f..3657e2b6f 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 */ }; /** diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index c8e261617..4d8ba0cae 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -111,8 +111,6 @@ enum { F_POWER_CHIP, /**< power chip */ /* Always append functions hereafter!!! */ - - /* Always append functions before!!! */ TOO_MANY_FUNCTIONS_DEFINED=128 //you should get a compilation error if there are already so many functions defined. It conflicts with sls_receiver_funcs.h diff --git a/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.c b/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.c index 2dea73656..dcaa581be 100755 --- a/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/jctbDetectorServer/firmware_funcs.c @@ -120,23 +120,23 @@ int withGotthard = 0; * why is this used anywhere instead of macro*/ int nChans=NCHAN; int nChips=NCHIP; -int nDacs=NDAC; -int nAdcs=NADC; +//int nDacs;//=NDAC; +//int nAdcs=NADC; extern enum detectorType myDetectorType; /** for jungfrau reinitializing macro later in server_funcs.c in initDetector*/ -extern int N_CHAN; -extern int N_CHIP; -extern int N_DAC; -extern int N_ADC; -extern int N_CHANS; + extern int N_CHAN; + extern int N_CHIP; + extern int N_DAC; + extern int N_ADC; + extern int N_CHANS; int analogEnable=1; int digitalEnable=0; - +int vLimit=-100; @@ -1267,10 +1267,8 @@ u_int32_t testRAM(void) { int getNModBoard() { -if(myDetectorType == JUNGFRAU) - return 1; -else - return 32;//nModX; + + return 1; } int setNMod(int n) { @@ -1489,7 +1487,7 @@ int setROI(int nroi,ROI* arg,int *retvalsize, int *ret) { // 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) { @@ -1691,10 +1689,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; @@ -1705,35 +1703,44 @@ 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; + + if (val>=0) { + + offw=DAC_REG; - ddx=8; csdx=10; cdx=9; - codata=((dacvalue)&0xff); + 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; @@ -1975,7 +1982,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; } @@ -2158,7 +2165,7 @@ u_int32_t fifo_full(void) u_int16_t* fifo_read_event(int ns) { - int i=0, j, mask=1; + int i=0, mask=1;//j, volatile u_int16_t a; bus_w16(DUMMY_REG,0); if (ns==0) { @@ -2213,14 +2220,16 @@ u_int16_t* fifo_read_event(int ns) } } if (digitalEnable) { - printf("+"); + // 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 */ @@ -2544,16 +2553,16 @@ int writeADC(int addr, int val) { int prepareSlowADCSeq() { - u_int16_t vv=0x3c40; + // u_int16_t vv=0x3c40; u_int16_t codata=( 1<<13) | (7<<10) | (7<<7) | (1<<6) | (0<<3) | (2<<1) | 1; u_int32_t valw; - int i, obit, ibit; + int obit, ibit; int cnv_bit=16, sdi_bit=17, sck_bit=18; - int oval=0; + // int oval=0; printf("Codata is %04x\n",codata); @@ -2601,25 +2610,25 @@ int prepareSlowADCSeq() { bus_w(ADC_WRITE_REG,(valw)); usleep(20); - + return 0; } int prepareSlowADC(int ichan) { - u_int16_t vv=0x3c40; + // u_int16_t vv=0x3c40; // u_int16_t codata=( 1<<13) | (7<<10) | (7<<7) | (1<<6) | (0<<3) | (2<<1) | 1; u_int16_t codata=(1<<13) | (7<<10) | (ichan<<7) | (1<<6) | (0<<3) | (0<<1) | 1; //read single channel if (ichan<0) codata=( 1<<13) | (3<<10) | (7<7) | (1<<6) | (0<<3) | (0<<1) | 1; u_int32_t valw; - int i, obit, ibit; + int obit, ibit; int cnv_bit=16, sdi_bit=17, sck_bit=18; - int oval=0; + // int oval=0; printf("Codata is %04x\n",codata); @@ -2667,7 +2676,7 @@ int prepareSlowADC(int ichan) { bus_w(ADC_WRITE_REG,(valw)); usleep(20); - + return 0; } @@ -2677,13 +2686,13 @@ int prepareSlowADC(int ichan) { int readSlowADC(int ichan) { - u_int16_t vv=0x3c40; + // u_int16_t vv=0x3c40; // u_int16_t codata=( 1<<13) | (7<<10) | (ichan<<7) | (1<<6) | (0<<3) | (0<<1) | 1; //read single channel u_int32_t valw; - int i, obit, ibit; + int i, obit; - int cnv_bit=16, sdi_bit=17, sck_bit=18; + int cnv_bit=16, sck_bit=18; int oval=0; @@ -3114,57 +3123,57 @@ int setSynchronization(int s) { int readCounterBlock(int startACQ, short int CounterVals[]){ - //char *counterVals=NULL; - //counterVals=realloc(counterVals,dataBytes); +/* //char *counterVals=NULL; */ +/* //counterVals=realloc(counterVals,dataBytes); */ - u_int32_t val; - volatile u_int16_t *ptr; +/* u_int32_t val; */ +/* volatile u_int16_t *ptr; */ - u_int32_t address = COUNTER_MEMORY_REG; - ptr=(u_int16_t*)(CSP0BASE+address*2); +/* u_int32_t address = COUNTER_MEMORY_REG; */ +/* ptr=(u_int16_t*)(CSP0BASE+address*2); */ - if (runBusy()) { - if(stopStateMachine()==FAIL) - return FAIL; - //waiting for the last frame read to be done - while(runBusy()) usleep(500); -#ifdef VERBOSE - printf("State machine stopped\n"); -#endif - } +/* if (runBusy()) { */ +/* if(stopStateMachine()==FAIL) */ +/* return FAIL; */ +/* //waiting for the last frame read to be done */ +/* while(runBusy()) usleep(500); */ +/* #ifdef VERBOSE */ +/* printf("State machine stopped\n"); */ +/* #endif */ +/* } */ - val=bus_r(MULTI_PURPOSE_REG); -#ifdef VERBOSE - printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); -#endif +/* val=bus_r(MULTI_PURPOSE_REG); */ +/* #ifdef VERBOSE */ +/* printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */ +/* #endif */ - memcpy(CounterVals,ptr,dataBytes); /*warning: passing argument 2 of ‘memcpy’ discards qualifiers from pointer target type*/ -#ifdef VERBOSE - int i; - printf("Copied counter memory block with size of %d bytes..\n",dataBytes); - for(i=0;i<6;i++) - printf("%d: %d\t",i,CounterVals[i]); -#endif +/* memcpy(CounterVals,ptr,dataBytes); /\*warning: passing argument 2 of ‘memcpy’ discards qualifiers from pointer target type*\/ */ +/* #ifdef VERBOSE */ +/* int i; */ +/* printf("Copied counter memory block with size of %d bytes..\n",dataBytes); */ +/* for(i=0;i<6;i++) */ +/* printf("%d: %d\t",i,CounterVals[i]); */ +/* #endif */ - bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT)); -#ifdef VERBOSE - printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); -#endif +/* bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT)); */ +/* #ifdef VERBOSE */ +/* printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */ +/* #endif */ - if(startACQ==1){ - startStateMachine(); - if(runBusy()) - printf("State machine RUNNING\n"); - else - printf("State machine IDLE\n"); - } +/* if(startACQ==1){ */ +/* startStateMachine(); */ +/* if(runBusy()) */ +/* printf("State machine RUNNING\n"); */ +/* else */ +/* printf("State machine IDLE\n"); */ +/* } */ -/* if(sizeof(CounterVals)<=0){ - printf("ERROR:size of counterVals=%d\n",(int)sizeof(CounterVals)); - return FAIL; - }*/ +/* /\* if(sizeof(CounterVals)<=0){ */ +/* printf("ERROR:size of counterVals=%d\n",(int)sizeof(CounterVals)); */ +/* return FAIL; */ +/* }*\/ */ return OK; @@ -3174,67 +3183,67 @@ int readCounterBlock(int startACQ, short int CounterVals[]){ int resetCounterBlock(int startACQ){ + int ret = OK; - char *counterVals=NULL; - counterVals=realloc(counterVals,dataBytes); +/* char *counterVals=NULL; */ +/* counterVals=realloc(counterVals,dataBytes); */ - int ret = OK; - u_int32_t val; - volatile u_int16_t *ptr; +/* u_int32_t val; */ +/* volatile u_int16_t *ptr; */ - u_int32_t address = COUNTER_MEMORY_REG; - ptr=(u_int16_t*)(CSP0BASE+address*2); +/* u_int32_t address = COUNTER_MEMORY_REG; */ +/* ptr=(u_int16_t*)(CSP0BASE+address*2); */ - if (runBusy()) { - if(stopStateMachine()==FAIL) - return FAIL; - //waiting for the last frame read to be done - while(runBusy()) usleep(500); -#ifdef VERBOSE - printf("State machine stopped\n"); -#endif - } +/* if (runBusy()) { */ +/* if(stopStateMachine()==FAIL) */ +/* return FAIL; */ +/* //waiting for the last frame read to be done */ +/* while(runBusy()) usleep(500); */ +/* #ifdef VERBOSE */ +/* printf("State machine stopped\n"); */ +/* #endif */ +/* } */ - val=bus_r(MULTI_PURPOSE_REG); -#ifdef VERBOSE - printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); -#endif +/* val=bus_r(MULTI_PURPOSE_REG); */ +/* #ifdef VERBOSE */ +/* printf("Value of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */ +/* #endif */ - bus_w(MULTI_PURPOSE_REG,(val|RESET_COUNTER_BIT)); -#ifdef VERBOSE - printf("Setting bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); -#endif +/* bus_w(MULTI_PURPOSE_REG,(val|RESET_COUNTER_BIT)); */ +/* #ifdef VERBOSE */ +/* printf("Setting bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */ +/* #endif */ - memcpy(counterVals,ptr,dataBytes);/*warning: passing argument 2 of ‘memcpy’ discards qualifiers from pointer target type*/ -#ifdef VERBOSE - int i; - printf("Copied counter memory block with size of %d bytes..\n",(int)sizeof(counterVals)); - for(i=0;i<6;i=i+2) - printf("%d: %d\t",i,*(counterVals+i)); -#endif +/* memcpy(counterVals,ptr,dataBytes);/\*warning: passing argument 2 of ‘memcpy’ discards qualifiers from pointer target type*\/ */ +/* #ifdef VERBOSE */ +/* int i; */ +/* printf("Copied counter memory block with size of %d bytes..\n",(int)sizeof(counterVals)); */ +/* for(i=0;i<6;i=i+2) */ +/* printf("%d: %d\t",i,*(counterVals+i)); */ +/* #endif */ - bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT)); -#ifdef VERBOSE - printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); -#endif +/* bus_w(MULTI_PURPOSE_REG,(val&~RESET_COUNTER_BIT)); */ +/* #ifdef VERBOSE */ +/* printf("\nClearing bit 2 of multipurpose reg:%d\n",bus_r(MULTI_PURPOSE_REG)); */ +/* #endif */ - if(startACQ==1){ - startStateMachine(); - if(runBusy()) - printf("State machine RUNNING\n"); - else - printf("State machine IDLE\n"); - } +/* if(startACQ==1){ */ +/* startStateMachine(); */ +/* if(runBusy()) */ +/* printf("State machine RUNNING\n"); */ +/* else */ +/* printf("State machine IDLE\n"); */ +/* } */ - if(sizeof(counterVals)<=0){ - printf("ERROR:size of counterVals=%d\n",(int)sizeof(counterVals)); - ret = FAIL; - } +/* if(sizeof(counterVals)<=0){ */ +/* printf("ERROR:size of counterVals=%d\n",(int)sizeof(counterVals)); */ +/* ret = FAIL; */ +/* } */ return ret; @@ -3401,7 +3410,8 @@ uint64_t writePatternWord(int addr, uint64_t word) { return readPatternWord(addr); } uint64_t writePatternIOControl(uint64_t word) { - if (word!=0xffffffffffffffff) { /*warning: integer constant is too large for ‘long’ type*/ + uint64_t c=0xffffffffffffffffULL; + if (word!=c) { /*warning: integer constant is too large for ‘long’ type*/ // printf("%llx %llx %lld",get64BitReg(PATTERN_IOCTRL_REG_LSB,PATTERN_IOCTRL_REG_MSB),word); set64BitReg(word,PATTERN_IOCTRL_REG_LSB,PATTERN_IOCTRL_REG_MSB); // printf("************ write IOCTRL (%x)\n",PATTERN_IOCTRL_REG_MSB); @@ -3410,7 +3420,8 @@ uint64_t writePatternIOControl(uint64_t word) { } uint64_t writePatternClkControl(uint64_t word) { - if (word!=0xffffffffffffffff) set64BitReg(word,PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB);/*warning: integer constant is too large for ‘long’ type*/ + uint64_t c=0xffffffffffffffffULL; + if (word!=c) set64BitReg(word,PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB);/*warning: integer constant is too large for ‘long’ type*/ return get64BitReg(PATTERN_IOCLKCTRL_REG_LSB,PATTERN_IOCLKCTRL_REG_MSB); } @@ -3555,7 +3566,7 @@ void initDac(int dacnum) { printf("data bit=%d, clkbit=%d, csbit=%d",ddx,cdx,csdx); - codata=((((0x6)<<4)+((0xf))<<16)+((0x0<<4)&0xfff0)); /*warning: suggest parentheses around + or - inside shift*/ + codata=(((0x6)<<4)|((0xf)<<16)|((0x0<<4)&0xfff0)); valw=0xffff; bus_w(offw,(valw)); // start point 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) { @@ -3746,12 +3767,16 @@ int setPower(int ind, int val) { retval1=retval; } else retval1=0; - } else { + } else if (dacindex>=0) { if (retval>=0) { retval1=2700-(retval*1000)/4095; - printf("Vchip id %d mV\n",vmax); + printf("Vchip is %d mV\n",vmax); } else retval1=-1; + } else { + printf("Get vlimit %d\n",vLimit); + retval=vLimit; + retval1=vLimit; } /* switch (ind) { */ @@ -3781,15 +3806,17 @@ int setPower(int ind, int val) { int powerChip(int arg) { //#ifndef CTB - u_int32_t preg=bus_r(POWER_ON_REG); - 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); + + 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; @@ -3799,10 +3826,50 @@ int powerChip(int arg) { +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)); + /* for (i=1;i<25;i++) { */ + /* // printf("%d",((codata>>(24-i)))&0x1); */ + /* valw=(valw&(~(0x1<>(24-i))&0x1)<>(24-i))&0x1)); */ - valw=((valw&(~(0x1<dacs=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; } @@ -118,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 - - prepareSlowADCSeq(); - // 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); @@ -221,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); @@ -238,13 +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; } @@ -1049,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)); @@ -1085,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: @@ -1130,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 (inddataBytes << endl; for (int id=0; idnumberOfDetectors; id++) { @@ -2251,11 +2251,11 @@ double* multiSlsDetector::decodeData(int *datain, int &nn, double *fdata) { dataout=fdata; else { if (detectors[0]->getDetectorsType()==JUNGFRAUCTB) { - dataout=new double[thisMultiDetector->dataBytes/2]; nn=thisMultiDetector->dataBytes/2; + dataout=new double[nn]; } else { - dataout=new double[thisMultiDetector->numberOfChannels]; nn=thisMultiDetector->numberOfChannels; + dataout=new double[nn]; } } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 4d013a141..db2b3cbe6 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -801,7 +801,7 @@ int slsDetector::initializeDetectorSize(detectorType type) { //update?!?!?!? if(thisDetector->myDetectorType==JUNGFRAUCTB) { - cout << "here2" << endl; + // cout << "here2" << endl; getTotalNumberOfChannels(); //thisDetector->nChan[X]=32; //thisDetector->nChans=thisDetector->nChan[X]*thisDetector->nChan[Y]; @@ -1703,8 +1703,9 @@ int slsDetector::getTotalNumberOfChannels() { } thisDetector->nChans=thisDetector->nChan[X]; thisDetector->dataBytes=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods*2*thisDetector->timerValue[SAMPLES_JCTB]; - cout << "Total number of channels is "<< thisDetector->nChans*thisDetector->nChips*thisDetector->nMods << " data bytes is " << thisDetector->dataBytes << endl; - } + } 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; }; @@ -3928,9 +3929,9 @@ int* slsDetector::getDataFromDetector(int *retval){ n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); - //#ifdef VERBOSE +#ifdef VERBOSE std::cout<< "Received "<< n << " data bytes" << std::endl; - //#endif +#endif if (n!=thisDetector->dataBytes) { std::cout<< "wrong data size received from detector: received " << n << " but expected " << thisDetector->dataBytes << std::endl; thisDetector->stoppedFlag=1; @@ -3940,8 +3941,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 << endl; return retval; }; @@ -3956,8 +3962,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) { @@ -3965,23 +3971,18 @@ 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 +#ifdef VERBOSE std::cout<< "received "<< i<< " frames" << std::endl; - //#else - // std::cout << std::endl; - #endif +#endif return dataQueue.front(); // check what we return! }; @@ -4019,19 +4020,21 @@ int* slsDetector::startAndReadAll(){ int* retval; //#ifdef VERBOSE +#ifdef VERBOSE int i=0; +#endif //#endif startAndReadAllNoWait(); //#ifdef VERBOSE // std::cout<< "started" << std::endl; //#endif while ((retval=getDataFromDetector())){ - #ifdef VERBOSE +#ifdef VERBOSE i++; std::cout<< i << std::endl; //#else //std::cout<< "-" << flush; - #endif +#endif dataQueue.push(retval); //std::cout<< "pushed" << std::endl; @@ -5029,14 +5032,17 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) { - double *dataout; - if (fdata) { - dataout=fdata; - // printf("not allocating fdata!\n"); - } else { + double *dataout; + if (fdata) { + dataout=fdata; + // printf("not allocating fdata!\n"); + if (thisDetector->myDetectorType==JUNGFRAUCTB) nn=thisDetector->dataBytes/2; + } else { if (thisDetector->myDetectorType==JUNGFRAUCTB) { - dataout=new double[thisDetector->dataBytes/2]; 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; @@ -5044,30 +5050,31 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) { // 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; ichandataBytes/2; ichan++) { + 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; 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; @@ -5078,7 +5085,7 @@ double* slsDetector::decodeData(int *datain, int &nn, 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; @@ -5096,36 +5103,32 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) { case 16: for (ichan=0; ichanmyDetectorType == MYTHEN){ - for (ichan=0; ichanmyDetectorType == MYTHEN) mask=0xffffff; + for (ichan=0; ichansetDAC(-1,dac,mode)); #endif if(mode) - strcat(answer,"mV"); + strcat(answer," mV"); return string(answer); } @@ -4007,7 +4013,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; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index fca29fac9..b9fde9e1a 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -174,8 +174,8 @@ int slsDetectorUtils::acquire(int delflag){ //resets frames caught in receiver if(receiver){ pthread_mutex_lock(&mg); //cout << "lock"<< endl; - resetFramesCaught(); - pthread_mutex_unlock(&mg);//cout << "unlock"<< 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)) { @@ -344,7 +344,7 @@ int slsDetectorUtils::acquire(int delflag){ } else break; - + while (dataQueueSize()) usleep(100000); // cout << "mglock " << endl;; pthread_mutex_lock(&mg); //cout << "lock"<< endl; // cout << "done " << endl;; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 9bca1e424..a3d8720e7 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -101,6 +101,13 @@ void postProcessing::processFrame(int *myData, int delflag, int jctb) { // cout << "decode 0"<< endl; // if (getDetectorsType()==MYTHEN) { + + + // for (int ib=0; ib<1000; ib++) + // cout << ((*(((u_int64_t*)myData)+ib))>>17&1) ; + // cout << endl; + + fdata=decodeData(myData,nn, fdata); //#ifdef VERBOSE