From 9ac08e5e764db9b16310e115a466187d1cbfa328 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Fri, 30 Jan 2015 12:58:53 +0100 Subject: [PATCH 1/2] supports frames with many samples for jctb - obtained by faking number of chips in case of many samples --- .../commonFiles/sls_detector_defs.h | 3 +- .../jungfrauDetectorServer/firmware_funcs.c | 541 +++++++++--------- .../jungfrauDetectorServer/firmware_funcs.h | 2 + .../jungfrauDetectorServer/registers_m.h | 11 + .../jungfrauDetectorServer/server_funcs.c | 121 ++-- .../slsDetector/slsDetector.cpp | 63 +- .../slsDetector/slsDetectorActions.h | 10 +- .../slsDetector/slsDetectorBase.h | 6 + .../slsDetector/slsDetectorCommand.cpp | 9 + .../slsDetector/slsDetectorUtils.h | 7 +- .../slsDetectorAnalysis/fileIO.cpp | 14 +- .../slsDetectorAnalysis/fileIO.h | 2 + .../slsDetectorAnalysis/fileIOStatic.h | 1 + .../slsDetectorAnalysis/postProcessing.cpp | 118 ++-- .../slsDetectorAnalysis/postProcessing.h | 3 +- 15 files changed, 488 insertions(+), 423 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 5207da62c..649436162 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -401,7 +401,8 @@ enum speedVariable { PHASE_SHIFT, /**< adds phase shift */ OVERSAMPLING, /**< oversampling for analog detectors */ ADC_CLOCK, /**< adc clock divider */ - ADC_PHASE /**< adc clock phase */ + ADC_PHASE, /**< adc clock phase */ + ADC_PIPELINE /**< adc pipeline */ }; diff --git a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c index 18f74c469..c2bb7bce5 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c @@ -1,4 +1,5 @@ //#define TESTADC +#define TESTADC1 #include "server_defs.h" @@ -34,7 +35,10 @@ const int nModY=1; int nModBoard; int nModX=NMAXMOD; int dynamicRange=16;//32; +int nSamples=1; + int dataBytes=NMAXMOD*NCHIP*NCHAN*2; + int storeInRAM=0; int ROI_flag=0; int adcConfigured=-1; @@ -50,7 +54,8 @@ int phase_shift=0;//DEFAULT_PHASE_SHIFT; int ipPacketSize=DEFAULT_IP_PACKETSIZE; int udpPacketSize=DEFAULT_UDP_PACKETSIZE; -u_int32_t clkDivider[2]={160,32}; +u_int32_t clkDivider[2]={32,16}; +int32_t clkPhase[2]={0,0}; int ififostart, ififostop, ififostep, ififo; @@ -307,28 +312,28 @@ int cleanFifo(){ int setDAQRegister() { - u_int32_t addr, reg, val; - addr=DAQ_REG; +/* u_int32_t addr, reg, val; */ +/* addr=DAQ_REG; */ - //depended on adcval - int packetlength=0x7f; - if(!ROI_flag) packetlength=0x13f; +/* //depended on adcval */ +/* int packetlength=0x7f; */ +/* if(!ROI_flag) packetlength=0x13f; */ - //depended on pcb rev - int tokenTiming = TOKEN_TIMING_REV2; - if((bus_r(PCB_REV_REG)&BOARD_REVISION_MASK)==1) - tokenTiming= TOKEN_TIMING_REV1; +/* //depended on pcb rev */ +/* int tokenTiming = TOKEN_TIMING_REV2; */ +/* if((bus_r(PCB_REV_REG)&BOARD_REVISION_MASK)==1) */ +/* tokenTiming= TOKEN_TIMING_REV1; */ - val = (packetlength<<16) + tokenTiming; - //val=34+(42<<8)+(packetlength<<16); +/* val = (packetlength<<16) + tokenTiming; */ +/* //val=34+(42<<8)+(packetlength<<16); */ - reg=bus_r(addr); - bus_w(addr,val); - reg=bus_r(addr); -//#ifdef VERBOSE - printf("DAQ reg 0x15:%x\n",reg); -//#endif +/* reg=bus_r(addr); */ +/* bus_w(addr,val); */ +/* reg=bus_r(addr); */ +/* //#ifdef VERBOSE */ +/* printf("DAQ reg 0x15:%x\n",reg); */ +/* //#endif */ return OK; } @@ -369,27 +374,30 @@ u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val, int trig) { + + printf("*********** pll busy: %08x\n",bus_r(STATUS_REG)&PLL_RECONFIG_BUSY); + bus_w(PLL_PARAM_REG,val); - printf("param: %x\n",val); + // printf("param: %x\n",val); vv=reg<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); + + } else { + // if (mode==1) { + // } else { + printf("phase in %d\n",clkPhase[0]); + + if (clkPhase[0]>0) { + inv=0; + phase=clkPhase[0]; + } else { + inv=1; + phase=-1*clkPhase[0]; + } + + printf("phase out %d %08x\n",phase,phase); + val=phase | (inv<<16);;// | (inv<<21); + + printf("Phase, val: %08x\n", val); setPllReconfigReg(PLL_PHASE_SHIFT_REG,val,0); //shifts counter 0 + + + } + + 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); + + // printf("PLL mode\n"); setPllReconfigReg(PLL_MODE_REG,0,0); + usleep(10000); +/* if (mode!=1) { */ + /* printf("reset pll\n"); */ +/* bus_w(PLL_CNTRL_REG,((1<1) @@ -480,46 +570,9 @@ u_int32_t setClockDivider(int d, int ic) { clkDivider[ic]=d; - + configurePll(ic); - 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(10000); - } - - - - - setPllReconfigReg(PLL_START_REG, 1,1); - usleep(100000); - bus_w(PLL_CNTRL_REG, 0); return clkDivider[ic]; } @@ -527,7 +580,7 @@ u_int32_t setClockDivider(int d, int ic) { int phaseStep(int st, int ic){ - u_int32_t addr; + u_int32_t addr, val=( (1<0) */ @@ -537,25 +590,30 @@ int phaseStep(int st, int ic){ /* st*=-1; */ /* } */ - bus_w(PLL_CNTRL_REG,(1<65535 || st<-65535) + return -1; - bus_w(PLL_CNTRL_REG, 0); - setPllReconfigReg(PLL_MODE_REG,1,0); - getPllReconfigReg(PLL_MODE_REG,0); + printf("ic=%d; phase %d\n", ic, st); - - setPllReconfigReg(PLL_PHASE_SHIFT_REG,st|(ic<<21),0); //shifts counter 0 - printf("shift %08x\n",st|(ic<<21)); - setPllReconfigReg(PLL_START_REG, 1,1); - usleep(100000); - bus_w(PLL_CNTRL_REG, 0); - - //setClockDivider(clkDivider[ic],ic); - - - return st; + + if (ic==1) + clkPhase[0]=-st; + else if (ic==0) + clkPhase[0]=st; + + + + /* printf("Changin phase %d\n",st); */ +/* for (i=0; i=0) + bus_w(DAQ_REG, d); + return bus_r(DAQ_REG)&0xff; +} + + u_int32_t setSetLength(int d) { return 0; } @@ -1146,12 +1212,12 @@ int64_t getFrames(){ int64_t setExposureTime(int64_t value){ /* time is in ns */ if (value!=-1) - value*=(1E-9*CLK_FREQ); - return set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ); + value*=(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ); + return set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ); } int64_t getExposureTime(){ - return get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ); + return get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ); } int64_t setGates(int64_t value){ @@ -1165,28 +1231,29 @@ int64_t getGates(){ int64_t setPeriod(int64_t value){ /* time is in ns */ if (value!=-1) { - value*=(1E-9*CLK_FREQ); + // value*=(1E-9*CLK_FREQ); + value*=(1E-3*clkDivider[0]); } - return set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ); + return set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ); } int64_t getPeriod(){ - return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ); + return get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ); } int64_t setDelay(int64_t value){ /* time is in ns */ if (value!=-1) { - value*=(1E-9*CLK_FREQ); + value*=(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ); } - return set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-9*CLK_FREQ); + return set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ); } int64_t getDelay(){ - return get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-9*CLK_FREQ); + return get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-3*clkDivider[0]);//(1E-9*CLK_FREQ); } int64_t setTrains(int64_t value){ @@ -1477,7 +1544,7 @@ int setADC(int adc){ if(adc==-1) ROI_flag=0; else ROI_flag=1; - setDAQRegister();//token timing + // setDAQRegister();//token timing cleanFifo();//adc sync //with gotthard module @@ -1894,144 +1961,80 @@ u_int32_t fifo_full(void) u_int16_t* fifo_read_event() { + int i=0; - - int i=0, j=0; -#ifdef VIRTUAL - return NULL; -#endif - - //#ifdef VERBOSE - printf("before looping\n"); - volatile u_int32_t fs; u_int16_t *dum; - //#endif volatile u_int32_t t = bus_r16(LOOK_AT_ME_REG); -#ifdef VERBOSE - printf("Data bytes is %d\n", dataBytes); - printf("lookatmereg=x%x\n",t); -#endif -/* - while ((t&0x1)==0) - { - t = bus_r(LOOK_AT_ME_REG); - if (!runBusy()){ - return NULL; - } - } -*/ - bus_w(DUMMY_REG,0); - while(t==0) { -#ifdef VERYVERBOSE - printf("before readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); -#endif -#ifdef VERYVERBOSE - printf("look at me reg:%08x\n",bus_r(LOOK_AT_ME_REG)); -#endif - if (runBusy()==0) { - t = bus_r(LOOK_AT_ME_REG); -#ifdef VERYVERBOSE - printf("status should be idle!..look at me reg:%08x\n",bus_r(LOOK_AT_ME_REG)); -#endif - if (t==0) { - //#ifdef VERBOSE - printf("no frame found - exiting\n"); - printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); - //#endif -#ifdef VERYVERBOSE - printf("returning null\n"); - printf("lookatmereg=x%x\n",t); -#endif - return NULL; - } else { - //#ifdef VERBOSE - printf("no frame found %x status %x\n", bus_r(LOOK_AT_ME_REG),runState()); - //#endif - break; - } - } - t = bus_r(LOOK_AT_ME_REG); - #ifdef VERYVERBOSE - printf("before starting while loop again: look at me reg:%08x\n\n",bus_r(LOOK_AT_ME_REG)); - #endif - if (i%1000==0) - printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); - i++; + while(t!=0xffffffff) { + if (runBusy()==0) { + t = bus_r(LOOK_AT_ME_REG); + if (t!=0xffffffff) { + 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; + } + } + t = bus_r(LOOK_AT_ME_REG); + printf("."); } -#ifdef VERYVERBOSE - printf(" out of while loop!\n"); -#endif - #ifdef VERYVERBOSE - printf("before readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); - i=0; - for (i=0; i<32; i++) { - // printf("Fifo %d (%04x) status :\n", i,FIFO_STATUS_REG | i); - fs=bus_r16(FIFO_STATUS_REG| i); - if (fs&0xfff0fff) - printf("before %d: %x\n",i, fs); - - } - -#endif - + // printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); /* dma_memcpy(now_ptr,values ,dataBytes); */ /* #else */ for (i=0; i<32; i++) { dum=((u_int16_t*)(now_ptr))+i; - bus_w(DUMMY_REG,i<<1); -#ifdef TESTADC - printf("%d s:%04x ",i,bus_r16(FIFO_STATUS_REG)); -#endif - - bus_w(DUMMY_REG,(i<<1) | 1); - bus_w(DUMMY_REG,i<<1); - *dum=bus_r16(FIFO_DATA_REG);// | i); //values[i]; -#ifdef TESTADC - printf("d:%04x s:%04x\n",*dum&0x3fff, bus_r16(FIFO_STATUS_REG)); -#endif - } - //#endif - printf("-"); - //memcpy(now_ptr,values ,dataBytes); //this reads the fifo twice... - - #ifdef VERYVERBOSE - printf("after readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); - i=0; - for (i=0; i<32; i++) { - fs=bus_r16(FIFO_STATUS_REG| i); - if (fs&0xfff0fff) - printf("after %d: %x\n",i, fs); - } - #endif - -#ifdef VERYVERBOSE - int a; - for (a=0;a<8; a=a+2) - printf("\n%d %d: x%04x x%04x ",a+1,a,*(now_ptr+a+1),*(now_ptr+a) ); - // for (a=2554;a<2560; a=a+2) - // printf("\n%d %d: x%04x x%04x ",a+1,a,*(now_ptr+a+1),*(now_ptr+a) ); - printf("********\n"); - //memcpy(now_ptr, values, dataBytes); - //#endif - //#ifdef VERYVERBOSE - printf("Copying to ptr %08x %d\n",(unsigned int)(now_ptr), dataBytes); - printf("after readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); -#endif - - if (storeInRAM>0) { - now_ptr+=dataBytes; - } -#ifdef VERYVERBOSE - printf("lookatmereg=x%x\n",t); -#endif + bus_w(DUMMY_REG,i<<1); + // usleep(10); + bus_w(DUMMY_REG,(i<<1) | 1); + // usleep(10); + bus_w(DUMMY_REG,i<<1); +/* usleep(10); */ + *dum=bus_r16(FIFO_DATA_REG); + } + printf("*"); return ram_values; - printf("\n"); } +u_int16_t* fifo_read_frame() +{ + u_int16_t *dum; + int ns=0; + now_ptr=(char*)ram_values; + while(ns0) { + dynamicRange=16; + nSamples=dr/16; + dataBytes=NMAXMOD*NCHIP*NCHAN*2; + } + allocateRAM(); + printf("Setting dataBytes to %d: dr %d; samples %d\n",dataBytes, dynamicRange, nSamples); return getDynamicRange(); } @@ -2106,8 +2117,8 @@ int setDynamicRange(int dr) { int getDynamicRange() { - dynamicRange=16; - return dynamicRange; + // dynamicRange=16; + return dynamicRange*nSamples; } @@ -2156,69 +2167,53 @@ int setStoreInRAM(int b) { int allocateRAM() { size_t size; - u_int32_t nt, nf; - nt=setTrains(-1); - nf=setFrames(-1); - if (nt==0) nt=1; - if (nf==0) nf=1; - // ret=clearRAM(); - if (storeInRAM) { - size=dataBytes*nf*nt; - if (size1) { + + clearRAM(); + ram_values=malloc(size); + // ram_values=realloc(ram_values,size)+2; + // if (ram_values) + // break; + // nSamples--; + //} if (ram_values) { now_ptr=(char*)ram_values; -#ifdef VERBOSE + + //#ifdef VERBOSE printf("ram allocated 0x%x of size %d to %x\n",(int)now_ptr,(unsigned int) size,(unsigned int)(now_ptr+size)); -#endif + //#endif ram_size=size; return OK; - } else { - printf("could not allocate %d bytes\n",(int)size); - if (storeInRAM==1) { - printf("retrying\n"); - storeInRAM=0; - size=dataBytes; - ram_values=realloc(ram_values,size)+2; - if (ram_values==NULL) - printf("Fatal error: there must be a memory leak somewhere! You can't allocate even one frame!\n"); - else { - now_ptr=(char*)ram_values; - ram_size=size; -#ifdef VERBOSE - printf("ram allocated 0x%x of size %d to %x\n",(int)now_ptr,(unsigned int) size,(unsigned int)(now_ptr+size)); -#endif - } - } else { - printf("Fatal error: there must be a memory leak somewhere! You can't allocate even one frame!\n"); - } - return FAIL; } + + + printf("Fatal error: there must be a memory leak somewhere! You can't allocate even one frame!\n"); + return FAIL; + @@ -2330,7 +2325,7 @@ int prepareADC(){ bus_w(ADC_LATCH_DISABLE_REG,0x0); // enable all ADCs - bus_w(DAQ_REG,0xd); //adc pipeline=13 + bus_w(DAQ_REG,0x12); //adc pipeline=18 bus_w(ADC_OFFSET_REG,0xbbbbbbbb); // bus_w(ADC_INVERSION_REG,0x1f6170c6); diff --git a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h index 8bc329546..868707d4f 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.h @@ -51,6 +51,7 @@ 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 setExtSignal(int d, enum externalSignalFlag mode); int getExtSignal(int d); @@ -134,6 +135,7 @@ u_int32_t fifo_full(void); u_int16_t* fifo_read_event(); +u_int16_t* fifo_read_frame(); u_int32_t* decode_data(int* datain); //u_int32_t move_data(u_int64_t* datain, u_int64_t* dataout); int setDynamicRange(int dr); diff --git a/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h b/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h index 5825680d7..a1f8b92bb 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h @@ -503,6 +503,15 @@ #define PLL_CNTR_WRITE_BIT 2 #define PLL_CNTR_PLL_RESET_BIT 3 + +#define PLL_CNTR_PHASE_EN_BIT 8 +#define PLL_CNTR_UPDN_BIT 9 +#define PLL_CNTR_CNTSEL_OFF 10 + + + + + #define PLL_MODE_REG 0x0 #define PLL_STATUS_REG 0x1 #define PLL_START_REG 0x2 @@ -525,6 +534,8 @@ #define PPL_BW_PARAM_DEFAULT 0x2EE0 #define PPL_VCO_PARAM_DEFAULT 0x1 +#define PLL_VCO_FREQ_MHZ 480//800 + diff --git a/slsDetectorSoftware/jungfrauDetectorServer/server_funcs.c b/slsDetectorSoftware/jungfrauDetectorServer/server_funcs.c index 0648ab859..8aac8624b 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/server_funcs.c +++ b/slsDetectorSoftware/jungfrauDetectorServer/server_funcs.c @@ -34,6 +34,7 @@ enum detectorType myDetectorType=GENERIC; extern int nModX; extern int nModY; extern int dataBytes; +extern int nSamples; extern int dynamicRange; extern int storeInRAM; @@ -153,6 +154,8 @@ int init_detector(int b, int checkType) { strcpy(lastClientIP,"none"); strcpy(thisClientIP,"none1"); lockStatus=0; + + allocateRAM(); return OK; } @@ -1938,6 +1941,11 @@ int get_run_status(int file_des) { int read_frame(int file_des) { + + int ns=0; + u_int16_t* p=NULL; + + if (differentClients==1 && lockStatus==1) { dataret=FAIL; sprintf(mess,"Detector locked by %s\n",lastClientIP); @@ -1949,81 +1957,39 @@ int read_frame(int file_des) { return dataret; } - - if (storeInRAM==0) { - if ((dataretval=(char*)fifo_read_event())) { - dataret=OK; -#ifdef VERYVERBOSE - printf("Sending ptr %x %d\n",(unsigned int)(dataretval), dataBytes); -#endif - sendDataOnly(file_des,&dataret,sizeof(dataret)); - sendDataOnly(file_des,dataretval,dataBytes); + p=fifo_read_frame(); + if (p) { + nframes++; + dataretval=(char*)ram_values; + dataret=OK; #ifdef VERBOSE - printf("sent %d bytes \n",dataBytes); - printf("dataret OK\n"); + printf("sending data of %d frames\n",nframes); #endif - return OK; - } else { - //might add delay???? - if(getFrames()>-1) { + 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); + } else { + if (getFrames()>-1) { dataret=FAIL; - sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+1)); + sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2)); printf("%s\n",mess); } else { dataret=FINISHED; sprintf(mess,"acquisition successfully finished\n"); printf("%s\n",mess); + if (differentClients) + dataret=FORCE_UPDATE; } -#ifdef VERYVERBOSE - printf("%d %d %x %s\n",(int)(sizeof(mess)),(int)(strlen(mess)),(unsigned int)( mess),mess); -#endif - sendDataOnly(file_des,&dataret,sizeof(dataret)); - sendDataOnly(file_des,mess,sizeof(mess)); -#ifdef VERYVERBOSE - printf("message sent %s\n",mess); -#endif - printf("dataret %d\n",dataret); - return dataret; - } - } else { - nframes=0; - while(fifo_read_event()) { - nframes++; - } - dataretval=(char*)ram_values; - dataret=OK; -#ifdef VERBOSE - printf("sending data of %d frames\n",nframes); -#endif - for (iframes=0; iframes-2) { - dataret=FAIL; - sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2)); - printf("%s\n",mess); - } else { - dataret=FINISHED; - sprintf(mess,"acquisition successfully finished\n"); - printf("%s\n",mess); - if (differentClients) - dataret=FORCE_UPDATE; - } #ifdef VERBOSE printf("Frames left %d\n",(int)(getFrames())); #endif - sendDataOnly(file_des,&dataret,sizeof(dataret)); - sendDataOnly(file_des,mess,sizeof(mess)); - printf("dataret %d\n",dataret); - return dataret; + sendDataOnly(file_des,&dataret,sizeof(dataret)); + sendDataOnly(file_des,mess,sizeof(mess)); } - printf("dataret %d\n",dataret); - return dataret; + return dataret; + } @@ -2164,9 +2130,9 @@ int set_timer(int file_des) { printf(mess); printf("set timer failed\n"); } else if (ind==FRAME_NUMBER) { - ret=allocateRAM(); - if (ret!=OK) - sprintf(mess, "could not allocate RAM for %lld frames\n", tns); + // ret=allocateRAM(); + // if (ret!=OK) + // sprintf(mess, "could not allocate RAM for %lld frames\n", tns); } n = sendDataOnly(file_des,&ret,sizeof(ret)); @@ -2291,7 +2257,7 @@ int set_dynamic_range(int file_des) { int retval; int ret=OK; - + printf("Set dynamic range?\n"); sprintf(mess,"can't set dynamic range\n"); @@ -2313,10 +2279,11 @@ int set_dynamic_range(int file_des) { if (ret!=OK) { sprintf(mess,"set dynamic range failed\n"); } else { - ret=allocateRAM(); - if (ret!=OK) - sprintf(mess,"Could not allocate RAM for the dynamic range selected\n"); - else if (differentClients) + /* ret=allocateRAM(); */ +/* if (ret!=OK) */ +/* sprintf(mess,"Could not allocate RAM for the dynamic range selected\n"); */ +// else + if (differentClients) ret=FORCE_UPDATE; } @@ -2457,6 +2424,11 @@ int set_speed(int file_des) { break; + case ADC_PIPELINE: + retval=adcPipeline(val); + break; + + default: ret=FAIL; @@ -2486,6 +2458,15 @@ int set_speed(int file_des) { retval=getClockDivider(1); break; + case ADC_PHASE: + retval=-1; + break; + + + case ADC_PIPELINE: + retval=adcPipeline(-1); + break; + default: ret=FAIL; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 09586844e..c0b3aac06 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -612,6 +612,10 @@ int slsDetector::initializeDetectorSize(detectorType type) { 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; + + } if(thisDetector->myDetectorType==MYTHEN){ if (thisDetector->dynamicRange==24 || thisDetector->timerValue[PROBES_NUMBER]>0) thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; @@ -1540,6 +1544,11 @@ int slsDetector::setNumberOfModules(int n, dimension d){ thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; } + if(thisDetector->myDetectorType==JUNGFRAUCTB){ + + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*dr/8; + + } #ifdef VERBOSE std::cout<< "Data size is " << thisDetector->dataBytes << std::endl; @@ -3363,9 +3372,9 @@ int* slsDetector::getDataFromDetector(int *retval){ } else { 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: received " << n << " but expected " << thisDetector->dataBytes << std::endl; thisDetector->stoppedFlag=1; @@ -3376,7 +3385,7 @@ int* slsDetector::getDataFromDetector(int *retval){ return NULL; } } - + // cout << "get data returning " << endl; return retval; }; @@ -3401,12 +3410,13 @@ int* slsDetector::readAll(){ while ((retval=getDataFromDetector())){ i++; -#ifdef VERBOSE + //#ifdef VERBOSE std::cout<< i << std::endl; //#else //std::cout << "-" << flush ; -#endif + //#endif dataQueue.push(retval); + std::cout<< "pushed" << std::endl; } controlSocket->Disconnect(); } @@ -4097,6 +4107,9 @@ int slsDetector::setDynamicRange(int n){ #endif if (n==24) n=32; + + + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -4121,24 +4134,31 @@ int slsDetector::setDynamicRange(int n){ if (ret!=FAIL && retval>0) { /* checking the number of probes to chose the data size */ - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8; - - if(thisDetector->myDetectorType==MYTHEN){ - if (thisDetector->timerValue[PROBES_NUMBER]!=0) - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; - - if (retval==32) - thisDetector->dynamicRange=24; - } - thisDetector->dynamicRange=retval; + 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; + } + if(thisDetector->myDetectorType==MYTHEN){ + if (thisDetector->timerValue[PROBES_NUMBER]!=0) + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; + + if (retval==32) + thisDetector->dynamicRange=24; + } -#ifdef VERBOSE + thisDetector->dynamicRange=retval; + + + //#ifdef VERBOSE std::cout<< "Dynamic range set to "<< thisDetector->dynamicRange << std::endl; std::cout<< "Data bytes "<< thisDetector->dataBytes << std::endl; -#endif + //#endif } @@ -4368,11 +4388,14 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){ double* slsDetector::decodeData(int *datain, double *fdata) { double *dataout; - if (fdata) + if (fdata) { dataout=fdata; - else + // 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; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorActions.h b/slsDetectorSoftware/slsDetector/slsDetectorActions.h index 5cc495d9f..a920854b8 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorActions.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorActions.h @@ -204,11 +204,11 @@ class slsDetectorActions : public virtual slsDetectorBase */ virtual int setAllTrimbits(int val, int imod=-1)=0; - /** returns the detector type - \param pos position in the multi detector structure (is -1 returns type of detector with id -1) - \returns type - */ - virtual detectorType getDetectorsType(int pos=-1)=0; +/* /\** returns the detector type */ +/* \param pos position in the multi detector structure (is -1 returns type of detector with id -1) */ +/* \returns type */ +/* *\/ */ +/* virtual detectorType getDetectorsType(int pos=-1)=0; */ virtual int setThresholdEnergy(int, int im=-1, detectorSettings isettings=GET_SETTINGS)=0; virtual int setChannel(int64_t, int ich=-1, int ichip=-1, int imod=-1)=0; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 554adeefe..97bb255cf 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -77,6 +77,12 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef /** virtual destructor */ virtual ~slsDetectorBase(){}; + /** returns the detector type + \param pos position in the multi detector structure (is -1 returns type of detector with id -1) + \returns type + */ + virtual detectorType getDetectorsType(int pos=-1)=0; + string getDetectorDeveloper(){return string("PSI");}; // protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 7c1f36179..4cd6f5c12 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -828,6 +828,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed; i++; + + descrToFuncMap[i].m_pFuncName="adcpipeline"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed; + i++; + + + /* settings dump/retrieve */ descrToFuncMap[i].m_pFuncName="config"; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfiguration; @@ -3939,6 +3946,8 @@ string slsDetectorCommand::cmdSpeed(int narg, char *args[], int action) { index=ADC_CLOCK; else if (cmd=="adcphase") index=ADC_PHASE; + else if (cmd=="adcpipeline") + index=ADC_PIPELINE; else return string("could not decode speed variable ")+cmd; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 46bf60726..387923f94 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -75,6 +75,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { // int getPositions(double *pos=NULL){return angularConversion::getPositions(pos);}; using slsDetectorBase::setFlatFieldCorrection; + using slsDetectorBase::getDetectorsType; using postProcessing::setBadChannelCorrection; int enableFlatFieldCorrection(int i=-1) {if (i>0) setFlatFieldCorrectionFile("default"); else if (i==0) setFlatFieldCorrectionFile(""); return getFlatFieldCorrection();}; @@ -126,12 +127,6 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { virtual string setHostname(const char* name, int pos=-1)=0; - /** returns the detector type - \param pos position in the multi detector structure (is -1 returns type of detector with id -1) - \returns type - */ - virtual detectorType getDetectorsType(int pos=-1)=0; - /** returns the detector type \param pos position in the multi detector structure (is -1 returns type of detector with id -1) \returns type diff --git a/slsDetectorSoftware/slsDetectorAnalysis/fileIO.cpp b/slsDetectorSoftware/slsDetectorAnalysis/fileIO.cpp index 4e25a1dcc..5ab0d033f 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/fileIO.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/fileIO.cpp @@ -21,6 +21,11 @@ string fileIO::createFileName() { frameIndex, \ detIndex \ ); + + if (getDetectorsType()==JUNGFRAUCTB) { + nBytes=2*getTotalNumberOfChannels(); + } else + nBytes=getDataBytes(); return currentFileName; } @@ -86,8 +91,6 @@ int fileIO::writeDataFile(ofstream &outfile, int *data, int offset){ int fileIO::writeDataFile(void *data, int iframe) { - // cout << "fileIO writeDataFile" << endl; - if (iframe<0) iframe=frameIndex; @@ -96,12 +99,13 @@ int fileIO::writeDataFile(void *data, int iframe) { if ((iframe%(*framesPerFile))==0 || (iframe<0)) { createFileName(); - filefd = fopen((currentFileName+string(".raw")).c_str(), "w"); + filefd = fopen((currentFileName+string(".raw")).c_str(), "w"); } if (filefd){ - fileIOStatic::writeBinaryDataFile(filefd,getDataBytes(), data); - iframe++; +// fileIOStatic::writeBinaryDataFile(filefd,getDataBytes(), data); + fileIOStatic::writeBinaryDataFile(filefd,nBytes, data); + iframe++; } if ((iframe%(*framesPerFile)==0) || (iframe<0)) { diff --git a/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h b/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h index d828617b3..7091eb388 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h @@ -317,7 +317,9 @@ yes */ int nframes; // int fformat; + + int nBytes; }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h b/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h index 61ced8e9b..aa683ac75 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/fileIOStatic.h @@ -412,6 +412,7 @@ class fileIOStatic { }; static int writeBinaryDataFile(FILE *sfilefd, size_t nbytes, void *data){ \ + // cout << "bin " << sfilefd << " " << nbytes << " " << data << endl; fwrite(data, 1, nbytes, sfilefd); \ return slsDetectorDefs::OK; \ }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 06f2aaeb1..1b4bc2c20 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -9,17 +9,17 @@ //#define VERBOSE -static void* startProcessData(void *n){\ - postProcessing *myDet=(postProcessing*)n;\ - myDet->processData(1);\ - pthread_exit(NULL);\ +static void* startProcessData(void *n){ + postProcessing *myDet=(postProcessing*)n; + myDet->processData(1); + pthread_exit(NULL); }; -static void* startProcessDataNoDelete(void *n){\ - postProcessing *myDet=(postProcessing*)n;\ - myDet->processData(0);\ - pthread_exit(NULL);\ +static void* startProcessDataNoDelete(void *n){ + postProcessing *myDet=(postProcessing*)n; + myDet->processData(0); + pthread_exit(NULL); }; @@ -65,10 +65,10 @@ postProcessing::~postProcessing(){ -void postProcessing::processFrame(int *myData, int delflag) { +void postProcessing::processFrame(int *myData, int delflag, int jctb) { string fname; - // double *fdata=NULL; + //double *fdata=NULL; #ifdef VERBOSE cout << "start processing"<< endl; @@ -136,7 +136,7 @@ void postProcessing::processFrame(int *myData, int delflag) { if (dataReady){ // cout << "callback arg "<< getCurrentProgress()<< " " << (fname+string(".raw")).c_str() << " " << getTotalNumberOfChannels() << endl; - + // cout << "DATAREADY 1" <0) { /** Pop data queue */ -#ifdef VERBOSE - cout << "data foun"<< endl< Date: Tue, 10 Feb 2015 10:16:43 +0100 Subject: [PATCH 2/2] jungfrau detector server starts in CPU_NOT_10GB mode; ADC VREF put to 1V --- .../jungfrauDetectorServer/firmware_funcs.c | 12 +++++++----- .../jungfrauDetectorServer/registers_m.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c index c2bb7bce5..1778c0171 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c @@ -1039,15 +1039,15 @@ int startReceiver(int start) { int reg=bus_r(addr); //for start recever, write 0 and for stop, write 1 if (!start) - bus_w(CONFIG_REG,reg|CPU_OR_RECEIVER_BIT); + bus_w(CONFIG_REG,reg&(~GB10_NOT_CPU_BIT)); else - bus_w(CONFIG_REG,reg&(~CPU_OR_RECEIVER_BIT)); + 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&CPU_OR_RECEIVER_BIT; + int d =reg&GB10_NOT_CPU_BIT; if(d!=0) d=1; if(d!=start) return OK; @@ -2279,8 +2279,6 @@ int prepareADC(){ codata=0; writeADC(0x08,0x3); writeADC(0x08,0x0); - writeADC(0x14,0x40);//lvds reduced range - // writeADC(0x14,0x00);//lvds writeADC(0x16,0x01);//output clock phase @@ -2288,6 +2286,10 @@ int prepareADC(){ // writeADC(0x16,0x4);//output clock phase + writeADC(0x18,0x0);// vref 1V + + writeADC(0x14,0x40);//lvds reduced range -- offset binary + writeADC(0xD,0x0);//no test mode #ifdef TESTADC diff --git a/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h b/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h index a1f8b92bb..fae176f09 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h +++ b/slsDetectorSoftware/jungfrauDetectorServer/registers_m.h @@ -392,7 +392,7 @@ #define TOT_ENABLE_BIT 0x00000002 #define TIMED_GATE_BIT 0x00000004 #define CONT_RO_ENABLE_BIT 0x00080000 -#define CPU_OR_RECEIVER_BIT 0x00001000 +#define GB10_NOT_CPU_BIT 0x00001000