diff --git a/slsDetectorSoftware/mythenDetectorServer/Makefile b/slsDetectorSoftware/mythenDetectorServer/Makefile index 94e7ef09d..56cc2ed50 100755 --- a/slsDetectorSoftware/mythenDetectorServer/Makefile +++ b/slsDetectorSoftware/mythenDetectorServer/Makefile @@ -13,7 +13,8 @@ INSTMODE= 0777 SRCS= server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c OBJS= $(SRCS:%.c=%.o) -CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DVERBOSE +CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS +#-DVERBOSE # -DVERYVERBOSE #-Werror diff --git a/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.c b/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.c index 2a44ef11e..c2183db05 100755 --- a/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/mythenDetectorServer/firmware_funcs.c @@ -834,24 +834,33 @@ int getDynamicRange() { } int testBus() { - int j; + u_int32_t j, i; char cmd[100]; - u_int32_t val; - printf("%s\n",cmd); - system(cmd); - for (j=0; j<1000000; j++) { - val=bus_r(FIX_PATT_REG); - if (val!=0xacdc1980){ - printf("%d %x\n",j, val); + u_int32_t val=0x0; + // printf("%s\n",cmd); + // system(cmd); + i=0; + printf("testing bus\n"); + while (i<10000000) { + // val=bus_r(FIX_PATT_REG); + bus_w(DUMMY_REG,val); + bus_w(FIX_PATT_REG,0x0); + j=bus_r(DUMMY_REG); + if (i%10000==1) + printf("value 0x%x\n",j); + if (j!=val){ + printf("read wrong value %x instead of %x\n",j, val); return FAIL; } + val+=0xbbbbb; + i++; } return OK; } int setStoreInRAM(int b) { - if (b) + if (b>0) storeInRAM=1; else storeInRAM=0; diff --git a/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c b/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c index b3cc8f22c..d85629619 100755 --- a/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c +++ b/slsDetectorSoftware/mythenDetectorServer/mcb_funcs.c @@ -420,7 +420,10 @@ int program_one_dac(int addr, int value, int imod) { int idac; int v=value; // sls_detector_module *myMod; - control=9+addr; + control=9+addr; + + + printf("programming dac %d value %d module %d\n",addr, value,imod); #ifdef MAX5533 value=value | (control<< 12); #endif @@ -467,16 +470,16 @@ int program_one_dac(int addr, int value, int imod) { if (imod>=0 && imoddacs[idac]=v; -#ifdef VERBOSE - printf("module=%d index=%d, val=%d addr=%x\n",imod, idac, v, detectorDacs+idac+NDAC*imod); -#endif detectorDacs[idac+NDAC*imod]=v; + //#ifdef VERBOSE + printf("module=%d index=%d, val=%d addr=%x\n",imod, idac, v, detectorDacs+idac+NDAC*imod); + //#endif } else if (imod==ALLMOD) { for (im=0; imdacs[idac]=v; } } @@ -537,9 +540,9 @@ float initDACbyIndex(int ind,float val, int imod) { v=(val+(val-ref)*r1/r2)*DAC_DR/DAC_MAX; - initDACbyIndexDACU(ind,v,imod); - - return val; + v=initDACbyIndexDACU(ind,v,imod); + + return (v*DAC_MAX/DAC_DR+ref*r1/r2)/(1+r1/r2); } float initDACbyIndexDACU(int ind, int val, int imod) { @@ -550,15 +553,27 @@ float initDACbyIndexDACU(int ind, int val, int imod) { int cs=daccs[ind]; int addr=dacaddr[ind]; int iv; + int im; - - initDAC(cs, addr,val, imod); + if (val>=0) { + initDAC(cs, addr,val, imod); /*#ifdef VERBOSE iv=detectorDacs[ind+imod*NDAC]; printf("module=%d index=%d, cs=%d, addr=%d, dacu=%d, set to %d",imod, ind,cs,addr,val,iv); #endif */ - return val; + //return val; + } + if (imod>=0 && imodgain,(detectorModules+imod)->offset, ethr,dacu); #endif - initDACbyIndexDACU(VTHRESH, dacu, imod); - } else - printf("could not set threshold energy for module %d, settings %d (offset is %f; gain is %f)\n",imod,myo,myg); + } else { + dacu=ethr; +#ifdef VERBOSE + printf("could not set threshold energy for module %d, settings %d (offset is %f; gain is %f)\n",imod,thisSettings,myo,myg); +#endif + } + initDACbyIndexDACU(VTHRESH, dacu, imod); } return ret; } @@ -682,7 +701,7 @@ float getDACbyIndexDACU(int ind, int imod) { int initDAC(int dac_cs, int dac_addr, int value, int imod) { int i; -#ifdef DEBUGOUT +#ifdef VERBOSE printf("Programming dac %d %d with value %d\n", dac_cs, dac_addr, value); #endif clearDACSregister(imod); @@ -701,7 +720,6 @@ int initDAC(int dac_cs, int dac_addr, int value, int imod) { /*}*/ set_one_dac(imod); nextDAC(imod); - return 0; } diff --git a/slsDetectorSoftware/mythenDetectorServer/server.c b/slsDetectorSoftware/mythenDetectorServer/server.c index 34fb71419..fce7aecc1 100755 --- a/slsDetectorSoftware/mythenDetectorServer/server.c +++ b/slsDetectorSoftware/mythenDetectorServer/server.c @@ -34,8 +34,9 @@ int main(int argc, char *argv[]) b=0; printf("opening stop server on port %d\n",portno); } - +#ifndef VIRTUAL system("bus -a 0xb0000000 -w 0xd0008"); +#endif init_detector(b); diff --git a/slsDetectorSoftware/mythenDetectorServer/server_funcs.c b/slsDetectorSoftware/mythenDetectorServer/server_funcs.c index 782ae98e4..5c669fd0a 100755 --- a/slsDetectorSoftware/mythenDetectorServer/server_funcs.c +++ b/slsDetectorSoftware/mythenDetectorServer/server_funcs.c @@ -1,4 +1,3 @@ - #include "sls_detector_defs.h" #include "server_funcs.h" #include "server_defs.h" @@ -38,7 +37,9 @@ char mess[1000]; int init_detector( int b) { mapCSP0(); +#ifndef VIRTUAL system("bus -a 0xb0000000 -w 0xd0008"); +#endif testFpga(); #ifdef MCB_FUNCS if (b) { @@ -594,7 +595,7 @@ int digital_test(int fnum) { retval=testFpga(); break; case DETECTOR_MEMORY_TEST: - ret=FAIL; + ret=testRAM(); break; case DETECTOR_BUS_TEST: retval=testBus(); @@ -801,7 +802,7 @@ int set_dac(int fnum) { #ifdef VERBOSE printf("DAC set to %f V\n", retval); #endif - if (retval==val) + if (retval==val || val==-1) ret=OK; else { ret=FAIL; @@ -1643,12 +1644,11 @@ int read_frame(int fnum) { if(getFrames()>-2) { dataret=FAIL; sprintf(mess,"no data and run stopped: %d frames left\n",getFrames()+2); -#ifdef VERBOSE printf("%s\n",mess); -#endif } else { dataret=FINISHED; sprintf(mess,"acquisition successfully finished\n"); + printf("%s\n",mess); } #ifdef VERYVERBOSE printf("%d %d %x %s\n",strlen(mess)+1,strlen(mess), mess,mess); @@ -1681,9 +1681,11 @@ int read_frame(int fnum) { if (getFrames()>-2) { dataret=FAIL; sprintf(mess,"no data and run stopped: %d frames left\n",getFrames()+2); + printf("%s\n",mess); } else { dataret=FINISHED; sprintf(mess,"acquisition successfully finished\n"); + printf("%s\n",mess); } #ifdef VERBOSE printf("Frames left %d\n",getFrames()); @@ -2084,6 +2086,8 @@ int set_readout_flags(int fnum) { //ret=setStoreInRAM(0); // initChipWithProbes(0,0,0, ALLMOD); switch(arg) { + case GET_READOUT_FLAGS: + break; case STORE_IN_RAM: ret=setStoreInRAM(1); break;