diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index f71349d54..a0607e0ce 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -62,6 +62,7 @@ using namespace std; #define RATE_CORRECTION_NOT_32or16BIT 0x0000000000800000ULL #define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000001000000ULL #define PROGRAMMING_ERROR 0x0000000002000000ULL +#define RECEIVER_ACTIVATE 0x0000000004000000ULL // 0x00000000FFFFFFFFULL /** @short class returning all error messages for error mask */ @@ -202,7 +203,8 @@ public: if(slsErrorMask&PROGRAMMING_ERROR) retval.append("Could not program FPGA\n"); - + if(slsErrorMask&RECEIVER_ACTIVATE) + retval.append("Could not activate/deactivate receiver\n"); //------------------------------------------------------ length of message diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index d09ee273d..d30312142 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -103,11 +103,13 @@ enum { F_SET_RATE_CORRECT, /** < set/reset rate correction tau */ F_GET_RATE_CORRECT, /** < get rate correction tau */ + F_ACTIVATE, /** < activate/deactivate readout */ F_SET_NETWORK_PARAMETER, /**< set network parameters such as transmission delay, flow control */ F_PROGRAM_FPGA /**< program FPGA */ + /* Always append functions hereafter!!! */ }; diff --git a/slsDetectorSoftware/eigerDetectorServer/Beb.c b/slsDetectorSoftware/eigerDetectorServer/Beb.c index d1bbcb947..bdd47a461 100644 --- a/slsDetectorSoftware/eigerDetectorServer/Beb.c +++ b/slsDetectorSoftware/eigerDetectorServer/Beb.c @@ -46,6 +46,8 @@ short Beb_bit_mode; int BEB_MMAP_SIZE = 0x1000; + int Beb_activated = 1; + void BebInfo_BebInfo(struct BebInfo* bebInfo, unsigned int beb_num){ @@ -172,6 +174,10 @@ void Beb_GetModuleCopnfiguration(int* master, int* top){ /* do not work at the moment */ int Beb_SetMasterViaSoftware(){ + + if(!Beb_activated) + return 0; + //mapping new memory u_int32_t* csp0base=0; u_int32_t value = 0, ret = 1; @@ -200,6 +206,10 @@ int Beb_SetMasterViaSoftware(){ /* do not work at the moment */ int Beb_SetSlaveViaSoftware(){ + + if(!Beb_activated) + return 0; + //mapping new memory u_int32_t* csp0base=0; u_int32_t value = 0, ret = 1; @@ -268,11 +278,18 @@ int Beb_Activate(int enable){ if(fd > 0) Beb_close(fd,csp0base); + Beb_activated = ret; + return ret; } int Beb_SetNetworkParameter(enum detNetworkParameter mode, int val){ + + if(!Beb_activated) + return val; + + //mapping new memory u_int32_t* csp0base=0; u_int32_t valueread = 0; @@ -325,6 +342,10 @@ int Beb_SetNetworkParameter(enum detNetworkParameter mode, int val){ int Beb_ResetToHardwareSettings(){ + + if(!Beb_activated) + return 1; + //mapping new memory u_int32_t* csp0base=0; u_int32_t value = 0, ret = 1; @@ -396,6 +417,10 @@ u_int32_t Beb_GetFirmwareSoftwareAPIVersion(){ } void Beb_ResetFrameNumber(){ + + if(!Beb_activated) + return; + //mapping new memory to read master top module configuration u_int32_t* csp0base=0; //open file pointer @@ -446,7 +471,6 @@ int Beb_InitBebInfos(){//file name at some point bebInfoSize++; - //if(!Beb_ReadSetUpFromFile("/home/root/executables/setup_beb.txt")) return 0; /* //loop through file to fill vector. BebInfo* b = new BebInfo(26); @@ -477,52 +501,6 @@ int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, char* src_mac } -int Beb_ReadSetUpFromFile(char* file_name){ - char line[100]; - char str[100]; - - int i0,i1; - char mac0[50],mac1[50],ip0[50],ip1[0]; - FILE* fp = fopen(file_name, "r"); - if( fp == NULL ){ - perror("Error while opening the beb setup file.\n"); - return 0; - } - - printf("Setting up beb side of detector:\n"); - while ( fgets (line , 255 , fp) != NULL ){ - if(strlen(line)<=1) - continue; - sscanf (line, "%s", str); - if (str[0]=='#') - continue; - - if(!strcmp(str,"add_beb")){ - if( sscanf (line,"%s %d %d %s %s %s %s",str,&i0,&i1,mac0,ip0,mac1,ip1) < 7){ - printf("Error adding beb from %s.\n",file_name); - exit(0); - } - - printf ("Read: %s %d %d %s %s %s %s\n", str,i0,i1,mac0,ip0,mac1,ip1); - - if(Beb_GetBebInfoIndex(i0)){ - printf("Error adding beb from %s, beb number %d already added.\n",file_name,i0); - exit(0); - } - - struct BebInfo b0; - BebInfo_BebInfo(&b0,i0); - BebInfo_SetSerialAddress(&b0,i1); - BebInfo_SetHeaderInfo(&b0,0,mac0,ip0,42000+i0); - BebInfo_SetHeaderInfo(&b0,1,mac1,ip1,52000+i0); - beb_infos[bebInfoSize] = b0; - bebInfoSize++; - } - } - fclose(fp); - return 1; -} - int Beb_CheckSourceStuffBebInfo(){ @@ -552,6 +530,10 @@ unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb){ int Beb_WriteTo(unsigned int index){ + + if(!Beb_activated) + return 1; + if(index>=bebInfoSize){ printf("WriteTo index error.\n"); return 0; @@ -575,35 +557,15 @@ void Beb_SwapDataFun(int little_endian, unsigned int n, unsigned int *d){ int Beb_SetByteOrder(){ -/* - Beb_send_data_raw[0] = 0x8fff0000; - if(Local_Write(ll_beb,4,Beb_send_data_raw)!=4) return 0; - - while((Local_Read(ll_beb,Beb_recv_buffer_size*4,Beb_recv_data_raw)/4)>0) printf("\t) Cleanning buffer ...\n"); - - if(bebInfoSize<2) return 0; - - Beb_send_ndata = 3; - Beb_send_data[0] = 0x000c0000; - Beb_send_data[1] = 0; - Beb_send_data[2] = 0; - Beb_WriteTo(0); - - //using little endian for data, big endian not fully tested, swap on 16 bit boundary. - Beb_send_ndata = 3; - Beb_send_data[0] = 0x000c0000; - Beb_send_data[1] = 1; - Beb_send_data[2] = 0; - Beb_SwapDataFun(0,2,&(Beb_send_data[1])); - Beb_WriteTo(0); - - printf("\tSetting Byte Order .............. ok\n"); -*/ return 1; } int Beb_SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int header_number, char* dst_mac, char* dst_ip, unsigned int dst_port){ + + if(!Beb_activated) + return 1; + u_int32_t bram_phy_addr; u_int32_t* csp0base=0; /*u_int32_t* bram_ptr = NULL;*/ @@ -809,7 +771,9 @@ int Beb_SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, i cprintf(GREEN, "Beb_send_data[1] Swapped:%X\n",Beb_send_data[1]); #endif - if(!Beb_WriteTo(i)) return 0; + if(Beb_activated){ + if(!Beb_WriteTo(i)) return 0; + } return 1; } @@ -828,6 +792,9 @@ int Beb_SetUpTransferParameters(short the_bit_mode){ int Beb_StopAcquisition() { + if(!Beb_activated) + return 1; + u_int32_t* csp0base=0; volatile u_int32_t valuel,valuer; //open file pointer @@ -854,6 +821,10 @@ int Beb_StopAcquisition() } int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int dst_number, unsigned int nimages, int test_just_send_out_packets_no_wait){ + + if(!Beb_activated) + return 1; + if(dst_number>64) return 0; unsigned int header_size = 4; //4*64 bits diff --git a/slsDetectorSoftware/eigerDetectorServer/Beb.h b/slsDetectorSoftware/eigerDetectorServer/Beb.h index b11e11815..535b0e382 100644 --- a/slsDetectorSoftware/eigerDetectorServer/Beb.h +++ b/slsDetectorSoftware/eigerDetectorServer/Beb.h @@ -41,7 +41,6 @@ struct BebInfo{ void Beb_ClearBebInfos(); int Beb_InitBebInfos(); - int Beb_ReadSetUpFromFile(char* file_name); int Beb_CheckSourceStuffBebInfo(); unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb); diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.c b/slsDetectorSoftware/eigerDetectorServer/FebControl.c index ea9c1a32a..f3d4f0d52 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.c +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.c @@ -64,7 +64,10 @@ int Feb_control_master = 0; unsigned int Feb_Control_rate_correction_table[1024]; double Feb_Control_rate_meas[16384]; + double ratemax=-1; +int Feb_Control_activated = 1; + void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){ unsigned int i; @@ -152,6 +155,10 @@ int Module_GetBottomDACValue(struct Module* mod,unsigned int i) +void Feb_Control_activate(int activate){ + Feb_Control_activated = activate; +} + int Feb_Control_IsBottomModule(){ if(Module_BottomAddressIsValid(&modules[Feb_Control_current_index])) return 1; @@ -186,40 +193,10 @@ int Feb_Control_Init(int master, int top, int module_num){ Feb_Control_module_number = (module_num & 0xFF); int serial = !top; - - /* - //for Gemmas modules: if master, serial 0, else 1 - int serial = 1; - if(master) - serial = 0; - switch(Feb_Control_module_number){ - case 34: serial = 0; break; //martin half - case 26: serial = 0; break; //leo - - case 31: serial = 0; break; //martin - case 32: serial = 1; break; - case 24: serial = 2; break; - case 25: serial = 3; break; - - case 15: serial = 0; break; //dhanya - case 16: serial = 1; break; - case 30: serial = 2; break; - case 38: serial = 3; break; - - case 49: serial = 0; break; // Gemma - case 48: serial = 1; break; // Gemma - }*/ printf("serial: %d\n",serial); Feb_Control_current_index = 1; - /*for(i=1;i0) - sprintf(str,"%s",str); /*sprintf(str,"mod%d::%s",module_num,str);*/ - if(!Feb_Control_SetDAC(str,f0,1)) - cprintf(RED,"Error in string: %s",str); - - } - } - fclose(fp); - printf("Done reading set up file\n"); - return 1; -} int Feb_Control_CheckSetup(int master){ @@ -675,12 +467,14 @@ int Feb_Control_SendIDelays(unsigned int dst_num, int chip_lr, unsigned int chan printf(", tracks 0x%x to: %d, %d clks and %d units.\n",channels,(((15-delay_data_valid_nclks)<<6)|ndelay_units),delay_data_valid_nclks,ndelay_units); - if(!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG2, 1<<31 | delay_data_valid_nclks<<16 | ndelay_units,0,0) || //the 1<<31 time enables the setting of the data valid delays - !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG3,set_left_delay_channels,0,0) || - !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG4,set_right_delay_channels,0,0) || - !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG_CTRL,CHIP_DATA_OUT_DELAY_SET,1,1)){ - cprintf(RED,"Warning: could not SetChipDataInputDelays(...).\n"); - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG2, 1<<31 | delay_data_valid_nclks<<16 | ndelay_units,0,0) || //the 1<<31 time enables the setting of the data valid delays + !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG3,set_left_delay_channels,0,0) || + !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG4,set_right_delay_channels,0,0) || + !Feb_Interface_WriteRegister(dst_num,CHIP_DATA_OUT_DELAY_REG_CTRL,CHIP_DATA_OUT_DELAY_SET,1,1)){ + cprintf(RED,"Warning: could not SetChipDataInputDelays(...).\n"); + return 0; + } } return 1; @@ -738,9 +532,11 @@ int Feb_Control_SendHighVoltage(unsigned int dst_num,float* value){ } unsigned int r = 0x20000000 | (b&0xff); - if(!Feb_Interface_WriteRegister(dst_num,0,r,0,0)){ - cprintf(RED,"Warning: trouble setting high voltage for dst_num %d.\n",dst_num); - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteRegister(dst_num,0,r,0,0)){ + cprintf(RED,"Warning: trouble setting high voltage for dst_num %d.\n",dst_num); + return 0; + } } *value = Feb_Control_DACToVoltage(b,nsteps,vmin,vmax); @@ -752,43 +548,15 @@ int Feb_Control_SendHighVoltage(unsigned int dst_num,float* value){ int Feb_Control_DecodeDACString(char* dac_str, unsigned int* module_index, int* top, int* bottom, unsigned int* dac_ch){ char* local_s = dac_str; - //char temp[50]; *module_index = Feb_Control_current_index; - - /* - char* p1 = strstr(local_s,"mod");//size_t p1 = local_s.find("mod"); - char* p2 = strstr(local_s,"::");//size_t p2 =local_s.find("::"); - if(p1!=NULL&&p2!=NULL&&(p1+3)15){ cprintf(RED,"Warning invalid ch for SetDAC.\n"); return 0; @@ -918,9 +651,11 @@ int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int unsigned int r = dac_ic<<30 | 3<<16 | dac_ch<<12 | *value; //3 write and power up - if(!Feb_Interface_WriteRegister(dst_num,0,r,1,0)){ - cprintf(RED,"Warning: trouble setting dac %d voltage.\n",ch); - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteRegister(dst_num,0,r,1,0)){ + cprintf(RED,"Warning: trouble setting dac %d voltage.\n",ch); + return 0; + } } float voltage=Feb_Control_DACToVoltage(*value,4096,0,2048); @@ -929,14 +664,7 @@ int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int return 1; } -/* -float GetDAC(string s){ - static unsigned int n; - if(!GetDACNumber(s,n)) return 0; - return dac[n]; -} - */ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ printf("Setting Trimbits\n"); @@ -959,12 +687,15 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ for(l_r=0;l_r<2;l_r++){ // l_r loop //printf("\nl_r:%d\t\t",l_r); unsigned int disable_chip_mask = l_r ? DAQ_CS_BAR_LEFT : DAQ_CS_BAR_RIGHT; - if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0) - &&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) - &&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){ - printf("Could not select chips\n"); - return 0; + if(Feb_Control_activated){ + if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0) + &&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) + &&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){ + printf("Could not select chips\n"); + return 0; + } } + int row_set; for(row_set=0;row_set<16;row_set++){ //16 rows at a time //printf("row_set:%d\t\t",row_set); @@ -1020,22 +751,26 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ } //end row loop if(Module_TopAddressIsValid(&modules[1])){ - if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)|| - !Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)|| - //if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)|| - // !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)|| - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - printf(" some errror!\n"); - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)|| + !Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)|| + //if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)|| + // !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)|| + !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + printf(" some errror!\n"); + return 0; + } } }else{ - if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)|| - !Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)|| - //if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)|| - // !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)|| - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - printf(" some errror!\n"); - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_l)|| + !Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)|| + //if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)|| + // !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)|| + !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + printf(" some errror!\n"); + return 0; + } } } @@ -1077,14 +812,20 @@ return Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[ } int Feb_Control_SetCommandRegister(unsigned int cmd){ - return Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CHIP_CMDS,cmd,0,0); + if(Feb_Control_activated) + return Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CHIP_CMDS,cmd,0,0); + else + return 1; } int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret_status){ - if(!Feb_Interface_ReadRegister(dst_address,DAQ_REG_STATUS,ret_status)){ - cprintf(RED,"Error: reading status register.\n"); - return 0; + //if deactivated, should be handled earlier and should not get into this function + if(Feb_Control_activated){ + if(!Feb_Interface_ReadRegister(dst_address,DAQ_REG_STATUS,ret_status)){ + cprintf(RED,"Error: reading status register.\n"); + return 0; + } } *ret_status = (0x02FF0000 & *ret_status) >> 16; @@ -1093,11 +834,12 @@ int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us){ - if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)||!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_START,0,0)){ - cprintf(RED,"Warning: could not start.\n"); - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)||!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_START,0,0)){ + cprintf(RED,"Warning: could not start.\n"); + return 0; + } } - return Feb_Control_WaitForFinishedFlag(sleep_time_us); } @@ -1105,6 +847,10 @@ int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us){ int Feb_Control_AcquisitionInProgress(){ unsigned int status_reg_r=0,status_reg_l=0; + //deactivated should return end of acquisition + if(!Feb_Control_activated) + return 0; + int ind = Feb_Control_current_index; if(Module_BottomAddressIsValid(&modules[ind])){ @@ -1132,6 +878,10 @@ int Feb_Control_AcquisitionInProgress(){ int Feb_Control_AcquisitionStartedBit(){ unsigned int status_reg_r=0,status_reg_l=0; + //deactivated should return acquisition started/ready + if(!Feb_Control_activated) + return 1; + int ind = Feb_Control_current_index; if(Module_BottomAddressIsValid(&modules[ind])){ @@ -1172,6 +922,11 @@ int Feb_Control_WaitForFinishedFlag(int sleep_time_us){ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){ + + //deactivated dont wait (otherwise give a toggle value back) + if(!Feb_Control_activated) + return 1; + int value = prev_flag; while(value == prev_flag){ usleep(sleep_time_us); @@ -1186,10 +941,13 @@ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){ } -int Feb_Control_Reset(){printf("Reset daq\n"); - if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){ - cprintf(RED,"Warning: Could not reset daq, no response.\n"); - return 0; +int Feb_Control_Reset(){ + printf("Reset daq\n"); + if(Feb_Control_activated){ + if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){ + cprintf(RED,"Warning: Could not reset daq, no response.\n"); + return 0; + } } return Feb_Control_WaitForFinishedFlag(5000); @@ -1199,10 +957,12 @@ int Feb_Control_Reset(){printf("Reset daq\n"); int Feb_Control_SetStaticBits(){ - //program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64 - if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - cprintf(RED,"Warning: Could not set static bits\n"); - return 0; + if(Feb_Control_activated){ + //program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64 + if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + cprintf(RED,"Warning: Could not set static bits\n"); + return 0; + } } return 1; @@ -1448,13 +1208,7 @@ void Feb_Control_PrintAcquisitionSetup(){ } int Feb_Control_SendBitModeToBebServer(){ - /* - static int first_pass = 1; - static char buffer[1024]; - if(first_pass&&!Feb_Control_SetupSendToSocket("localhost",43212)) return 0; - else first_pass=0; - */ unsigned int just_bit_mode = (DAQ_STATIC_BIT_M4|DAQ_STATIC_BIT_M8) & Feb_Control_staticBits; unsigned int bit_mode = 16; //default if(just_bit_mode == DAQ_STATIC_BIT_M4) bit_mode = 4; @@ -1467,60 +1221,9 @@ int Feb_Control_SendBitModeToBebServer(){ return 0; } - /* - bzero(buffer,1024); - sprintf(buffer,"setbitmode %d",bit_mode); - - if(Feb_Control_WriteNRead(buffer,strlen(buffer),1024)<1||strncmp(buffer,"0",1)){ - cprintf(RED,"Error: sending bit mode ...\n"); - return 0; - } - */ return 1; } -/* -int Feb_Control_SetupSendToSocket(const char* ip_address_hostname, unsigned short int port){ - - struct hostent *server; - if((server = gethostbyname(ip_address_hostname)) == NULL){ //or look into getaddrinfo(3) - fprintf(stderr,"ERROR, no such host\n"); - return 0; - } - - //struct sockaddr_in serv_addr; - bzero((char *) &Feb_Control_serv_addr, sizeof(Feb_Control_serv_addr)); - Feb_Control_serv_addr.sin_family = AF_INET; - bcopy((char *)server->h_addr,(char *)&Feb_Control_serv_addr.sin_addr.s_addr,server->h_length); - Feb_Control_serv_addr.sin_port = htons(port); - - return 1; -} - -int Feb_Control_WriteNRead(char* message, int length, int max_length){ - - int sockfd = socket(AF_INET, SOCK_STREAM, 0); - if(sockfd <0){ - fprintf(stderr,"ERROR opening socket\n"); - return 0; - } - - if(connect(sockfd,(struct sockaddr *) &Feb_Control_serv_addr,sizeof(Feb_Control_serv_addr)) < 0){ - fprintf(stderr,"ERROR connecting\n"); - return 0; - } - - int n = write(sockfd,message,length); - if(n<0) cprintf(RED,"Error writing to socket"); - - length = read(sockfd,message,max_length); - if(length<0) cprintf(RED,"Error reading to socket"); - - close(sockfd); - - return length; -} - */ int Feb_Control_PrepareForAcquisition(){//return 1; static unsigned int reg_nums[20]; @@ -1568,30 +1271,13 @@ int Feb_Control_PrepareForAcquisition(){//return 1; reg_nums[5]=DAQ_REG_SUBFRAME_EXPOSURES; reg_vals[5]= Feb_Control_subframe_exposure_time_in_10nsec; //(1 means 10ns, 100 means 1000ns) // if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),20,reg_nums,reg_vals,0,0)){ - if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),6,reg_nums,reg_vals,0,0)){ - printf("Trouble starting acquisition....\n");; - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),6,reg_nums,reg_vals,0,0)){ + printf("Trouble starting acquisition....\n");; + return 0; + } } - -/* - reg_nums[0]=DAQ_REG_NEXPOSURES; - reg_vals[0]=Feb_Control_nimages; - reg_nums[1]=DAQ_REG_EXPOSURE_TIMER; - reg_vals[1]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_time_in_sec); - reg_nums[2]=DAQ_REG_EXPOSURE_REPEAT_TIMER; - reg_vals[2]=Feb_Control_ConvertTimeToRegister(Feb_Control_exposure_period_in_sec); - reg_nums[3]=DAQ_REG_CHIP_CMDS; - reg_vals[3]=(Feb_Control_acquireNReadoutMode|Feb_Control_triggerMode|Feb_Control_externalEnableMode|Feb_Control_subFrameMode); - reg_nums[4]=DAQ_REG_SUBFRAME_EXPOSURES; - reg_vals[4]= Feb_Control_subframe_exposure_time_in_10nsec; //(1 means 10ns, 100 means 1000ns) - // if(!Feb_Interface_WriteRegisters((Module_GetTopLeftAddress(&modules[1])|Module_GetTopRightAddress(&modules[1])),20,reg_nums,reg_vals,0,0)){ - if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),5,reg_nums,reg_vals,0,0)){ - printf("Trouble starting acquisition....\n");; - return 0; - } -*/ - return 1; } @@ -1612,22 +1298,13 @@ int Feb_Control_StartAcquisition(){ reg_nums[14]=DAQ_REG_CTRL; reg_vals[14]=ACQ_CTRL_START; - if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),15,reg_nums,reg_vals,0,0)){ - cprintf(RED,"Trouble starting acquisition....\n");; - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),15,reg_nums,reg_vals,0,0)){ + cprintf(RED,"Trouble starting acquisition....\n");; + return 0; + } } -/* - reg_nums[0]=DAQ_REG_CTRL; - reg_vals[0]=0; - reg_nums[1]=DAQ_REG_CTRL; - reg_vals[1]=ACQ_CTRL_START; - - if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),2,reg_nums,reg_vals,0,0)){ - printf("Trouble starting acquisition....\n");; - return 0; - } -*/ return 1; } @@ -1706,11 +1383,13 @@ int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos){ c |= (inc_x_pos) ? DAQ_CLK_MAIN_CLK_TO_SELECT_NEXT_PIXEL : 0; c |= (inc_y_pos) ? DAQ_CLK_ROW_CLK_TO_SELECT_NEXT_ROW : 0; - if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SEND_N_TESTPULSES,npulses,0,0) || - !Feb_Control_SetCommandRegister(c) || - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - cprintf(RED,"Warning: could not PulsePixelNMove(...).\n"); - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SEND_N_TESTPULSES,npulses,0,0) || + !Feb_Control_SetCommandRegister(c) || + !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + cprintf(RED,"Warning: could not PulsePixelNMove(...).\n"); + return 0; + } } return 1; @@ -1718,11 +1397,13 @@ int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos){ /**new*/ int Feb_Control_Shift32InSerialIn(unsigned int value_to_shift_in){ - if(!Feb_Control_SetCommandRegister(DAQ_SERIALIN_SHIFT_IN_32) || - !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SHIFT_IN_32,value_to_shift_in,0,0) || - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - cprintf(RED,"Warning: could not shift in 32.\n"); - return 0; + if(Feb_Control_activated){ + if(!Feb_Control_SetCommandRegister(DAQ_SERIALIN_SHIFT_IN_32) || + !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SHIFT_IN_32,value_to_shift_in,0,0) || + !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + cprintf(RED,"Warning: could not shift in 32.\n"); + return 0; + } } return 1; } @@ -1742,11 +1423,13 @@ int Feb_Control_ClockRowClock(unsigned int ntimes){ ntimes=1023; } - if(!Feb_Control_SetCommandRegister(DAQ_CLK_ROW_CLK_NTIMES) || - !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CLK_ROW_CLK_NTIMES,ntimes,0,0) || - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - cprintf(RED,"Warning: could not clock row clock.\n"); - return 0; + if(Feb_Control_activated){ + if(!Feb_Control_SetCommandRegister(DAQ_CLK_ROW_CLK_NTIMES) || + !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CLK_ROW_CLK_NTIMES,ntimes,0,0) || + !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + cprintf(RED,"Warning: could not clock row clock.\n"); + return 0; + } } return 1; @@ -1939,18 +1622,22 @@ int Feb_Control_SetRateCorrectionTable(unsigned int *table){ printf("daq reset completely\n"); if(Module_TopAddressIsValid(&modules[1])){ - if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)|| - !Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)|| - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - cprintf(BG_RED,"Error in Top Writing to Memory ::Feb_Control_SetRateCorrectionTable\n"); - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)|| + !Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)|| + !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + cprintf(BG_RED,"Error in Top Writing to Memory ::Feb_Control_SetRateCorrectionTable\n"); + return 0; + } } }else{ - if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)|| - !Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)|| - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - cprintf(BG_RED,"Error in Bottom Writing to Memory ::Feb_Control_SetRateCorrectionTable\n"); - return 0; + if(Feb_Control_activated){ + if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)|| + !Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)|| + !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + cprintf(BG_RED,"Error in Bottom Writing to Memory ::Feb_Control_SetRateCorrectionTable\n"); + return 0; + } } } return 1; diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.h b/slsDetectorSoftware/eigerDetectorServer/FebControl.h index 30a45e702..3d1fa8b43 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.h +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.h @@ -64,6 +64,7 @@ int Module_GetBottomDACValue(struct Module* mod,unsigned int i); +void Feb_Control_activate(int activate); int Feb_Control_IsBottomModule(); int Feb_Control_GetModuleNumber(); @@ -112,8 +113,6 @@ int Feb_Control_GetModuleNumber(); void Feb_Control_FebControl(); int Feb_Control_Init(int master, int top, int module_num); - int Feb_Control_ReadSetUpFileToAddModules(char* file_name); - int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name); int Feb_Control_CheckSetup(); unsigned int Feb_Control_GetNModules(); diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.14.1 b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.14.1 deleted file mode 100755 index 658df43b3..000000000 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.14.1 and /dev/null differ diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c index 487d5502c..73b435403 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c @@ -1329,7 +1329,9 @@ int getBebFPGATemp(){ int activate(int enable){ - return Beb_Activate(enable); + int ret = Beb_Activate(enable); + Feb_Control_activate(ret); + return ret; } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index ae2fcef1d..158afdabe 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -1270,6 +1270,13 @@ int slsDetector::activate(int const enable){ int arg = enable; char mess[MAX_STR_LENGTH]=""; int ret = OK; + + if(thisDetector->myDetectorType != EIGER){ + std::cout<< "Not implemented for this detector" << std::endl; + setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE)); + return -1; + } + #ifdef VERBOSE if(!enable) std::cout<< "Deactivating Detector" << std::endl; @@ -1296,11 +1303,36 @@ int slsDetector::activate(int const enable){ } } #ifdef VERBOSE - if(retval) + if(retval==1) std::cout << "Detector Activated" << std::endl; - else + else if(retval==0) std::cout << "Detector Deactivated" << std::endl; + else + std::cout << "Detector Activation unknown:" << retval << std::endl; #endif + + if(ret!=FAIL){ + if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Activating/Deactivating Receiver: " << retval << std::endl; +#endif + if (connectData() == OK) + ret=thisReceiver->sendInt(fnum,retval,retval); + disconnectData(); + if(ret==FAIL) + setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE)); + } + } +#ifdef VERBOSE + if(retval==1) + std::cout << "Receiver Activated" << std::endl; + else if(retval==0) + std::cout << "Receiver Deactivated" << std::endl; + else + std::cout << "Receiver Activation unknown:" << retval << std::endl; +#endif + + return retval; } @@ -5547,6 +5579,7 @@ char* slsDetector::setReceiver(string receiverIP){ setTimer(FRAME_PERIOD,thisDetector->timerValue[FRAME_PERIOD]); setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]); setDynamicRange(thisDetector->dynamicRange); + activate(-1); //set scan tag setUDPConnection(); if(thisDetector->myDetectorType == EIGER)