From c0db1a89a82fd518093dfed3c513be279e027087 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 2 Aug 2016 10:32:37 +0200 Subject: [PATCH] deactivate for eiger --- slsDetectorSoftware/commonFiles/error_defs.h | 5 + .../commonFiles/sls_detector_defs.h | 2 - .../commonFiles/sls_detector_funcs.h | 2 + slsDetectorSoftware/eigerDetectorServer/Beb.c | 124 +++++++++++++++++- slsDetectorSoftware/eigerDetectorServer/Beb.h | 4 + .../eigerDetectorServer/FebRegisterDefs.h | 5 + .../slsDetectorFunctionList.c | 7 + .../slsDetectorServer_defs.h | 2 +- .../multiSlsDetector/multiSlsDetector.cpp | 19 +++ .../multiSlsDetector/multiSlsDetector.h | 5 + .../slsDetector/slsDetector.cpp | 42 ++++++ slsDetectorSoftware/slsDetector/slsDetector.h | 7 + .../slsDetector/slsDetectorBase.h | 8 ++ .../slsDetector/slsDetectorCommand.cpp | 15 +++ .../slsDetectorFunctionList.h | 1 + .../slsDetectorServer_funcs.c | 61 +++++++++ .../slsDetectorServer_funcs.h | 1 + 17 files changed, 306 insertions(+), 4 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 2ad16c404..2b501420a 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -32,6 +32,7 @@ using namespace std; #define RECEIVER_DET_HOSTNAME_NOT_SET 0x0040000000000000ULL #define RECEIVER_DET_HOSTTYPE_NOT_SET 0x0020000000000000ULL #define DETECTOR_TEN_GIGA 0x0010000000000000ULL +#define DETECTOR_ACTIVATE 0x0008000000000000ULL // 0xFFFFFFFF00000000ULL @@ -113,6 +114,10 @@ public: if(slsErrorMask&DETECTOR_TEN_GIGA) retval.append("Could not enable/disable 10GbE in the detector.\n"); + if(slsErrorMask&DETECTOR_ACTIVATE) + retval.append("Could not activate/deactivate detector\n"); + + diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index e6d11e0e9..dde67c21f 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -10,8 +10,6 @@ //#include #include "sls_receiver_defs.h" -#define REQUIRED_FIRMWARE_VERSION 14 - /** default maximum string length */ #define MAX_SCAN_STEPS 2000 /** maxmimum number of modules per controller*/ diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index b0c63f366..09bfff428 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -103,6 +103,8 @@ enum { F_SET_RATE_CORRECT, /** < set/reset rate correction tau */ F_GET_RATE_CORRECT, /** < get rate correction tau */ + F_ACTIVATE /** < activate/deactivate readout */ + /* Always append functions hereafter!!! */ }; diff --git a/slsDetectorSoftware/eigerDetectorServer/Beb.c b/slsDetectorSoftware/eigerDetectorServer/Beb.c index 7d718008c..8ed632faa 100644 --- a/slsDetectorSoftware/eigerDetectorServer/Beb.c +++ b/slsDetectorSoftware/eigerDetectorServer/Beb.c @@ -169,6 +169,128 @@ void Beb_GetModuleCopnfiguration(int* master, int* top){ } } +/* do not work at the moment */ +int Beb_SetMasterViaSoftware(){ + //mapping new memory + u_int32_t baseaddr, value = 0, ret = 1; + + //open file pointer + int fd = Beb_open(XPAR_PLB_GPIO_SYS_BASEADDR,&baseaddr); + if(fd < 0) + cprintf(BG_RED,"Set Master FAIL\n"); + else{ + value = Beb_Read32(baseaddr, MASTERCONFIG_OFFSET); + value|=MASTER_BIT; + value|=OVERWRITE_HARDWARE_BIT; + int newval = Beb_Write32(baseaddr, MASTERCONFIG_OFFSET,value); + if(newval!=value) + cprintf(BG_RED,"Could not set Master via Software\n"); + else + ret = 0; + } + + //close file pointer + if(fd > 0) + Beb_close(fd); + + return ret; +} + +/* do not work at the moment */ +int Beb_SetSlaveViaSoftware(){ + //mapping new memory + u_int32_t baseaddr, value = 0, ret = 1; + + //open file pointer + int fd = Beb_open(XPAR_PLB_GPIO_SYS_BASEADDR,&baseaddr); + if(fd < 0) + cprintf(BG_RED,"Set Slave FAIL\n"); + else{ + value = Beb_Read32(baseaddr, MASTERCONFIG_OFFSET); + value&=~MASTER_BIT; + value|=OVERWRITE_HARDWARE_BIT; + int newval = Beb_Write32(baseaddr, MASTERCONFIG_OFFSET,value); + if(newval!=value) + cprintf(BG_RED,"Could not set Slave via Software\n"); + else + ret = 0; + } + + //close file pointer + if(fd > 0) + Beb_close(fd); + + return ret; +} + +int Beb_Activate(int enable){ + //mapping new memory + u_int32_t baseaddr, value = 0, ret = -1; + + //open file pointer + int fd = Beb_open(XPAR_PLB_GPIO_SYS_BASEADDR,&baseaddr); + if(fd < 0) + cprintf(BG_RED,"Deactivate FAIL\n"); + else{ + if(enable > -1){ + value = Beb_Read32(baseaddr, MASTERCONFIG_OFFSET); + printf("Deactivate register value before:%d\n",value); + if(enable) + value&=~DEACTIVATE_BIT; + else + value|=DEACTIVATE_BIT; + + int newval = Beb_Write32(baseaddr, MASTERCONFIG_OFFSET,value); + if(newval!=value){ + if(enable) + cprintf(BG_RED,"Could not activate via Software\n"); + else + cprintf(BG_RED,"Could not deactivate via Software\n"); + } + } + + value = Beb_Read32(baseaddr, MASTERCONFIG_OFFSET); + if(value&DEACTIVATE_BIT) ret = 0; + else ret = 1; + if(enable == -1){ + if(ret) + cprintf(BLUE,"Detector is active. Register value:%d\n", value); + else + cprintf(BG_RED,"Detector is deactivated! Register value:%d\n", value); + } + + } + //close file pointer + if(fd > 0) + Beb_close(fd); + + return ret; +} + +int Beb_ResetToHardwareSettings(){ + //mapping new memory + u_int32_t baseaddr, value = 0, ret = 1; + + //open file pointer + int fd = Beb_open(XPAR_PLB_GPIO_SYS_BASEADDR,&baseaddr); + if(fd < 0) + cprintf(BG_RED,"Reset to Hardware Settings FAIL\n"); + else{ + value = Beb_Write32(baseaddr, MASTERCONFIG_OFFSET,0); + if(value) + cprintf(BG_RED,"Could not reset to hardware settings\n"); + else + ret = 0; + } + + //close file pointer + if(fd > 0) + Beb_close(fd); + + return ret; +} + + u_int32_t Beb_GetFirmwareRevision(){ //mapping new memory @@ -199,7 +321,7 @@ u_int32_t Beb_GetFirmwareSoftwareAPIVersion(){ //open file pointer int fd = Beb_open(XPAR_VERSION,&baseaddr); if(fd < 0) - cprintf(BG_RED,"Firmware Revision Read FAIL\n"); + cprintf(BG_RED,"Firmware Software API Version Read FAIL\n"); else{ value = Beb_Read32(baseaddr, FIRMWARESOFTWARE_API_OFFSET); if(!value) diff --git a/slsDetectorSoftware/eigerDetectorServer/Beb.h b/slsDetectorSoftware/eigerDetectorServer/Beb.h index 0d62fcd67..1948eee9d 100644 --- a/slsDetectorSoftware/eigerDetectorServer/Beb.h +++ b/slsDetectorSoftware/eigerDetectorServer/Beb.h @@ -48,6 +48,10 @@ struct BebInfo{ void Beb_GetModuleCopnfiguration(int* master, int* top); + int Beb_SetMasterViaSoftware(); + int Beb_SetSlaveViaSoftware(); + int Beb_Activate(int enable); + int Beb_ResetToHardwareSettings(); u_int32_t Beb_GetFirmwareRevision(); u_int32_t Beb_GetFirmwareSoftwareAPIVersion(); void Beb_ResetFrameNumber(); diff --git a/slsDetectorSoftware/eigerDetectorServer/FebRegisterDefs.h b/slsDetectorSoftware/eigerDetectorServer/FebRegisterDefs.h index 417c148f1..961e7b170 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebRegisterDefs.h +++ b/slsDetectorSoftware/eigerDetectorServer/FebRegisterDefs.h @@ -116,6 +116,11 @@ #define MASTER_BIT_MASK 0x200 // Master Slave Top Bottom Definition #define MODULE_CONFIGURATION_MASK 0x84 +//Software Configuration +#define MASTERCONFIG_OFFSET 0x160 //0x20 * 11 (P11) +#define MASTER_BIT 0x1 +#define OVERWRITE_HARDWARE_BIT 0x2 +#define DEACTIVATE_BIT 0x4 //command memory #define LEFT_OFFSET 0x0 diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c index 5b48f8cb7..82db02cf4 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c @@ -175,6 +175,7 @@ int initDetector(){ printf("mac read from detector: %llx\n",getDetectorMAC()); printf("ip read from detector: %x\n",getDetectorIP()); + printf("\n"); return 1; } @@ -1306,4 +1307,10 @@ int getBebFPGATemp() return Beb_GetBebFPGATemp(); } + +int activate(int enable){ + return Beb_Activate(enable); +} + + #endif diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h index 06e2bdc26..b6dbd9ac5 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h @@ -16,7 +16,7 @@ #define FEB_PORT 43210 #define BEB_PORT 43212 - +#define REQUIRED_FIRMWARE_VERSION 14 #define FIRMWAREREV 0xcaba //temporary should be in firmware diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 6acd95006..13fa1ab03 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1064,6 +1064,25 @@ string multiSlsDetector::checkOnline() { +int multiSlsDetector::activate(int const enable){ + int i; + int64_t ret1=-100, ret; + + for (i=0; inumberOfDetectors; i++) { + if (detectors[i]) { + ret=detectors[i]->activate(enable); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE)); + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } +#ifdef VERBOSE + if(retval) + std::cout << "Detector Activated" << std::endl; + else + std::cout << "Detector Deactivated" << std::endl; +#endif + return retval; + +} + + /* configure the socket communication and check that the server exists enum communicationProtocol{ diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index b74bbd6eb..0a62b600d 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -318,6 +318,13 @@ class slsDetector : public slsDetectorUtils, public energyConversion { string checkOnline(); + /** @short activates the detector (detector specific) + \param enable can be: -1 returns wether the detector is in active (1) or inactive (0) state + \returns 0 (inactive) or 1 (active) + */ + int activate(int const enable=GET_ONLINE_FLAG); + + /** returns if the detector already existed \returns 1 if the detector structure has already be initlialized, 0 otherwise */ int exists() {return thisDetector->alreadyExisting;}; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 7b6d11fb6..6a6612114 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -394,6 +394,14 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef \returns 0 (offline) or 1 (online) */ virtual int setOnline(int const online=-1)=0; + + /** @short activates the detector (detector specific) + \param enable can be: -1 returns wether the detector is in active (1) or inactive (0) state + \returns 0 (inactive) or 1 (active) + */ + virtual int activate(int const enable=GET_ONLINE_FLAG)=0; + + /** @short set detector settings \param isettings settings index (-1 gets) diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 1c5ba6765..06209a650 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -207,6 +207,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdOnline; i++; + descrToFuncMap[i].m_pFuncName="activate"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdOnline; + i++; + descrToFuncMap[i].m_pFuncName="enablefwrite"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdEnablefwrite; i++; @@ -2885,6 +2889,17 @@ string slsDetectorCommand::cmdOnline(int narg, char *args[], int action) { else strcat(ans," :Not online"); } + else if(cmd=="activate"){ + myDet->setOnline(ONLINE_FLAG); + if (action==PUT_ACTION) { + if (!sscanf(args[1],"%d",&ival)) + return string("Could not scan activate mode ")+string(args[1]); + /* if(dynamic_cast(myDet) != NULL) + return string("Can only set it from the multiDetector mode");*/ + myDet->activate(ival); + } + sprintf(ans,"%d",myDet->activate()); + } else if(cmd=="r_online"){ if (action==PUT_ACTION) { if (sscanf(args[1],"%d",&ival)) diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h index 9c4ba3c6f..0e0075859 100644 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h @@ -153,6 +153,7 @@ void setExternalGating(int enable[]); void setAllTrimbits(int val); int getAllTrimbits(); int getBebFPGATemp(); +int activate(int enable); #endif diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index f06b2aa51..e18f6ffd6 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -204,6 +204,7 @@ int function_table() { flist[F_PULSE_CHIP]=&pulse_chip; flist[F_SET_RATE_CORRECT]=&set_rate_correct; flist[F_GET_RATE_CORRECT]=&get_rate_correct; + flist[F_ACTIVATE]=&set_activate; #ifdef VERBOSE @@ -4021,3 +4022,63 @@ int get_rate_correct(int file_des) { return ret; } + + + + + + +int set_activate(int file_des) { + + int arg, n; + int ret=OK,ret1=OK; + int retval; + + sprintf(mess,"can't activate/deactivate detector\n"); + + n = receiveData(file_des,&arg,sizeof(arg),INT32); + if (n < 0) { + sprintf(mess,"Error reading from socket\n"); + ret=FAIL; + } + +#ifdef VERBOSE + printf("Setting activate mode of detector to %d\n",arg); +#endif + if (ret==OK) { + + if (differentClients==1 && lockStatus==1 && arg>=0) { + ret=FAIL; + sprintf(mess,"Detector locked by %s\n",lastClientIP); + } else { +#ifdef SLS_DETECTOR_FUNCTION_LIST +#ifdef EIGERD + retval=activate(arg); +#else + sprintf(mess,"Deactivate/Activate Not implemented for this detector\n"); + ret=FAIL; +#endif +#endif + } + if (ret==OK){ + if ((retval!=arg) && (arg!=-1)) { + ret=FAIL; + sprintf(mess,"Could not set activate mode to %d, is set to %d\n",arg, retval); + }else if (differentClients) + ret=FORCE_UPDATE; + + } + } + + + //ret could be swapped during sendData + ret1 = ret; + n = sendData(file_des,&ret1,sizeof(ret),INT32); + if (ret==FAIL) { + n = sendData(file_des,mess,sizeof(mess),OTHER); + } else { + n = sendData(file_des,&retval,sizeof(retval),INT32); + } + return ret; +} + diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h index a1bd9a16b..379e52d19 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h @@ -89,5 +89,6 @@ int pulse_pixel_and_move(int); int pulse_chip(int); int set_rate_correct(int); int get_rate_correct(int); +int set_activate(int); #endif