diff --git a/slsDetectorSoftware/jungfrauDetectorServer/Makefile b/slsDetectorSoftware/jungfrauDetectorServer/Makefile index af9c684c4..928dae653 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/Makefile +++ b/slsDetectorSoftware/jungfrauDetectorServer/Makefile @@ -9,7 +9,7 @@ CC = $(CROSS)gcc CFLAGS += -Wall -DMOENCHD -DMCB_FUNCS -DDACS_INT -DDEBUG #-DVERBOSE #-DVERYVERBOSE #-DVIRTUAL #-DDACS_INT_CSERVER -PROGS= jungfrauDetectorServer +PROGS= jungfrauDetectorServer INSTDIR= /tftpboot INSTMODE= 0777 @@ -23,12 +23,20 @@ OBJS = $(SRCS:%.c=%.o) all: clean $(PROGS) +test: clean jungfrauADCTEst + boot: $(OBJS) -$(PROGS): $(OBJS) +jungfrauDetectorServer: $(OBJS) echo $(OBJS) $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) +jungfrauADCTEst: $(OBJS) + echo $(OBJS) + $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) -DTESTADC + + + install: $(PROGS) $(INSTALL) -d $(INSTDIR) diff --git a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c index 204ff3dde..404f784bf 100755 --- a/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/jungfrauDetectorServer/firmware_funcs.c @@ -1,3 +1,5 @@ +#define TESTADC + #include "server_defs.h" #include "firmware_funcs.h" @@ -263,42 +265,42 @@ int setPhaseShiftOnce(){ int cleanFifo(){ - u_int32_t addr, reg, val, adc_sync; - printf("Cleaning FIFO\n"); - addr=ADC_SYNC_REG; +/* u_int32_t addr, reg, val, adc_sync; */ +/* printf("Cleaning FIFO\n"); */ +/* addr=ADC_SYNC_REG; */ - if(withGotthard) - adc_sync = GOTTHARD_ADCSYNC_VAL; - else - adc_sync = ADCSYNC_VAL; +/* if(withGotthard) */ +/* adc_sync = GOTTHARD_ADCSYNC_VAL; */ +/* else */ +/* adc_sync = ADCSYNC_VAL; */ - reg = bus_r(addr) & CLEAN_FIFO_MASK; +/* reg = bus_r(addr) & CLEAN_FIFO_MASK; */ - //only for start up - if(!reg) reg = adc_sync; +/* //only for start up */ +/* if(!reg) reg = adc_sync; */ - // 88 3 02111 - if (ROI_flag==0) { - val=reg | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY; - bus_w(addr,val); - // 88 0 02111 - val=reg | TOKEN_RESTART_DELAY; - bus_w(addr,val); - } - else { - //1b332214 - val=reg | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY_ROI; - bus_w(addr,val); - //1b032214 - val=reg | TOKEN_RESTART_DELAY_ROI; - bus_w(addr,val); +/* // 88 3 02111 */ +/* if (ROI_flag==0) { */ +/* val=reg | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY; */ +/* bus_w(addr,val); */ +/* // 88 0 02111 */ +/* val=reg | TOKEN_RESTART_DELAY; */ +/* bus_w(addr,val); */ +/* } */ +/* else { */ +/* //1b332214 */ +/* val=reg | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY_ROI; */ +/* bus_w(addr,val); */ +/* //1b032214 */ +/* val=reg | TOKEN_RESTART_DELAY_ROI; */ +/* bus_w(addr,val); */ - } - reg=bus_r(addr); -//#ifdef DDEBUG - printf("ADC SYNC reg 0x19:%x\n",reg); -//#endif +/* } */ +/* reg=bus_r(addr); */ +/* //#ifdef DDEBUG */ +/* printf("ADC SYNC reg 0x19:%x\n",reg); */ +/* //#endif */ return OK; } @@ -1344,49 +1346,52 @@ int getTemperature(int tempSensor, int imod){ int initHighVoltage(int val, int imod){ -#ifdef VERBOSE - printf("Setting/Getting High Voltage of module:%d with val:%d\n",imod,val); -#endif - volatile u_int32_t addr=HV_REG; - int writeVal,writeVal2; - switch(val){ - case -1: break; - case 0: writeVal=0x0; writeVal2=0x0; break; - case 90: writeVal=0x0; writeVal2=0x1; break; - case 110:writeVal=0x2; writeVal2=0x3; break; - case 120:writeVal=0x4; writeVal2=0x5; break; - case 150:writeVal=0x6; writeVal2=0x7; break; - case 180:writeVal=0x8; writeVal2=0x9; break; - case 200:writeVal=0xA; writeVal2=0xB; break; - default :printf("Invalid voltage\n");return -2;break; - } - //to set value - if(val!=-1){ - //set value to converted value - bus_w(addr,writeVal); - bus_w(addr,writeVal2); -#ifdef VERBOSE - printf("Value sent is %d and then %d\n",writeVal,writeVal2); -#endif - } - //read value and return the converted value - val=bus_r(addr); -#ifdef VERBOSE - printf("Value read from reg is %d\n",val); -#endif - switch(val){ - case 0x0:val=0;break; - case 0x1:val=90;break; - case 0x3:val=110;break; - case 0x5:val=120;break; - case 0x7:val=150;break; - case 0x9:val=180;break; - case 0xB:val=200;break; - default:printf("Weird value read:%d\n",val);return -3;break; - } -#ifdef VERBOSE - printf("High voltage of module:%d is %d\n",imod,val); -#endif + + printf("*******SetHV: Doing nothing - still to be implemented!\n"); + +/* #ifdef VERBOSE */ +/* printf("Setting/Getting High Voltage of module:%d with val:%d\n",imod,val); */ +/* #endif */ +/* volatile u_int32_t addr=HV_REG; */ +/* int writeVal,writeVal2; */ +/* switch(val){ */ +/* case -1: break; */ +/* case 0: writeVal=0x0; writeVal2=0x0; break; */ +/* case 90: writeVal=0x0; writeVal2=0x1; break; */ +/* case 110:writeVal=0x2; writeVal2=0x3; break; */ +/* case 120:writeVal=0x4; writeVal2=0x5; break; */ +/* case 150:writeVal=0x6; writeVal2=0x7; break; */ +/* case 180:writeVal=0x8; writeVal2=0x9; break; */ +/* case 200:writeVal=0xA; writeVal2=0xB; break; */ +/* default :printf("Invalid voltage\n");return -2;break; */ +/* } */ +/* //to set value */ +/* if(val!=-1){ */ +/* //set value to converted value */ +/* bus_w(addr,writeVal); */ +/* bus_w(addr,writeVal2); */ +/* #ifdef VERBOSE */ +/* printf("Value sent is %d and then %d\n",writeVal,writeVal2); */ +/* #endif */ +/* } */ +/* //read value and return the converted value */ +/* val=bus_r(addr); */ +/* #ifdef VERBOSE */ +/* printf("Value read from reg is %d\n",val); */ +/* #endif */ +/* switch(val){ */ +/* case 0x0:val=0;break; */ +/* case 0x1:val=90;break; */ +/* case 0x3:val=110;break; */ +/* case 0x5:val=120;break; */ +/* case 0x7:val=150;break; */ +/* case 0x9:val=180;break; */ +/* case 0xB:val=200;break; */ +/* default:printf("Weird value read:%d\n",val);return -3;break; */ +/* } */ +/* #ifdef VERBOSE */ +/* printf("High voltage of module:%d is %d\n",imod,val); */ +/* #endif */ return val; } @@ -1722,7 +1727,12 @@ int i; //#ifdef VERBOSE printf("*******Starting State Machine*******\n"); //#endif - cleanFifo(); + +//NEEDED? +// cleanFifo(); + + + // fifoReset(); now_ptr=(char*)ram_values; #ifdef SHAREDMEMORY @@ -1849,15 +1859,16 @@ u_int16_t* fifo_read_event() { - int i=0; + int i=0, j=0; #ifdef VIRTUAL return NULL; #endif -#ifdef VERBOSE + //#ifdef VERBOSE printf("before looping\n"); - volatile u_int32_t fs; -#endif + volatile u_int32_t fs; + u_int16_t *dum; + //#endif volatile u_int32_t t = bus_r16(LOOK_AT_ME_REG); #ifdef VERBOSE @@ -1874,6 +1885,7 @@ u_int16_t* fifo_read_event() } */ + bus_w(DUMMY_REG,0); while(t==0) { #ifdef VERYVERBOSE printf("before readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); @@ -1914,28 +1926,48 @@ u_int16_t* fifo_read_event() #ifdef VERYVERBOSE printf(" out of while loop!\n"); #endif -#ifdef VERYVERBOSE + #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); - printf("before: %x\n",fs); + // 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 - - dma_memcpy(now_ptr,values ,dataBytes); + +/* 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 + #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); - printf("after %d: %x\n",i, fs); + fs=bus_r16(FIFO_STATUS_REG| i); + if (fs&0xfff0fff) + printf("after %d: %x\n",i, fs); } -#endif + #endif #ifdef VERYVERBOSE int a; @@ -2154,44 +2186,118 @@ int allocateRAM() { } + + +int writeADC(int addr, int val) { + + + u_int32_t valw,codata,csmask; + int i,cdx,ddx,j; + cdx=0; ddx=1; + csmask=0xfc; // 1111100 + + codata=val + (addr<< 8); + printf("***** ADC SPI WRITE TO REGISTER %04X value %04X\n",addr,val); + // start point + valw=0xff; + bus_w(ADC_WRITE_REG,(valw)); + + //chip sel bar down + valw=((0xffffffff&(~csmask))); + bus_w(ADC_WRITE_REG,valw); + + for (i=0;i<24;i++) { + //cldwn + valw=valw&(~(0x1<>(23-i))&0x1)<>(23-i))&0x1)<timerValue[PROBES_NUMBER]==0) { + if (thisDetector->myDetectorType==JUNGFRAUCTB) { + + for (ichan=0; ichandataBytes; ibyte++) { @@ -4430,6 +4447,7 @@ double* slsDetector::decodeData(int *datain, double *fdata) { dataout[ichan]=ival; } } + } } else { for (ichan=0; ichan