From 0254ff0281faa4ae4e47aaedae5b60824af0810a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 2 Jun 2017 19:29:34 +0200 Subject: [PATCH] cleaning up of servers --- .../commonFiles/sls_detector_defs.h | 3 - .../slsDetectorFunctionList.c | 1075 ++++++++--------- .../slsDetectorServer_defs.h | 92 +- .../RegisterDefs.h | 3 + .../slsDetectorFunctionList.c | 655 ++++++---- .../slsDetectorServer_defs.h | 22 +- .../slsDetectorFunctionList.h | 33 +- .../slsDetectorServer_funcs.c | 20 +- 8 files changed, 1083 insertions(+), 820 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index ae9ed32a4..6d4e2a5b6 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -19,9 +19,6 @@ /** header length for data :gotthard*/ #define HEADERLENGTH 12 -#define DEFAULT_SUBFRAME_EXPOSURE_VAL 2621440 /** default value for sub frame value 2.6ms*/ -#define MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS 0x1FFFFFFF /** 29 bit register for max subframe exposure value */ - /** maximum rois */ #define MAX_ROIS 100 diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c index fe298c981..a799d4594 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c @@ -51,24 +51,7 @@ unsigned int nimages_per_request=1; int on_dst=0; int dst_requested[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; -int default_dac_values[16] = { - 0, //SvP - 2480, //Vtr - 3300, //Vrf - 1400, //Vrs - 4000, //SvN - 2556, //Vtgstv - 1000, //Vcmp_ll - 1000, //Vcmp_lr - 4000, //cal - 1000, //Vcmp_rl - 1100, //rxb_rb - 1100, //rxb_lb - 1000, //Vcmp_rr - 1000, //Vcp - 2000, //Vcn - 1550 //Vis -}; + int default_gain_values[3] = {517000,517000,517000}; int default_offset_values[3] = {3851000,3851000,3851000}; @@ -79,10 +62,11 @@ int master = 0; int normal = 0; -#define TEN_GIGA_BUFFER_SIZE 4112 -#define ONE_GIGA_BUFFER_SIZE 1040 + +/* basic tests */ + void checkFirmwareCompatibility(){ uint32_t ipadd = getDetectorIP(); uint64_t macadd = getDetectorMAC(); @@ -90,9 +74,10 @@ void checkFirmwareCompatibility(){ int64_t swversion = getDetectorId(DETECTOR_SOFTWARE_VERSION); int64_t sw_fw_apiversion = getDetectorId(SOFTWARE_FIRMWARE_API_VERSION); - cprintf(BLUE,"\n\n********************************************************\n" - "**********************EIGER Server**********************\n" - "********************************************************\n"); + cprintf(BLUE,"\n\n" + "********************************************************\n" + "**********************EIGER Server**********************\n" + "********************************************************\n"); cprintf(BLUE,"\n" "Detector IP Addr:\t\t 0x%x\n" "Detector MAC Addr:\t\t 0x%llx\n" @@ -100,8 +85,8 @@ void checkFirmwareCompatibility(){ "Firmware Version:\t\t %lld\n" "Software Version:\t\t %llx\n" "F/w-S/w API Version:\t\t %lld\n" - "Required Firmware Version:\t %d\n" - "\n********************************************************\n", + "Required Firmware Version:\t %d\n\n" + "********************************************************\n", ipadd, macadd, fwversion,swversion, sw_fw_apiversion,REQUIRED_FIRMWARE_VERSION); @@ -133,27 +118,13 @@ void checkFirmwareCompatibility(){ int moduleTest( enum digitalTestMode arg, int imod){ - //template testShiftIn from mcb_funcs.c - - //CHIP_TEST - //testShiftIn - //testShiftOut - //testShiftStSel - //testDataInOutMux - //testExtPulseMux - //testOutMux - //testFpgaMux - + cprintf(BG_RED, "Warning: Module Test not implemented for this detector\n"); return OK; } - - - int detectorTest( enum digitalTestMode arg){ - //templates from firmware_funcs.c - + cprintf(BG_RED, "Warning: Detector Tests not implemented for this detector\n"); //DETECTOR_FIRMWARE_TEST:testFpga() //DETECTOR_MEMORY_TEST:testRAM() //DETECTOR_BUS_TEST:testBus() @@ -162,6 +133,10 @@ int detectorTest( enum digitalTestMode arg){ } + + +/* Ids */ + int64_t getDetectorId(enum idMode arg){ int64_t retval = -1; @@ -232,7 +207,6 @@ u_int64_t getDetectorMAC() { } - u_int32_t getDetectorIP(){ char temp[50]=""; u_int32_t res=0; @@ -259,6 +233,9 @@ u_int32_t getDetectorIP(){ + +/* initialization */ + void initControlServer(){ //Feb and Beb Initializations getModuleConfiguration(); @@ -306,6 +283,8 @@ void getModuleConfiguration(){ +/* set up detector */ + void allocateDetectorStructureMemory(){ printf("This Server is for 1 Eiger half module (250k)\n"); @@ -346,25 +325,25 @@ void setupDetector() { //Get dac values int retval[2]; for(i=0;i<(detectorModules)->ndac;i++) - setDAC((enum detDacIndex)i,default_dac_values[i],(detectorModules)->module,0,retval); + setDAC((enum DAC_INDEX)i,DEFAULT_DAC_VALS[i],(detectorModules)->module,0,retval); //setting default measurement parameters - setTimer(FRAME_NUMBER,1); - setTimer(ACQUISITION_TIME,1E9); - setTimer(SUBFRAME_ACQUISITION_TIME,DEFAULT_SUBFRAME_EXPOSURE_VAL); - setTimer(FRAME_PERIOD,1E9); - setDynamicRange(16); - eiger_photonenergy = -1; - setReadOutFlags(NONPARALLEL); - setSpeed(0,1);//clk_devider,half speed - setIODelay(650,0); - setTiming(AUTO_TIMING); + setTimer(FRAME_NUMBER, DEFAULT_NUM_FRAMES); + setTimer(ACQUISITION_TIME, DEFAULT_EXPTIME); + setTimer(SUBFRAME_ACQUISITION_TIME, DEFAULT_SUBFRAME_EXPOSURE_VAL); + setTimer(FRAME_PERIOD, DEFAULT_PERIOD); + setDynamicRange(DEFAULT_DYNAMIC_RANGE); + eiger_photonenergy = DEFAULT_PHOTON_ENERGY; + setReadOutFlags(DEFAULT_READOUT_FLAG); + setSpeed(CLOCK_DIVIDER, DEFAULT_CLK_SPEED);//clk_devider,half speed + setIODelay(DEFAULT_IO_DELAY, DEFAULT_MOD_INDEX); + setTiming(DEFAULT_TIMING_MODE); //SetPhotonEnergyCalibrationParameters(-5.8381e-5,1.838515,5.09948e-7,-4.32390e-11,1.32527e-15); - setRateCorrection(0); //deactivate rate correction - int enable[2] = {0,1}; + setRateCorrection(DEFAULT_RATE_CORRECTION); + int enable[2] = {DEFAULT_EXT_GATING_ENABLE, DEFAULT_EXT_GATING_POLARITY}; setExternalGating(enable);//disable external gating - Feb_Control_SetInTestModeVariable(0); - setHighVoltage(0); + Feb_Control_SetInTestModeVariable(DEFAULT_TEST_MODE); + setHighVoltage(DEFAULT_HIGH_VOLTAGE); Feb_Control_CheckSetup(); } @@ -372,8 +351,106 @@ void setupDetector() { + + +/* set parameters - nmod, dr, roi */ + +int setNMod(int nm, enum dimension dim){ + return NMOD; +} + + int getNModBoard(enum dimension arg){ - return 1; + return NMAXMOD; +} + +int setDynamicRange(int dr){ + if(dr > 0){ + printf(" Setting dynamic range: %d\n",dr); + if(Feb_Control_SetDynamicRange(dr)){ + + //EigerSetBitMode(dr); + on_dst = 0; + int i; + for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested + if(Beb_SetUpTransferParameters(dr)) + eiger_dynamicrange = dr; + else printf("ERROR:Could not set bit mode in the back end\n"); + } + } + //make sure back end and front end have the same bit mode + dr= Feb_Control_GetDynamicRange(); + + return dr; +} + + + + +/* parameters - readout */ + +int setSpeed(enum speedVariable arg, int val){ + + if (arg != CLOCK_DIVIDER) + return -1; + + if(val != -1){ + printf(" Setting Read out Speed: %d\n",val); + if(Feb_Control_SetReadoutSpeed(val)) + eiger_readoutspeed = val; + } + return eiger_readoutspeed; +} + + +enum readOutFlags setReadOutFlags(enum readOutFlags val){ + + enum readOutFlags retval = GET_READOUT_FLAGS; + if(val!=GET_READOUT_FLAGS){ + + + if(val&0xF0000){ + switch(val){ + case PARALLEL: val=E_PARALLEL; printf(" Setting Read out Flag: Parallel\n"); break; + case NONPARALLEL: val=E_NON_PARALLEL; printf(" Setting Read out Flag: Non Parallel\n"); break; + case SAFE: val=E_SAFE; printf(" Setting Read out Flag: Safe\n"); break; + + default: + cprintf(RED,"Cannot set unknown readout flag. 0x%x\n", val); + return -1; + } + printf(" Setting Read out Flag: %d\n",val); + if(Feb_Control_SetReadoutMode(val)) + eiger_readoutmode = val; + else return -1; + + }else{ + switch(val){ + case STORE_IN_RAM: val=1; printf(" Setting Read out Flag: Store in Ram\n"); break; + case CONTINOUS_RO: val=0; printf(" Setting Read out Flag: Continuous Readout\n"); break; + + default: + cprintf(RED,"Cannot set unknown readout flag. 0x%x\n", val); + return -1; + } + printf(" Setting store in ram variable: %d\n",val); + eiger_storeinmem = val; + + } + } + + switch(eiger_readoutmode){ + case E_PARALLEL: retval=PARALLEL; break; + case E_NON_PARALLEL: retval=NONPARALLEL; break; + case E_SAFE: retval=SAFE; break; + } + + switch(eiger_storeinmem){ + case 0: retval|=CONTINOUS_RO; break; + case 1: retval|=STORE_IN_RAM; break; + } + printf("Read out Flag: 0x%x\n",retval); + return retval; } @@ -381,7 +458,201 @@ int getNModBoard(enum dimension arg){ -void setDAC(enum detDacIndex ind, int val, int imod, int mV, int retval[]){ + + +/* parameters - timer */ + +int64_t setTimer(enum timerIndex ind, int64_t val){ + + switch(ind){ + case FRAME_NUMBER: + if(val >= 0){ + printf(" Setting number of frames: %d * %d\n",(unsigned int)val,eiger_ncycles); + if(Feb_Control_SetNExposures((unsigned int)val*eiger_ncycles)){ + eiger_nexposures = val; + //SetDestinationParameters(EigerGetNumberOfExposures()*EigerGetNumberOfCycles()); + on_dst = 0; + int i; + for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested + ndsts_in_use = 1; + nimages_per_request = eiger_nexposures * eiger_ncycles; + } + }return eiger_nexposures; + + case ACQUISITION_TIME: + if(val >= 0){ + printf(" Setting exp time: %fs\n",val/(1E9)); + Feb_Control_SetExposureTime(val/(1E9)); + } + return (Feb_Control_GetExposureTime()*(1E9)); + + case SUBFRAME_ACQUISITION_TIME: + if(val >= 0){ + printf(" Setting sub exp time: %lldns\n",(long long int)val/10); + Feb_Control_SetSubFrameExposureTime(val/10); + } + return (Feb_Control_GetSubFrameExposureTime()); + + + case FRAME_PERIOD: + if(val >= 0){ + printf(" Setting acq period: %fs\n",val/(1E9)); + Feb_Control_SetExposurePeriod(val/(1E9)); + } + return (Feb_Control_GetExposurePeriod()*(1E9)); + + case CYCLES_NUMBER: + if(val >= 0){ + printf(" Setting number of triggers: %d * %d\n",(unsigned int)val,eiger_nexposures); + if(Feb_Control_SetNExposures((unsigned int)val*eiger_nexposures)){ + eiger_ncycles = val; + //SetDestinationParameters(EigerGetNumberOfExposures()*EigerGetNumberOfCycles()); + on_dst = 0; + int i; + for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested + nimages_per_request = eiger_nexposures * eiger_ncycles; + } + }return eiger_ncycles; + default: + cprintf(RED,"Warning: Timer Index not implemented for this detector: %d\n", ind); + break; + } + + return -1; +} + + + + + +/* parameters - channel, chip, module, settings */ + + +int setModule(sls_detector_module myMod, int delay){ + int retval[2]; + int i; + + //#ifdef VERBOSE + printf("Setting module with settings %d\n",myMod.reg); + //#endif + + setSettings( (enum detectorSettings)myMod.reg,-1); + + if(setIODelay(delay, -1)!= delay){ + cprintf(RED,"could not set iodelay %d\n",delay); + return FAIL; + } + + //copy module locally + if (detectorModules) + copyModule(detectorModules,&myMod); + + //set dac values + for(i=0;ichanregs[ich++]=tt[ip++]; + } + if (ichip<3) { + ip++; + ip++; + } + } + } + + //copy to local copy as well + if (detectorModules) + copyModule(myMod,detectorModules); + else + return FAIL; + return OK; +} + + + +enum detectorSettings setSettings(enum detectorSettings sett, int imod){ + if(sett == UNINITIALIZED){ + return thisSettings; + }if(sett != GET_SETTINGS) + thisSettings = sett; + printf(" Settings: %d\n", thisSettings); + return thisSettings; +} + +enum detectorSettings getSettings(){ + return thisSettings; +} + + + + + + +/* parameters - threshold */ + +int getThresholdEnergy(int imod){ + printf(" Getting Threshold energy\n"); + return eiger_photonenergy; +} + + +int setThresholdEnergy(int ev, int imod){ + printf(" Setting threshold energy:%d\n",ev); + if(ev >= 0) + eiger_photonenergy = ev; + return getThresholdEnergy(imod); +} + + + + + +/* parameters - dac, adc, hv */ + + +void setDAC(enum DAC_INDEX ind, int val, int imod, int mV, int retval[]){ if(ind == VTHRESHOLD){ int ret[5]; @@ -441,27 +712,7 @@ void setDAC(enum detDacIndex ind, int val, int imod, int mV, int retval[]){ -int setHighVoltage(int val){ - if(val!=-1){ - eiger_highvoltage = val; - if(master){ - int ret = Feb_Control_SetHighVoltage(val); - if(!ret) //could not set - return -2; - else if (ret == -1) //outside range - return -1; - } - } - - if(master && !Feb_Control_GetHighVoltage(&eiger_highvoltage)){ - cprintf(RED,"Warning: Could not read high voltage\n"); - return -3; - } - return eiger_highvoltage; -} - - -int getADC(enum detAdcIndex ind, int imod){ +int getADC(enum ADC_INDEX ind, int imod){ int retval = -1; char tempnames[6][20]={"FPGA EXT", "10GE","DCDC", "SODL", "SODR", "FPGA"}; char cstore[255]; @@ -497,6 +748,156 @@ int getADC(enum detAdcIndex ind, int imod){ } +int setHighVoltage(int val){ + if(val!=-1){ + eiger_highvoltage = val; + if(master){ + int ret = Feb_Control_SetHighVoltage(val); + if(!ret) //could not set + return -2; + else if (ret == -1) //outside range + return -1; + } + } + + if(master && !Feb_Control_GetHighVoltage(&eiger_highvoltage)){ + cprintf(RED,"Warning: Could not read high voltage\n"); + return -3; + } + return eiger_highvoltage; +} + + + + + + + +/* parameters - timing, extsig */ + +enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){ + enum externalCommunicationMode ret=GET_EXTERNAL_COMMUNICATION_MODE; + if(arg != GET_EXTERNAL_COMMUNICATION_MODE){ + switch((int)arg){ + case AUTO_TIMING: ret = 0; break; + case TRIGGER_EXPOSURE: ret = 2; break; + case BURST_TRIGGER: ret = 1; break; + case GATE_FIX_NUMBER: ret = 3; break; + } + printf(" Setting Triggering Mode: %d\n",(int)ret); + if(Feb_Control_SetTriggerMode(ret,1)) + eiger_triggermode = ret; + } + + ret = eiger_triggermode; + switch((int)ret){ + case 0: ret = AUTO_TIMING; break; + case 2: ret = TRIGGER_EXPOSURE; break; + case 1: ret = BURST_TRIGGER; break; + case 3: ret = GATE_FIX_NUMBER; break; + default: + printf("Unknown trigger mode found %d\n",ret); + ret = 0; + } + return ret; +} + + + + + + +/* configure mac */ + + +int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport, int udpport2, int ival){ + if (sourcemac != getDetectorMAC()){ + printf("*************************************************\n"); + printf("WARNING: actual detector mac address %llx does not match the one from client %llx\n",getDetectorMAC(),sourcemac); + sourcemac = getDetectorMAC(); + printf("WARNING: Matched detectormac to the hardware mac now\n"); + printf("*************************************************\n"); + } + //only for 1Gbe + if(!send_to_ten_gig){ + if (sourceip != getDetectorIP()){ + printf("*************************************************\n"); + printf("WARNING: actual detector ip address %x does not match the one from client %x\n",getDetectorIP(),sourceip); + sourceip = getDetectorIP(); + printf("WARNING: Matched detector ip to the hardware ip now\n"); + printf("*************************************************\n"); + } + } + + char src_mac[50], src_ip[50],dst_mac[50], dst_ip[50]; + int src_port = 0xE185; + sprintf(src_ip,"%d.%d.%d.%d",(sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff); + sprintf(dst_ip,"%d.%d.%d.%d",(destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff); + sprintf(src_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((sourcemac>>40)&0xFF), + (unsigned int)((sourcemac>>32)&0xFF), + (unsigned int)((sourcemac>>24)&0xFF), + (unsigned int)((sourcemac>>16)&0xFF), + (unsigned int)((sourcemac>>8)&0xFF), + (unsigned int)((sourcemac>>0)&0xFF)); + sprintf(dst_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((destmac>>40)&0xFF), + (unsigned int)((destmac>>32)&0xFF), + (unsigned int)((destmac>>24)&0xFF), + (unsigned int)((destmac>>16)&0xFF), + (unsigned int)((destmac>>8)&0xFF), + (unsigned int)((destmac>>0)&0xFF)); + + printf("src_port:%d\n",src_port); + printf("src_ip:%s\n",src_ip); + printf("dst_ip:%s\n",dst_ip); + printf("src_mac:%s\n",src_mac); + printf("dst_mac:%s\n",dst_mac); + + + int beb_num = BEB_NUM;//Feb_Control_GetModuleNumber(); + int header_number = 0; + int dst_port = udpport; + if(!top) + dst_port = udpport2; + + printf("dst_port:%d\n\n",dst_port); + + int i=0; + /* for(i=0;i<32;i++){ modified for Aldo*/ + if(Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) && + Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port)) + printf("set up left ok\n"); + else return -1; + /*}*/ + + header_number = 32; + dst_port = udpport2; + if(!top) + dst_port = udpport; + printf("dst_port:%d\n\n",dst_port); + + /*for(i=0;i<32;i++){*//** modified for Aldo*/ + if(Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) && + Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port)) + printf("set up right ok\n\n"); + else return -1; + /*}*/ + + on_dst = 0; + + for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested + nimages_per_request=eiger_nexposures * eiger_ncycles; + + return 0; +} + + + + + + + +/* eiger specific - iodelay, 10g, pulse, rate, temp, activate, delay nw parameter */ + int setIODelay(int val, int imod){ if(val!=-1){ printf(" Setting IO Delay: %d\n",val); @@ -611,6 +1012,11 @@ int getDefaultSettingsTau_in_nsec(){ return default_tau_from_file; } +void setDefaultSettingsTau_in_nsec(int t){ + default_tau_from_file = t; + printf("Default tau set to %d\n",default_tau_from_file); +} + int64_t getCurrentTau(){ if(!getRateCorrectionEnable()) return 0; @@ -618,123 +1024,60 @@ int64_t getCurrentTau(){ return Feb_Control_Get_RateTable_Tau_in_nsec(); } -void setDefaultSettingsTau_in_nsec(int t){ - default_tau_from_file = t; - printf("Default tau set to %d\n",default_tau_from_file); +void setExternalGating(int enable[]){ + if(enable>=0){ + Feb_Control_SetExternalEnableMode(enable[0], enable[1]);//enable = 0 or 1, polarity = 0 or 1 , where 1 is positive + eiger_extgating = enable[0]; + eiger_extgatingpolarity = enable[1]; + } + enable[0] = eiger_extgating; + enable[1] = eiger_extgatingpolarity; } -int setModule(sls_detector_module myMod, int delay){ - int retval[2]; - int i; - - //#ifdef VERBOSE - printf("Setting module with settings %d\n",myMod.reg); - //#endif - - setSettings( (enum detectorSettings)myMod.reg,-1); - - if(setIODelay(delay, -1)!= delay){ - cprintf(RED,"could not set iodelay %d\n",delay); +int setAllTrimbits(int val){ + int ichan; + if(!Feb_Control_SaveAllTrimbitsTo(val)){ + cprintf(RED,"error in setting all trimbits to value\n"); return FAIL; - } - - //copy module locally - if (detectorModules) - copyModule(detectorModules,&myMod); - - //set dac values - for(i=0;ireg,val); +#endif + if (detectorModules){ + for (ichan=0; ichan<(detectorModules->nchan); ichan++) { + *((detectorModules->chanregs)+ichan)=val; } } } - - //set trimbits - if(!Feb_Control_SetTrimbits(Feb_Control_GetModuleNumber(),tt)){ - cprintf(BG_RED,"Could not set trimbits\n"); - return FAIL; - } - - return thisSettings; -} - - -int getModule(sls_detector_module *myMod){ - int i; - int retval[2]; - - //dacs - for(i=0;ichanregs[ich++]=tt[ip++]; - } - if (ichip<3) { - ip++; - ip++; - } - } - } - - //copy to local copy as well - if (detectorModules) - copyModule(myMod,detectorModules); - else - return FAIL; return OK; } +int getAllTrimbits(){ + return *((detectorModules->chanregs)); +} +int getBebFPGATemp(){ + return Beb_GetBebFPGATemp(); +} +int activate(int enable){ + int ret = Beb_Activate(enable); + Feb_Control_activate(ret); + return ret; +} - - -int getThresholdEnergy(int imod){ - printf(" Getting Threshold energy\n"); - return eiger_photonenergy; +int setNetworkParameter(enum detNetworkParameter mode, int value){ + return Beb_SetNetworkParameter(mode, value); } -int setThresholdEnergy(int ev, int imod){ - printf(" Setting threshold energy:%d\n",ev); - if(ev >= 0) - eiger_photonenergy = ev; - return getThresholdEnergy(imod); -} -enum detectorSettings setSettings(enum detectorSettings sett, int imod){ - if(sett == UNINITIALIZED){ - return thisSettings; - }if(sett != GET_SETTINGS) - thisSettings = sett; - printf(" Settings: %d\n", thisSettings); - return thisSettings; -} -enum detectorSettings getSettings(){ - return thisSettings; -} + + + +/* aquisition */ + int startReceiver(int d){ @@ -858,271 +1201,8 @@ void readFrame(int *ret, char *mess){ -int64_t setTimer(enum timerIndex ind, int64_t val){ - switch(ind){ - case FRAME_NUMBER: - if(val >= 0){ - printf(" Setting number of frames: %d * %d\n",(unsigned int)val,eiger_ncycles); - if(Feb_Control_SetNExposures((unsigned int)val*eiger_ncycles)){ - eiger_nexposures = val; - //SetDestinationParameters(EigerGetNumberOfExposures()*EigerGetNumberOfCycles()); - on_dst = 0; - int i; - for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested - ndsts_in_use = 1; - nimages_per_request = eiger_nexposures * eiger_ncycles; - } - }return eiger_nexposures; - - case ACQUISITION_TIME: - if(val >= 0){ - printf(" Setting exp time: %fs\n",val/(1E9)); - Feb_Control_SetExposureTime(val/(1E9)); - } - return (Feb_Control_GetExposureTime()*(1E9)); - - case SUBFRAME_ACQUISITION_TIME: - if(val >= 0){ - printf(" Setting sub exp time: %lldns\n",(long long int)val/10); - Feb_Control_SetSubFrameExposureTime(val/10); - } - return (Feb_Control_GetSubFrameExposureTime()); - - - case FRAME_PERIOD: - if(val >= 0){ - printf(" Setting acq period: %fs\n",val/(1E9)); - Feb_Control_SetExposurePeriod(val/(1E9)); - } - return (Feb_Control_GetExposurePeriod()*(1E9)); - /* case DELAY_AFTER_TRIGGER: - if(val >= 0) - EigerSetNumberOfExposures((unsigned int)val); - return EigerGetNumberOfExposures(); - - case GATES_NUMBER: - if(val >= 0) - EigerSetNumberOfGates((unsigned int)val); - return EigerGetNumberOfGates(); - - case PROBES_NUMBER: - if(val >= 0) - EigerSetNumberOfExposures((unsigned int)val); - return EigerGetNumberOfExposures();*/ - case CYCLES_NUMBER: - if(val >= 0){ - printf(" Setting number of triggers: %d * %d\n",(unsigned int)val,eiger_nexposures); - if(Feb_Control_SetNExposures((unsigned int)val*eiger_nexposures)){ - eiger_ncycles = val; - //SetDestinationParameters(EigerGetNumberOfExposures()*EigerGetNumberOfCycles()); - on_dst = 0; - int i; - for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested - nimages_per_request = eiger_nexposures * eiger_ncycles; - } - }return eiger_ncycles; - default: - printf("unknown timer index: %d\n",ind); - break; - } - - return -1; -} - - - - -int64_t getTimeLeft(enum timerIndex ind){ - - return -1; -} - - - -int setDynamicRange(int dr){ - if(dr > 0){ - printf(" Setting dynamic range: %d\n",dr); - if(Feb_Control_SetDynamicRange(dr)){ - - //EigerSetBitMode(dr); - on_dst = 0; - int i; - for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested - if(Beb_SetUpTransferParameters(dr)) - eiger_dynamicrange = dr; - else printf("ERROR:Could not set bit mode in the back end\n"); - } - } - //make sure back end and front end have the same bit mode - dr= Feb_Control_GetDynamicRange(); - - return dr; -} - - - -enum readOutFlags setReadOutFlags(enum readOutFlags val){ - - enum readOutFlags retval = GET_READOUT_FLAGS; - if(val!=GET_READOUT_FLAGS){ - - - if(val&0xF0000){ - switch(val){ - case PARALLEL: val=E_PARALLEL; printf(" Setting Read out Flag: Parallel\n"); break; - case NONPARALLEL: val=E_NON_PARALLEL; printf(" Setting Read out Flag: Non Parallel\n"); break; - case SAFE: val=E_SAFE; printf(" Setting Read out Flag: Safe\n"); break; - - default: - cprintf(RED,"Cannot set unknown readout flag. 0x%x\n", val); - return -1; - } - printf(" Setting Read out Flag: %d\n",val); - if(Feb_Control_SetReadoutMode(val)) - eiger_readoutmode = val; - else return -1; - - }else{ - switch(val){ - case STORE_IN_RAM: val=1; printf(" Setting Read out Flag: Store in Ram\n"); break; - case CONTINOUS_RO: val=0; printf(" Setting Read out Flag: Continuous Readout\n"); break; - - default: - cprintf(RED,"Cannot set unknown readout flag. 0x%x\n", val); - return -1; - } - printf(" Setting store in ram variable: %d\n",val); - eiger_storeinmem = val; - - } - } - - switch(eiger_readoutmode){ - case E_PARALLEL: retval=PARALLEL; break; - case E_NON_PARALLEL: retval=NONPARALLEL; break; - case E_SAFE: retval=SAFE; break; - } - - switch(eiger_storeinmem){ - case 0: retval|=CONTINOUS_RO; break; - case 1: retval|=STORE_IN_RAM; break; - } - printf("Read out Flag: 0x%x\n",retval); - return retval; -} - - - - -int setROI(int n, ROI arg[], int *retvalsize, int *ret){ - return FAIL; -} - - - -int setSpeed(enum speedVariable arg, int val){ - if(val != -1){ - printf(" Setting Read out Speed: %d\n",val); - if(Feb_Control_SetReadoutSpeed(val)) - eiger_readoutspeed = val; - } - return eiger_readoutspeed; -} - - - -int executeTrimming(enum trimMode mode, int par1, int par2, int imod){ - return FAIL; -} - -int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int udpport, int udpport2, int ival){ - if (sourcemac != getDetectorMAC()){ - printf("*************************************************\n"); - printf("WARNING: actual detector mac address %llx does not match the one from client %llx\n",getDetectorMAC(),sourcemac); - sourcemac = getDetectorMAC(); - printf("WARNING: Matched detectormac to the hardware mac now\n"); - printf("*************************************************\n"); - } - //only for 1Gbe - if(!send_to_ten_gig){ - if (sourceip != getDetectorIP()){ - printf("*************************************************\n"); - printf("WARNING: actual detector ip address %x does not match the one from client %x\n",getDetectorIP(),sourceip); - sourceip = getDetectorIP(); - printf("WARNING: Matched detector ip to the hardware ip now\n"); - printf("*************************************************\n"); - } - } - - char src_mac[50], src_ip[50],dst_mac[50], dst_ip[50]; - int src_port = 0xE185; - sprintf(src_ip,"%d.%d.%d.%d",(sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff); - sprintf(dst_ip,"%d.%d.%d.%d",(destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff); - sprintf(src_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((sourcemac>>40)&0xFF), - (unsigned int)((sourcemac>>32)&0xFF), - (unsigned int)((sourcemac>>24)&0xFF), - (unsigned int)((sourcemac>>16)&0xFF), - (unsigned int)((sourcemac>>8)&0xFF), - (unsigned int)((sourcemac>>0)&0xFF)); - sprintf(dst_mac,"%02x:%02x:%02x:%02x:%02x:%02x",(unsigned int)((destmac>>40)&0xFF), - (unsigned int)((destmac>>32)&0xFF), - (unsigned int)((destmac>>24)&0xFF), - (unsigned int)((destmac>>16)&0xFF), - (unsigned int)((destmac>>8)&0xFF), - (unsigned int)((destmac>>0)&0xFF)); - - printf("src_port:%d\n",src_port); - printf("src_ip:%s\n",src_ip); - printf("dst_ip:%s\n",dst_ip); - printf("src_mac:%s\n",src_mac); - printf("dst_mac:%s\n",dst_mac); - - - int beb_num = BEB_NUM;//Feb_Control_GetModuleNumber(); - int header_number = 0; - int dst_port = udpport; - if(!top) - dst_port = udpport2; - - printf("dst_port:%d\n\n",dst_port); - - int i=0; - /* for(i=0;i<32;i++){ modified for Aldo*/ - if(Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) && - Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port)) - printf("set up left ok\n"); - else return -1; - /*}*/ - - header_number = 32; - dst_port = udpport2; - if(!top) - dst_port = udpport; - printf("dst_port:%d\n\n",dst_port); - - /*for(i=0;i<32;i++){*//** modified for Aldo*/ - if(Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) && - Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port)) - printf("set up right ok\n\n"); - else return -1; - /*}*/ - - on_dst = 0; - - for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested - nimages_per_request=eiger_nexposures * eiger_ncycles; - - return 0; -} - - -int calculateDataBytes(){ - if(send_to_ten_gig) - return setDynamicRange(-1)*16*TEN_GIGA_BUFFER_SIZE; - else - return setDynamicRange(-1)*16*ONE_GIGA_BUFFER_SIZE; -} +/* common */ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){ @@ -1202,15 +1282,22 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){ } +int calculateDataBytes(){ + if(send_to_ten_gig) + return setDynamicRange(-1) * ONE_GIGA_CONSTANT * TEN_GIGA_BUFFER_SIZE; + else + return setDynamicRange(-1) * TEN_GIGA_CONSTANT * ONE_GIGA_BUFFER_SIZE; +} -int getTotalNumberOfChannels(){return getNumberOfChannelsPerModule();} -int getTotalNumberOfChips(){return NCHIP;} -int getTotalNumberOfModules(){return 1;} -int getNumberOfChannelsPerChip(){return NCHAN;} + +int getTotalNumberOfChannels(){return getNumberOfChannelsPerModule() * getTotalNumberOfModules;} +int getTotalNumberOfChips(){return getNumberOfChipsPerModule * getTotalNumberOfModules;} +int getTotalNumberOfModules(){return NMOD;} int getNumberOfChannelsPerModule(){return getNumberOfChannelsPerChip() * getTotalNumberOfChips();} int getNumberOfChipsPerModule(){return NCHIP;} int getNumberOfDACsPerModule(){return NDAC;} int getNumberOfADCsPerModule(){return NADC;} +int getNumberOfChannelsPerChip(){return NCHAN;} int getNumberOfGainsPerModule(){return NGAIN;} int getNumberOfOffsetsPerModule(){return NOFFSET;} @@ -1218,66 +1305,10 @@ int getNumberOfOffsetsPerModule(){return NOFFSET;} -enum externalSignalFlag getExtSignal(int signalindex){ - return GET_EXTERNAL_SIGNAL_FLAG; -} - - - - - -enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag){ - return getExtSignal(signalindex); -} - - - - - - -enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){ - enum externalCommunicationMode ret=GET_EXTERNAL_COMMUNICATION_MODE; - if(arg != GET_EXTERNAL_COMMUNICATION_MODE){ - switch((int)arg){ - case AUTO_TIMING: ret = 0; break; - case TRIGGER_EXPOSURE: ret = 2; break; - case BURST_TRIGGER: ret = 1; break; - case GATE_FIX_NUMBER: ret = 3; break; - } - printf(" Setting Triggering Mode: %d\n",(int)ret); - if(Feb_Control_SetTriggerMode(ret,1)) - eiger_triggermode = ret; - } - - ret = eiger_triggermode; - switch((int)ret){ - case 0: ret = AUTO_TIMING; break; - case 2: ret = TRIGGER_EXPOSURE; break; - case 1: ret = BURST_TRIGGER; break; - case 3: ret = GATE_FIX_NUMBER; break; - default: - printf("Unknown trigger mode found %d\n",ret); - ret = 0; - } - return ret; -} - - -void setExternalGating(int enable[]){ - if(enable>=0){ - Feb_Control_SetExternalEnableMode(enable[0], enable[1]);//enable = 0 or 1, polarity = 0 or 1 , where 1 is positive - eiger_extgating = enable[0]; - eiger_extgatingpolarity = enable[1]; - } - enable[0] = eiger_extgating; - enable[1] = eiger_extgatingpolarity; -} +/* sync */ enum masterFlags setMaster(enum masterFlags arg){ - //if(arg != GET_MASTER) - // masterMode = arg; - return NO_MASTER; } @@ -1287,42 +1318,10 @@ enum synchronizationMode setSynchronization(enum synchronizationMode arg){ return NO_SYNCHRONIZATION; } -int setAllTrimbits(int val){ - int ichan; - if(!Feb_Control_SaveAllTrimbitsTo(val)){ - cprintf(RED,"error in setting all trimbits to value\n"); - return FAIL; - }else{ -#ifdef VERBOSE - printf("Copying register %x value %d\n",destMod->reg,val); -#endif - if (detectorModules){ - for (ichan=0; ichan<(detectorModules->nchan); ichan++) { - *((detectorModules->chanregs)+ichan)=val; - } - } - } - return OK; -} - -int getAllTrimbits(){ - return *((detectorModules->chanregs)); -} - -int getBebFPGATemp(){ - return Beb_GetBebFPGATemp(); -} -int activate(int enable){ - int ret = Beb_Activate(enable); - Feb_Control_activate(ret); - return ret; -} -int setNetworkParameter(enum detNetworkParameter mode, int value){ - return Beb_SetNetworkParameter(mode, value); -} + #endif diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h index 2919ed968..6026fff00 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h @@ -8,46 +8,76 @@ #ifndef SLSDETECTORSERVER_DEFS_H_ #define SLSDETECTORSERVER_DEFS_H_ -//#include "sls_detector_defs.h" +#include "sls_detector_defs.h" #include -#define GOODBYE -200 +#define GOODBYE (-200) +#define REQUIRED_FIRMWARE_VERSION (16) -#define FEB_PORT 43210 -#define BEB_PORT 43212 - -#define REQUIRED_FIRMWARE_VERSION 16 - -#define FIRMWAREREV 0xcaba //temporary should be in firmware +/* Enums */ +enum CLK_SPEED_INDEX {FULL_SPEED, HALF_SPEED, QUARTER_SPEED}; +enum DAC_INDEX {SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS,VTHRESHOLD}; +#define DEFAULT_DAC_VALS[16] { \ + 0, /* SvP */ \ + 2480, /* Vtr */ \ + 3300, /* Vrf */ \ + 1400, /* Vrs */ \ + 4000, /* SvN */ \ + 2556, /* Vtgstv */ \ + 1000, /* Vcmp_ll */ \ + 1000, /* Vcmp_lr */ \ + 4000, /* cal */ \ + 1000, /* Vcmp_rl */ \ + 1100, /* rxb_rb */ \ + 1100, /* rxb_lb */ \ + 1000, /* Vcmp_rr */ \ + 1000, /* Vcp */ \ + 2000, /* Vcn */ \ + 1550 /* Vis */ \ + }; +enum ADC_INDEX {TEMP_FPGAEXT, TEMP_10GE, TEMP_DCDC, TEMP_SODL, TEMP_SODR, TEMP_FPGA, TEMP_FPGAFEBL, TEMP_FPGAFEBR}; +enum NETWORK_PARA_INDEX {TXN_LEFT, TXN_RIGHT, TXN_FRAME,FLOWCTRL_10G}; -#define NCHAN 256*256 -#define NCHIP 4 -#define NDAC 16 -#define NADC 0 -#define NGAIN 0 -#define NOFFSET 0 - -#define NMAXMODX 1 -#define NMAXMODY 1 -#define NMAXMOD NMAXMODX*NMAXMODY -#define NCHANS NCHAN*NCHIP*NMAXMOD -#define NDACS NDAC*NMAXMOD +/* Hardware Definitions */ +#define NMAXMOD (1) +#define NMOD (1) +#define NCHAN (256 * 256) +#define NCHIP (4) +#define NADC (0) +#define NDAC (16) +#define NGAIN (0) +#define NOFFSET (0) -#define DYNAMIC_RANGE 16 +#define TEN_GIGA_BUFFER_SIZE (4112) +#define ONE_GIGA_BUFFER_SIZE (1040) +#define TEN_GIGA_CONSTANT (4) +#define ONE_GIGA_CONSTANT (16) +#define NORMAL_HIGHVOLTAGE_INPUTPORT "/sys/class/hwmon/hwmon5/device/in0_input" +#define NORMAL_HIGHVOLTAGE_OUTPUTPORT "/sys/class/hwmon/hwmon5/device/out0_output" +#define SPECIAL9M_HIGHVOLTAGE_PORT "/dev/ttyS1" +#define SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE (16) +/** Default Parameters */ +#define DEFAULT_MOD_INDEX (0) +#define DEFAULT_NUM_FRAMES (1) +#define DEFAULT_NUM_CYCLES (1) +#define DEFAULT_EXPTIME (1E9) //ns +#define DEFAULT_PERIOD (1E9) //ns +#define DEFAULT_DELAY (0) +#define DEFAULT_HIGH_VOLTAGE (0) +#define DEFAULT_SETTINGS (DYNAMICGAIN) +#define DEFAULT_SUBFRAME_EXPOSURE_VAL (2621440) // 2.6ms +#define DEFAULT_DYNAMIC_RANGE (16) +#define DEFAULT_READOUT_FLAG (NONPARALLEL) +#define DEFAULT_CLK_SPEED (HALF_SPEED) +#define DEFAULT_IO_DELAY (650) +#define DEFAULT_TIMING_MODE (AUTO_TIMING) +#define DEFAULT_PHOTON_ENERGY (-1) +#define DEFAULT_RATE_CORRECTION (0) -enum detDacIndex{SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS,VTHRESHOLD}; - -enum detAdcIndex{TEMP_FPGAEXT, TEMP_10GE, TEMP_DCDC, TEMP_SODL, TEMP_SODR, TEMP_FPGA, TEMP_FPGAFEBL, TEMP_FPGAFEBR}; - -enum detNetworkParameter{TXN_LEFT, TXN_RIGHT, TXN_FRAME,FLOWCTRL_10G}; - -#define NORMAL_HIGHVOLTAGE_INPUTPORT "/sys/class/hwmon/hwmon5/device/in0_input" -#define NORMAL_HIGHVOLTAGE_OUTPUTPORT "/sys/class/hwmon/hwmon5/device/out0_output" -#define SPECIAL9M_HIGHVOLTAGE_PORT "/dev/ttyS1" -#define SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE 16 +#define MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS (0x1FFFFFFF) /** 29 bit register for max subframe exposure value */ diff --git a/slsDetectorSoftware/jungfrauDetectorServerNewStructure/RegisterDefs.h b/slsDetectorSoftware/jungfrauDetectorServerNewStructure/RegisterDefs.h index b179e8230..5378eabd9 100644 --- a/slsDetectorSoftware/jungfrauDetectorServerNewStructure/RegisterDefs.h +++ b/slsDetectorSoftware/jungfrauDetectorServerNewStructure/RegisterDefs.h @@ -84,6 +84,9 @@ #define GET_PERIOD_LSB_REG (0x18 << 11) #define GET_PERIOD_MSB_REG (0x19 << 11) +/** Get Temperature Carlos, incorrectl as get gates */ +#define GET_TEMPERATURE_TMP112_REG (0x1c << 11) // in 10ths of millidegrees of TMP112 + /* Get Frames from Start 64 bit register (frames from start Run Control) */ #define FRAMES_FROM_START_PG_LSB_REG (0x24 << 11) #define FRAMES_FROM_START_PG_MSB_REG (0x25 << 11) diff --git a/slsDetectorSoftware/jungfrauDetectorServerNewStructure/slsDetectorFunctionList.c b/slsDetectorSoftware/jungfrauDetectorServerNewStructure/slsDetectorFunctionList.c index 400114abc..003f8a02c 100644 --- a/slsDetectorSoftware/jungfrauDetectorServerNewStructure/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/jungfrauDetectorServerNewStructure/slsDetectorFunctionList.c @@ -6,6 +6,7 @@ #include "slsDetectorFunctionList.h" #include "gitInfoJungfrau.h" +#include "slsDetectorServer_defs.h" //also include RegisterDefs.h @@ -208,7 +209,6 @@ u_int16_t getHardwareSerialNumber() { return ((bus_r(MOD_SERIAL_NUM_REG) & HARDWARE_SERIAL_NUM_MSK) >> HARDWARE_SERIAL_NUM_OFST); } - u_int32_t getDetectorNumber(){ return bus_r(MOD_SERIAL_NUM_REG); } @@ -396,7 +396,7 @@ void FPGATouchFlash(){ -/* set up detector*/ +/* set up detector */ void allocateDetectorStructureMemory(){ printf("This Server is for 1 Jungfrau module (500k)\n"); @@ -475,7 +475,7 @@ void setupDetector() { setTimer(FRAME_PERIOD, DEFAULT_PERIOD); setTimer(DELAY_AFTER_TRIGGER, DEFAULT_DELAY); /*setSpeed(CLOCK_DIVIDER, HALF_SPEED); depends if all the previous stuff works*/ - setTiming(AUTO_TIMING); + setTiming(DEFAULT_TIMING_MODE); setHighVoltage(DEFAULT_HIGH_VOLTAGE); } @@ -576,6 +576,7 @@ int setDynamicRange(int dr){ /* parameters - readout */ + int setSpeed(enum speedVariable arg, int val) { if (arg != CLOCK_DIVIDER) @@ -587,7 +588,7 @@ int setSpeed(enum speedVariable arg, int val) { switch(val){ // stop state machine if running - if(((bus_r(STATUS_REG) & RUN_BUSY_MSK) >> RUN_BUSY_OFST)) + if(runBusy()) stopStateMachine(); // todo in firmware, for now setting half speed @@ -767,7 +768,7 @@ int setModule(sls_detector_module myMod){ //set dac values for(i=0;i=0)&&((int)ind= 0) - printf("Setting dac %d: %s to %d ",ind, iname,val); + if (numbitstosend == 16) + printf("Writing to ADC SPI Register: 0x%04x\n",val); else - printf("Getting dac %d: %s ",ind, iname); - if(mV) - printf("in mV\n"); - else - printf("in dac units\n"); + printf("Writing to SPI Register: 0x%08x\n", val); #endif - if(val >= 0) - Feb_Control_SetDAC(iname,val,mV); - int k; - Feb_Control_GetDAC(iname, &k,0); - retval[0] = k; - Feb_Control_GetDAC(iname,&k,1); - retval[1] = k; - (detectorModules)->dacs[ind] = retval[0]; + u_int16_t valw; + // start point + valw = 0xffff; /**todo testwith old board 0xff for adc_spi */ // old board compatibility (not using specific bits) + bus_w16 (addr, valw); + + // chip sel bar down + valw &= ~csmask; /* todo with test: done a bit different, not with previous value */ + bus_w16 (addr, valw); + + { + int i = 0; + for (i = 0; i < numbitstosend; ++i) { + + // clk down + valw &= ~clkmask; + bus_w16 (addr, valw); + + // write data (i) + valw = ((valw & ~digoutmask) + // unset bit + (((val >> (numbitstosend - 1 - i)) & 0x1) << digofset)); // each bit from val starting from msb + bus_w16 (addr, valw); + + // clk up + valw |= clkmask ; + bus_w16 (addr, valw); + } + } + + // chip sel bar up + valw |= csmask; /* todo with test: not done for spi */ + bus_w16 (addr, valw); + + //clk down + valw &= ~clkmask; + bus_w16 (addr, valw); + + // stop point = start point of course + valw = 0xffff; /**todo testwith old board 0xff for adc_spi */ // old board compatibility (not using specific bits) + bus_w16 (addr, valw); + + printf("\n"); +} + + + +void initDac(int dacnum) { + printf("\n Initializing dac for %d to \n",dacnum); + + u_int32_t codata; + int csdx = dacnum / NDAC + DAC_SERIAL_CS_OUT_OFST; // old board (16 dacs),so can be DAC_SERIAL_CS_OUT_OFST or +1 + int dacchannel = 0xf; // all channels + int dacvalue = 0x6; // can be any random value (just writing to power up) + printf("Write to Input Register\n" + "Chip select bit:%d\n" + "Dac Channel:0x%x\n3" + "Dac Value:0x%x", + csdx, dacchannel, dacvalue); + + codata = LTC2620_DAC_CMD_WRITE + // command to write to input register + ((dacchannel << LTC2620_DAC_ADDR_OFST) & LTC2620_DAC_ADDR_MSK) + // all channels + ((dacvalue << LTC2620_DAC_DATA_OFST) & LTC2620_DAC_DATA_MSK); // any random value + serializeToSPI(SPI_REG, codata, (0x1 << csdx), LTC2620_DAC_NUMBITS, + DAC_SERIAL_CLK_OUT_MSK, DAC_SERIAL_DIGITAL_OUT_MSK, DAC_SERIAL_DIGITAL_OUT_OFST); +} + + + +void prepareADC(){ + printf("Preparing ADC\n"); + + //power mode reset + setAdc(AD9257_POWER_MODE_REG, + (AD9257_INT_RESET_VAL << AD9257_POWER_INTERNAL_OFST) & AD9257_POWER_INTERNAL_MSK); + //power mode chip run + setAdc(AD9257_POWER_MODE_REG, + (AD9257_INT_CHIP_RUN_VAL << AD9257_POWER_INTERNAL_OFST) & AD9257_POWER_INTERNAL_MSK); + + //output clock phase + setAdc(AD9257_OUT_PHASE_REG, + (AD9257_OUT_CLK_60_VAL << AD9257_OUT_CLK_OFST) & AD9257_OUT_CLK_MSK); + + // lvds-iee reduced , binary offset + setAdc(AD9257_OUT_MODE_REG, + (AD9257_OUT_LVDS_IEEE_VAL << AD9257_OUT_LVDS_OPT_OFST) & AD9257_OUT_LVDS_OPT_MSK); + + // all devices on chip to receive next command + setAdc(AD9257_DEV_IND_2_REG, + AD9257_CHAN_H_MSK | AD9257_CHAN_G_MSK | AD9257_CHAN_F_MSK | AD9257_CHAN_E_MSK); + setAdc(AD9257_DEV_IND_1_REG, + AD9257_CHAN_D_MSK | AD9257_CHAN_C_MSK | AD9257_CHAN_B_MSK | AD9257_CHAN_A_MSK | + AD9257_CLK_CH_DCO_MSK | AD9257_CLK_CH_IFCO_MSK); + + // vref 1.33 + setAdc(AD9257_VREF_REG, + (AD9257_VREF_1_33_VAL << AD9257_VREF_OFST) & AD9257_VREF_MSK); + + // no test mode + setAdc(AD9257_TEST_MODE_REG, + (AD9257_NONE_VAL << AD9257_OUT_TEST_OFST) & AD9257_OUT_TEST_MSK); + +#ifdef TESTADC + printf("***************************************** *******\n"); + printf("******* PUTTING ADC IN TEST MODE!!!!!!!!! *******\n"); + printf("***************************************** *******\n"); + // mixed bit frequency test mode + setAdc(AD9257_TEST_MODE_REG, + (AD9257_MIXED_BIT_FREQ_VAL << AD9257_OUT_TEST_OFST) & AD9257_OUT_TEST_MSK); +#endif +} + + + +void setAdc(int addr, int val) { + + u_int32_t codata; + codata = val + (addr << 8); + printf("\n Setting Adc spi register. Addr: 0x%04x Value: 0x%04x\n", addr, val); + serializeToSPI(ADC_SPI_REG, codata, ADC_SERIAL_CS_OUT_MSK, AD9257_ADC_NUMBITS, + ADC_SERIAL_CLK_OUT_MSK, ADC_SERIAL_DATA_OUT_MSK, ADC_SERIAL_DATA_OUT_OFST); +} + + +int voltageToDac(int value){ + int vmin = 0; + int vmax = 2500; + int nsteps = 4096; + if ((value < vmin) || (value > vmax)) return -1; + return (int)(((value - vmin) / (vmax - vmin)) * (nsteps - 1) + 0.5); +} + +int dacToVoltage(unsigned int digital){ + int vmin = 0; + int vmax = 2500; + int nsteps = 4096; + int v = vmin + (vmax - vmin) * digital / (nsteps - 1); + if((v < 0) || (v > nsteps - 1)) + return -1; + return v; +} + + + +void setDAC(enum DAC_INDEX ind, int val, int imod, int mV, int retval[]){ + + //if set and mv, convert to dac + if (val > 0 && mV) + val = voltageToDac(val); //gives -1 on error + + + if ( (val >= 0) || (val == -100)) { + u_int32_t codata; + int csdx = dacnum / NDAC + DAC_SERIAL_CS_OUT_OFST; // old board (16 dacs),so can be DAC_SERIAL_CS_OUT_OFST or +1 + int dacchannel = dacnum % NDAC; // 0-8, dac channel number (also for dacnum 9-15 in old board) + + printf("\n Setting of DAC %d with value %d\n",dacnum, dacvalue); + // command + if (dacvalue >= 0) { + printf("Write to Input Register and Update\n"); + codata = LTC2620_DAC_CMD_SET; + + } else if (dacvalue == -100) { + printf("POWER DOWN\n"); + codata = LTC2620_DAC_CMD_POWER_DOWN; + } + // address + printf("Chip select bit:%d\n" + "Dac Channel:0x%x\n3" + "Dac Value:0x%x", + csdx, dacchannel, dacvalue); + codata += ((dacchannel << LTC2620_DAC_ADDR_OFST) & LTC2620_DAC_ADDR_MSK) + + ((dacvalue << LTC2620_DAC_DATA_OFST) & LTC2620_DAC_DATA_MSK); + // to spi + serializeToSPI(SPI_REG, codata, (0x1 << csdx), LTC2620_DAC_NUMBITS, + DAC_SERIAL_CLK_OUT_MSK, DAC_SERIAL_DIGITAL_OUT_MSK, DAC_SERIAL_DIGITAL_OUT_OFST); + + dacValues[dacnum] = dacvalue; + } + + printf("\nGetting DAC %d\n",dacnum); + retval[0] = dacValues[dacnum]; + retval[1] = dacToVoltage(retval[0]); +} + + +int getADC(enum ADC_INDEX ind, int imod){ + + char tempnames[2][20]={"VRs/FPGAs Temperature", "ADCs/ASICs Temperature"}; + printf("Getting Temperature for %s\n",tempnames[ind]); + u_int32_t addr = GET_TEMPERATURE_TMP112_REG; + u_int32_t val = 0; + int retval = -1; + + for(int i = 0; i < 10; i++) { + switch((int)ind){ + + case TEMP_FPGA: + val = (val<<1) + ((bus_r(GET_TEMPERATURE_TMP112_REG) & (2)) >> 1); + break; + case TEMPADC: + val= (val<<1) + (bus_r(GET_TEMPERATURE_TMP112_REG) & (1)); + break; + } + } + /** or just read it */ + retval = ((int)tempVal) / 4.0; + + printf("Temperature %s: %.2f°C\n",tempnames[ind],retval); + + return retval; } @@ -952,158 +1114,34 @@ int setHighVoltage(int val){ } -int getADC(enum detAdcIndex ind, int imod){ - int retval = -1; - char tempnames[6][20]={"FPGA EXT", "10GE","DCDC", "SODL", "SODR", "FPGA"}; - char cstore[255]; - switch(ind){ - case TEMP_FPGA: - retval=getBebFPGATemp()*1000; - break; - case TEMP_FPGAFEBL: - retval=Feb_Control_GetLeftFPGATemp(); - break; - case TEMP_FPGAFEBR: - retval=Feb_Control_GetRightFPGATemp(); - break; - case TEMP_FPGAEXT: - case TEMP_10GE: - case TEMP_DCDC: - case TEMP_SODL: - case TEMP_SODR: - sprintf(cstore,"more /sys/class/hwmon/hwmon%d/device/temp1_input",ind); - FILE* sysFile = popen(cstore, "r"); - fgets(cstore, sizeof(cstore), sysFile); - pclose(sysFile); - sscanf(cstore,"%d",&retval); - break; + + + +/* parameters - timing, extsig */ + + +enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){ + + if(arg != GET_EXTERNAL_COMMUNICATION_MODE){ + switch((int)arg){ + case AUTO_TIMING: bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) & ~EXT_SIGNAL_MSK); break; + case TRIGGER_EXPOSURE: bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) | EXT_SIGNAL_MSK); break; default: - return -1; - } - - printf("Temperature %s: %f°C\n",tempnames[ind],(double)retval/1000.00); - - return retval; -} - - - - - - - - -int startStateMachine(){ - printf("*******Starting State Machine*******\n"); - - cleanFifos(); - - //start state machine - bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_START_ACQ_MSK); - bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_START_ACQ_MSK); - - printf("Status Register: %08x\n",bus_r(STATUS_REG)); -} - - -int stopStateMachine(){ - cprintf(BG_RED,"*******Stopping State Machine*******\n"); - - //stop state machine - bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STOP_ACQ_MSK); - usleep(100); - bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_STOP_ACQ_MSK); - - printf("Status Register: %08x\n",bus_r(STATUS_REG)); - return OK; -} - - - - - -enum runStatus getRunStatus(){ -#ifdef VERBOSE - printf("Getting status\n"); -#endif - - enum runStatus s; - u_int32_t retval = bus_r(STATUS_REG); - printf("Status Register: %08x\n",retval); - - //running - if(((retval & RUN_BUSY_MSK) >> RUN_BUSY_OFST)) { - if ((retval & WAITING_FOR_TRIGGER_MSK) >> WAITING_FOR_TRIGGER_OFST) { - printf("-----------------------------------WAITING-----------------------------------\n"); - s=WAITING; - } - else{ - printf("-----------------------------------RUNNING-----------------------------------\n"); - s=RUNNING; + cprintf(RED,"Unknown timing mode %d\n", arg); + return GET_EXTERNAL_COMMUNICATION_MODE; } } - - //not running - else { - if ((retval & STOPPED_MSK) >> STOPPED_OFST) { - printf("-----------------------------------STOPPED--------------------------\n"); - s=STOPPED; - } else if ((retval & RUNMACHINE_BUSY_MSK) >> RUNMACHINE_BUSY_OFST) { - printf("-----------------------------------READ MACHINE BUSY--------------------------\n"); - s=TRANSMITTING; - } else if (!retval) { - printf("-----------------------------------IDLE--------------------------------------\n"); - s=IDLE; - } else { - printf("-----------------------------------Unknown status %08x--------------------------------------\n", retval); - s=ERROR; - } - } - - return s; -} - - - -void readFrame(int *ret, char *mess){ - if(!Feb_Control_WaitForFinishedFlag(5000)) - cprintf(RED,"Error: Waiting for finished flag\n"); - cprintf(GREEN,"Acquisition finished***\n"); - - if(eiger_storeinmem){ - printf("requesting images after storing in memory\n"); - if(startReadOut() == FAIL){ - strcpy(mess,"Could not execute read image requests\n"); - *ret = (int)FAIL; - return; - } - } - - //wait for detector to send - Beb_EndofDataSend(send_to_ten_gig); - - - printf("*****Done Waiting...\n"); - *ret = (int)FINISHED; - strcpy(mess,"acquisition successfully finished\n"); + if (bus_r(EXT_SIGNAL_REG) == EXT_SIGNAL_MSK) + return TRIGGER_EXPOSURE; + return AUTO_TIMING; } - - - - - - - - - - - +/* configure mac */ long int calcChecksum(int sourceip, int destip) { @@ -1190,6 +1228,71 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t + +/* jungfrau specific - pll, flashing fpga */ + + + +void resetPLL() { + // reset PLL Reconfiguration and PLL + bus_w(PLL_CONTROL_REG, bus_r(PLL_CONTROL_REG) | PLL_CTRL_RECONFIG_RST_MSK | PLL_CTRL_RST_MSK); + usleep(100); + bus_w(PLL_CONTROL_REG, bus_r(PLL_CONTROL_REG) & ~PLL_CTRL_RECONFIG_RST_MSK & ~PLL_CTRL_RST_MSK); +} + + +u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val) { + + // set parameter + bus_w(PLL_PARAM_REG, val); + + // set address + bus_w(PLL_CONTROL_REG, (reg << PLL_CTRL_ADDR_OFST) & PLL_CTRL_ADDR_MSK); + usleep(10*1000); + + //write parameter + bus_w(PLL_CONTROL_REG, bus_r(PLL_CONTROL_REG) | PLL_CTRL_WR_PARAMETER_MSK); + bus_w(PLL_CONTROL_REG, bus_r(PLL_CONTROL_REG) & ~PLL_CTRL_WR_PARAMETER_MSK); + usleep(10*1000); + + return val; +} + + + + +void configurePll() { + u_int32_t val; + int32_t phase=0, inv=0; + + printf("phase in %d\n", clkPhase[1]); + if (clkPhase[1]>0) { + inv=0; + phase=clkPhase[1]; + } else { + inv=1; + phase=-1*clkPhase[1]; + } + printf("phase out %d %08x\n", phase, phase); + + if (inv) { + val = ((phase << PLL_SHIFT_NUM_SHIFTS_OFST) & PLL_SHIFT_NUM_SHIFTS_MSK) | PLL_SHIFT_CNT_SLCT_C1_VAL | PLL_SHIFT_UP_DOWN_NEG_VAL; + printf("**************** phase word %08x\n", val); + setPllReconfigReg(PLL_PHASE_SHIFT_REG, val); + } else { + val = ((phase << PLL_SHIFT_NUM_SHIFTS_OFST) & PLL_SHIFT_NUM_SHIFTS_MSK) | PLL_SHIFT_CNT_SLCT_C0_VAL | PLL_SHIFT_UP_DOWN_NEG_VAL; + printf("**************** phase word %08x\n", val); + setPllReconfigReg(PLL_PHASE_SHIFT_REG, val); + + printf("**************** phase word %08x\n", val); + val = ((phase << PLL_SHIFT_NUM_SHIFTS_OFST) & PLL_SHIFT_NUM_SHIFTS_MSK) | PLL_SHIFT_CNT_SLCT_C2_VAL; + setPllReconfigReg(PLL_PHASE_SHIFT_REG, val); + } + usleep(10000); +} + + + void eraseFlash(){ #ifdef VERY_VERBOSE printf("\nErasing Flash\n"); @@ -1290,17 +1393,124 @@ int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp){ +/* aquisition */ +int startStateMachine(){ + printf("*******Starting State Machine*******\n"); + cleanFifos(); -int calculateDataBytes(){ - if(send_to_ten_gig) - return setDynamicRange(-1)*16*TEN_GIGA_BUFFER_SIZE; - else - return setDynamicRange(-1)*16*ONE_GIGA_BUFFER_SIZE; + //start state machine + bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_START_ACQ_MSK); + bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_START_ACQ_MSK); + + printf("Status Register: %08x\n",bus_r(STATUS_REG)); } +int stopStateMachine(){ + cprintf(BG_RED,"*******Stopping State Machine*******\n"); + + //stop state machine + bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STOP_ACQ_MSK); + usleep(100); + bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_STOP_ACQ_MSK); + + printf("Status Register: %08x\n",bus_r(STATUS_REG)); + return OK; +} + + + + + +enum runStatus getRunStatus(){ +#ifdef VERBOSE + printf("Getting status\n"); +#endif + + enum runStatus s; + u_int32_t retval = bus_r(STATUS_REG); + printf("Status Register: %08x\n",retval); + + //running + if(((retval & RUN_BUSY_MSK) >> RUN_BUSY_OFST)) { + if ((retval & WAITING_FOR_TRIGGER_MSK) >> WAITING_FOR_TRIGGER_OFST) { + printf("-----------------------------------WAITING-----------------------------------\n"); + s=WAITING; + } + else{ + printf("-----------------------------------RUNNING-----------------------------------\n"); + s=RUNNING; + } + } + + //not running + else { + if ((retval & STOPPED_MSK) >> STOPPED_OFST) { + printf("-----------------------------------STOPPED--------------------------\n"); + s=STOPPED; + } else if ((retval & RUNMACHINE_BUSY_MSK) >> RUNMACHINE_BUSY_OFST) { + printf("-----------------------------------READ MACHINE BUSY--------------------------\n"); + s=TRANSMITTING; + } else if (!retval) { + printf("-----------------------------------IDLE--------------------------------------\n"); + s=IDLE; + } else { + printf("-----------------------------------Unknown status %08x--------------------------------------\n", retval); + s=ERROR; + } + } + + return s; +} + + + +void readFrame(int *ret, char *mess){ + + // wait for status to be done + while(runBusy()){ + usleep(500); + } + + // frames left to give status + int64_t retval = getTimeLeft(FRAME_NUMBER) + 1; + if ( retval > 0) { + *ret = (int)FAIL; + sprintf(mess,"no data and run stopped: %lld frames left\n",retval); + cprintf(RED,"%s\n",mess); + } else { + *ret = (int)FINISHED; + sprintf(mess,"acquisition successfully finished\n"); + printf("%s",mess); + } +} + + + +u_int32_t runBusy(void) { + u_int32_t s = ((bus_r(STATUS_REG) & RUN_BUSY_MSK) >> RUN_BUSY_OFST); +#ifdef VERBOSE + printf("Status Register: %08x\n", s); +#endif + return s; +} + + + + + + + + + + +/* common */ + + + + int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){ int ichip, idac, ichan, iadc; @@ -1378,36 +1588,22 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){ } +int calculateDataBytes(){ + return DATA_BYTES; +} -int getTotalNumberOfChannels(){return getNumberOfChannelsPerModule();} -int getTotalNumberOfChips(){return NCHIP;} -int getTotalNumberOfModules(){return 1;} -int getNumberOfChannelsPerChip(){return NCHAN;} +int getTotalNumberOfChannels(){return getNumberOfChannelsPerModule() * getTotalNumberOfModules;} +int getTotalNumberOfChips(){return getNumberOfChipsPerModule * getTotalNumberOfModules;} +int getTotalNumberOfModules(){return NMOD;} int getNumberOfChannelsPerModule(){return getNumberOfChannelsPerChip() * getTotalNumberOfChips();} int getNumberOfChipsPerModule(){return NCHIP;} int getNumberOfDACsPerModule(){return NDAC;} int getNumberOfADCsPerModule(){return NADC;} -int getNumberOfGainsPerModule(){return NGAIN;} -int getNumberOfOffsetsPerModule(){return NOFFSET;} +int getNumberOfChannelsPerChip(){return NCHAN;} - - -enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){ - if(arg != GET_EXTERNAL_COMMUNICATION_MODE){ - switch((int)arg){ - case AUTO_TIMING: bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) & ~EXT_SIGNAL_MSK); break; - case TRIGGER_EXPOSURE: bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) | EXT_SIGNAL_MSK); break; - default: - cprintf(RED,"Unknown timing mode %d\n", arg); - return GET_EXTERNAL_COMMUNICATION_MODE; - } - } - if (bus_r(EXT_SIGNAL_REG) == EXT_SIGNAL_MSK) - return TRIGGER_EXPOSURE; - return AUTO_TIMING; -} +/* sync */ enum masterFlags setMaster(enum masterFlags arg){ return NO_MASTER; @@ -1417,4 +1613,9 @@ enum synchronizationMode setSynchronization(enum synchronizationMode arg){ return NO_SYNCHRONIZATION; } + + + + + //#endif diff --git a/slsDetectorSoftware/jungfrauDetectorServerNewStructure/slsDetectorServer_defs.h b/slsDetectorSoftware/jungfrauDetectorServerNewStructure/slsDetectorServer_defs.h index c76fbf1eb..44daee671 100644 --- a/slsDetectorSoftware/jungfrauDetectorServerNewStructure/slsDetectorServer_defs.h +++ b/slsDetectorSoftware/jungfrauDetectorServerNewStructure/slsDetectorServer_defs.h @@ -2,7 +2,7 @@ #define SLSDETECTORSERVER_DEFS_H #include "sls_detector_defs.h" //default dynamicgain in settings -#include "registers_m.h" +#include "RegisterDefs.h" #include @@ -10,7 +10,7 @@ #define GOODBYE (-200) #define CTRL_SRVR_INIT_TIME_US (300 * 1000) //#define REQUIRED_FIRMWARE_VERSION 16 -//#define FIRMWAREREV 0xcaba //temporary should be in firmware + /* Struct Definitions */ typedef struct ip_header_struct { @@ -27,9 +27,9 @@ typedef struct ip_header_struct { } ip_header; /* Enums */ -enum clkspeed {FULL_SPEED, HALF_SPEED, QUARTER_SPEED}; +enum CLK_SPEED_INDEX {FULL_SPEED, HALF_SPEED, QUARTER_SPEED}; enum ADC_INDEX {TEMP_FPGA, TEMP_ADC}; -enum DAC_INDEX { VB_COMP, VDD_PROT, VIN_COM, VREF_PRECH, VB_PIXBUF, VB_DS, VREF_DS, VREF_COMP }; +enum DAC_INDEX {VB_COMP, VDD_PROT, VIN_COM, VREF_PRECH, VB_PIXBUF, VB_DS, VREF_DS, VREF_COMP }; #define DEFAULT_DAC_VALS { 1220, /* VB_COMP */ \ 3000, /* VDD_PROT */ \ 1053, /* VIN_COM */ \ @@ -52,20 +52,15 @@ enum DAC_INDEX { VB_COMP, VDD_PROT, VIN_COM, VREF_PRECH, VB_PIXBUF, VB_DS, VR /* Hardware Definitions */ -#define NMAXMODY (1) -#define NMAXMODX (1) -#define NMAXMOD (NMAXMODX * NMAXMODY) -#define NMODY (1) -#define NMODX (1) -#define NMOD (NMODX * NMODY) +#define NMAXMOD (1) +#define NMOD (1) #define NCHAN (256 * 256) #define NCHIP (8) #define NADC (0) #define NDAC (8) -#define NCHANS (NCHAN * NCHIP * NMAXMOD) -#define NDACS (NDAC * NMAXMOD) #define DYNAMIC_RANGE (16) -#define DATA_BYTES (NMAXMOD * NCHIP * NCHAN * 2) +#define NUM_BITS_PER_PIXEL (DYNAMIC_RANGE / 8) +#define DATA_BYTES (NCHIP * NCHAN * NUM_BITS_PER_PIXEL) #define IP_PACKETSIZE (0x2052) #define CLK_RUN (40) /* MHz */ #define CLK_SYNC (20) /* MHz */ @@ -78,6 +73,7 @@ enum DAC_INDEX { VB_COMP, VDD_PROT, VIN_COM, VREF_PRECH, VB_PIXBUF, VB_DS, VR #define DEFAULT_PERIOD (2*1000*1000) //ns #define DEFAULT_DELAY (0) #define DEFAULT_HIGH_VOLTAGE (0) +#define DEFAULT_TIMING_MODE (AUTO_TIMING) #define DEFAULT_SETTINGS (DYNAMICGAIN) #define DEFAULT_TX_UDP_PORT (0x7e9a) diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h index 5d120b0f4..e1d84d6de 100644 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h @@ -97,12 +97,17 @@ int setROI(int n, ROI arg[], int *retvalsize, int *ret); int setSpeed(enum speedVariable arg, int val); #if defined(EIGERD) || defined(MYTHEND) enum readOutFlags setReadOutFlags(enum readOutFlags val); +#endif +#ifdef MYTHEND int executeTrimming(enum trimMode mode, int par1, int par2, int imod); #endif // parameters - timer int64_t setTimer(enum timerIndex ind, int64_t val); +#ifndef EIGERD int64_t getTimeLeft(enum timerIndex ind); +#endif + // parameters - channel, chip, module, settings #ifdef MYTHEND @@ -128,12 +133,22 @@ int setThresholdEnergy(int ev, int imod); #endif // parameters - dac, adc, hv -void setDAC(enum detDacIndex ind, int val, int imod, int mV, int retval[]); -int getADC(enum detAdcIndex ind, int imod); +#ifdef JUNGFRAUD +void serializeToSPI(u_int32_t addr, u_int32_t val, u_int16_t csmask, int numbitstosend, u_int16_t clkmask, u_int16_t digoutmask, int digofset); +void initDac(int dacnum); +void prepareADC(); +void setAdc(int addr, int val); +int voltageToDac(int value); +int dacToVoltage(unsigned int digital); +#endif +void setDAC(enum DAC_INDEX ind, int val, int imod, int mV, int retval[]); +int getADC(enum ADC_INDEX ind, int imod); #ifndef MYTHEND int setHighVoltage(int val); #endif + + // parameters - timing, extsig #ifdef MYTHEND enum externalSignalFlag getExtSignal(int signalindex); @@ -159,7 +174,10 @@ int resetCounterBlock(int startACQ); int calibratePedestal(int frames); #elif JUNGFRAUD -// jungfrau specific - flashing fpga +// jungfrau specific - pll, flashing firmware +void resetPLL(); +u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val); +void configurePll(); void eraseFlash(); int startWritingFPGAprogram(FILE** filefp); int stopWritingFPGAprogram(FILE* filefp); @@ -183,7 +201,7 @@ int setAllTrimbits(int val); int getAllTrimbits(); int getBebFPGATemp(); int activate(int enable); -int setNetworkParameter(enum detNetworkParameter mode, int value); +int setNetworkParameter(enum NETWORK_PARA_INDEX mode, int value); #endif @@ -195,9 +213,14 @@ int startReceiver(int d); #endif int startStateMachine(); int stopStateMachine(); +#ifndef JUNGFRAUD int startReadOut(); +#endif enum runStatus getRunStatus(); void readFrame(int *ret, char *mess); +#ifdef JUNGFRAUD +u_int32_t runBusy(void); +#endif //common @@ -206,7 +229,6 @@ int calculateDataBytes(); int getTotalNumberOfChannels(); int getTotalNumberOfChips(); int getTotalNumberOfModules(); -int getNumberOfChannelsPerChip(); int getNumberOfChannelsPerModule(); int getNumberOfChipsPerModule(); int getNumberOfDACsPerModule(); @@ -215,6 +237,7 @@ int getNumberOfADCsPerModule(); int getNumberOfGainsPerModule(); int getNumberOfOffsetsPerModule(); #endif +int getNumberOfChannelsPerChip(); // sync enum masterFlags setMaster(enum masterFlags arg); diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index da7a9a39a..2531701be 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -1210,6 +1210,7 @@ int set_dac(int file_des) { retval[0] = setIODelay(val,imod); else{ setDAC(idac,val,imod,mV,retval); +#ifdef EIGERD if(val != -1) { //changing dac changes settings to undefined switch(idac){ @@ -1226,6 +1227,7 @@ int set_dac(int file_des) { break; } } +#endif } } @@ -1344,10 +1346,12 @@ int get_adc(int file_des) { iadc = TEMP_FPGAFEBR; break; #endif -#ifdef GOTTHARDD +#if defined(GOTTHARD) || defined(JUNGFRAUD) case TEMPERATURE_FPGA: + iadc = TEMP_FPGA; break; case TEMPERATURE_ADC: + iadc = TEMP_ADC; break; #endif default: @@ -2751,15 +2755,24 @@ int set_dynamic_range(int file_des) { ret=FAIL; sprintf(mess,"Detector locked by %s\n",lastClientIP); } else { -#ifdef EIGERD + switch(dr){ +#ifdef EIGERD case -1:case 4: case 8: case 16:case 32:break; +#elif JUNGFRAUD + case 16: break; +#endif default: +#ifdef EIGERD strcpy(mess,"could not set dynamic range. Must be 4,8,16 or 32.\n"); +#elif JUNGFRAUD + strcpy(mess,"could not change dynamic range from 16 for this detector.\n"); +#endif ret = FAIL; } -#endif + } +#ifdef EIGERD if(ret == OK){ int old_dr = setDynamicRange(-1); retval=setDynamicRange(dr); @@ -2783,6 +2796,7 @@ int set_dynamic_range(int file_des) { } } } +#endif #endif if (dr>=0 && retval!=dr) ret=FAIL;