diff --git a/slsDetectorServers/eigerDetectorServer/Beb.c b/slsDetectorServers/eigerDetectorServer/Beb.c index 0513a3949..548280cfe 100644 --- a/slsDetectorServers/eigerDetectorServer/Beb.c +++ b/slsDetectorServers/eigerDetectorServer/Beb.c @@ -165,16 +165,15 @@ void Beb_GetModuleConfiguration(int *master, int *top, int *normal) { LOG(logERROR, ("Module Configuration FAIL\n")); } else { // read data - ret = Beb_Read32(csp0base, MODULE_CONFIGURATION_MASK); + ret = Beb_Read32(csp0base, BEB_CONFIG_RD_OFST); LOG(logDEBUG1, ("Module Configuration OK\n")); LOG(logDEBUG1, ("Beb: value =0x%x\n", ret)); - if (ret & TOP_BIT_MASK) { + if (ret & BEB_CONFIG_TOP_RD_MSK) { *top = 1; - Beb_top = 1; } - if (ret & MASTER_BIT_MASK) + if (ret & BEB_CONFIG_MASTER_RD_MSK) *master = 1; - if (ret & NORMAL_MODULE_BIT_MASK) + if (ret & BEB_CONFIG_NORMAL_RD_MSK) *normal = 1; // close file pointer Beb_close(fd, csp0base); @@ -298,125 +297,149 @@ int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay) { return OK; } -/* do not work at the moment */ -int Beb_SetMasterViaSoftware() { +void Beb_SetTopVariable(int val) { Beb_top = val; } +int Beb_SetTop(enum TOPINDEX ind) { if (!Beb_activated) return 0; - // mapping new memory u_int32_t *csp0base = 0; - u_int32_t value = 0, ret = 1; - - // open file pointer + u_int32_t value = 0; int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); if (fd < 0) { - LOG(logERROR, ("Set Master FAIL\n")); - } else { - value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET); - value |= MASTER_BIT; - value |= OVERWRITE_HARDWARE_BIT; - int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET, value); - if (newval != value) { - LOG(logERROR, ("Could not set Master via Software\n")); - } else { - ret = 0; - } + LOG(logERROR, ("Set Top FAIL, could not open fd in Beb\n")); + return 0; + } + value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST); + switch (ind) { + case TOP_HARDWARE: + value &= ~BEB_CONFIG_OW_TOP_MSK; + break; + case OW_TOP: + value |= BEB_CONFIG_OW_TOP_MSK; + value |= BEB_CONFIG_TOP_MSK; + break; + case OW_BOTTOM: + value |= BEB_CONFIG_OW_TOP_MSK; + value &= ~BEB_CONFIG_TOP_MSK; + break; + default: + LOG(logERROR, ("Unknown top index in Beb: %d\n", ind)); + Beb_close(fd, csp0base); + return 0; } - // close file pointer - if (fd > 0) + char *top_names[] = {TOP_NAMES}; + int newval = Beb_Write32(csp0base, BEB_CONFIG_WR_OFST, value); + if (newval != value) { + LOG(logERROR, + ("Could not set Top flag to %s in Beb\n", top_names[ind])); Beb_close(fd, csp0base); - - return ret; + return 0; + } + LOG(logINFOBLUE, + ("%s Top flag to %s in Beb\n", + (ind == TOP_HARDWARE ? "Resetting" : "Overwriting"), top_names[ind])); + Beb_close(fd, csp0base); + return 1; } -/* do not work at the moment */ -int Beb_SetSlaveViaSoftware() { - +int Beb_SetMaster(enum MASTERINDEX ind) { if (!Beb_activated) return 0; - // mapping new memory u_int32_t *csp0base = 0; - u_int32_t value = 0, ret = 1; - - // open file pointer + u_int32_t value = 0; int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); if (fd < 0) { - LOG(logERROR, ("Set Slave FAIL\n")); - } else { - value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET); - value &= ~MASTER_BIT; - value |= OVERWRITE_HARDWARE_BIT; - int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET, value); - if (newval != value) { - LOG(logERROR, ("Could not set Slave via Software\n")); - } else { - ret = 0; - } + LOG(logERROR, ("Set Master FAIL, could not open fd in Beb\n")); + return 0; + } + value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST); + switch (ind) { + case MASTER_HARDWARE: + value &= ~BEB_CONFIG_OW_MASTER_MSK; + break; + case OW_MASTER: + value |= BEB_CONFIG_OW_MASTER_MSK; + value |= BEB_CONFIG_MASTER_MSK; + break; + case OW_SLAVE: + value |= BEB_CONFIG_OW_MASTER_MSK; + value &= ~BEB_CONFIG_MASTER_MSK; + break; + default: + LOG(logERROR, ("Unknown master index in Beb: %d\n", ind)); + Beb_close(fd, csp0base); + return 0; } - // close file pointer - if (fd > 0) + char *master_names[] = {MASTER_NAMES}; + int newval = Beb_Write32(csp0base, BEB_CONFIG_WR_OFST, value); + if (newval != value) { + LOG(logERROR, + ("Could not set Master flag to %s in Beb\n", master_names[ind])); Beb_close(fd, csp0base); + return 0; + } + LOG(logINFOBLUE, ("%s Master flag to %s in Beb\n", + (ind == MASTER_HARDWARE ? "Resetting" : "Overwriting"), + master_names[ind])); - return ret; + Beb_close(fd, csp0base); + return 1; } -int Beb_Activate(int enable) { - // mapping new memory +int Beb_SetActivate(int enable) { + if (enable < 0) { + LOG(logERROR, ("Invalid enable value\n")); + return 0; + } u_int32_t *csp0base = 0; - u_int32_t value = 0, ret = -1; - - // open file pointer int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); if (fd < 0) { - LOG(logERROR, ("Deactivate FAIL\n")); + LOG(logERROR, ("Activate FAIL, could not open fd\n")); + return 0; } else { - if (enable > -1) { - value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET); - LOG(logINFO, ("Deactivate register value before:%d\n", value)); - if (enable) - value &= ~DEACTIVATE_BIT; - else - value |= DEACTIVATE_BIT; - - int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET, value); - if (newval != value) { - if (enable) { - LOG(logERROR, ("Could not activate via Software\n")); - } else { - LOG(logERROR, ("Could not deactivate via Software\n")); - } - } - } - - value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET); - if (value & DEACTIVATE_BIT) - ret = 0; + u_int32_t value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST); + LOG(logDEBUG, ("Activate register value before:%d\n", value)); + if (enable) + value |= BEB_CONFIG_ACTIVATE_MSK; else - ret = 1; - if (enable == -1) { - if (ret) { - LOG(logINFOBLUE, - ("Detector is active. Register value:%d\n", value)); - } else { - LOG(logERROR, - ("Detector is deactivated! Register value:%d\n", value)); - } + value &= ~BEB_CONFIG_ACTIVATE_MSK; + + u_int32_t retval = Beb_Write32(csp0base, BEB_CONFIG_WR_OFST, value); + if (retval != value) { + LOG(logERROR, + ("Could not %s. WRote 0x%x, read 0x%x\n", + (enable ? "activate" : "deactivate"), value, retval)); + Beb_close(fd, csp0base); } } - // close file pointer - if (fd > 0) - Beb_close(fd, csp0base); - - Beb_activated = ret; - - return ret; + Beb_activated = enable; + Beb_close(fd, csp0base); + return 1; } -int Beb_GetActivate() { return Beb_activated; } +int Beb_GetActivate(int *retval) { + u_int32_t *csp0base = 0; + int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); + if (fd < 0) { + LOG(logERROR, ("Activate FAIL, could not open fd\n")); + return 0; + } else { + u_int32_t value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST); + Beb_activated = (value & BEB_CONFIG_ACTIVATE_MSK) ? 1 : 0; + if (Beb_activated) { + LOG(logINFOBLUE, ("Detector is active\n")); + } else { + LOG(logINFORED, ("Detector is deactivated!\n")); + } + } + Beb_close(fd, csp0base); + *retval = Beb_activated; + return 1; +} int Beb_Set32bitOverflow(int val) { if (!Beb_activated) @@ -454,8 +477,7 @@ int Beb_Set32bitOverflow(int val) { FLOW_REG_OVERFLOW_32_BIT_OFST; } // close file pointer - if (fd > 0) - Beb_close(fd, csp0base); + Beb_close(fd, csp0base); return valueread; } @@ -465,8 +487,8 @@ int Beb_GetTenGigaFlowControl() { u_int32_t *csp0base = 0; int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); if (fd <= 0) { - LOG(logERROR, - ("Could not read register to get ten giga flow control. FAIL\n")); + LOG(logERROR, ("Could not read register to get ten giga flow " + "control. FAIL\n")); return -1; } else { u_int32_t retval = Beb_Read32(csp0base, offset); @@ -485,8 +507,8 @@ int Beb_SetTenGigaFlowControl(int value) { u_int32_t *csp0base = 0; int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); if (fd <= 0) { - LOG(logERROR, - ("Could not read register to set ten giga flow control. FAIL\n")); + LOG(logERROR, ("Could not read register to set ten giga flow " + "control. FAIL\n")); return 0; } else { // reset bit @@ -545,8 +567,8 @@ int Beb_GetTransmissionDelayLeft() { u_int32_t *csp0base = 0; int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); if (fd <= 0) { - LOG(logERROR, - ("Could not read register to get transmission delay left. FAIL\n")); + LOG(logERROR, ("Could not read register to get transmission delay " + "left. FAIL\n")); return -1; } else { u_int32_t retval = Beb_Read32(csp0base, offset); @@ -565,8 +587,8 @@ int Beb_SetTransmissionDelayLeft(int value) { u_int32_t *csp0base = 0; int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); if (fd <= 0) { - LOG(logERROR, - ("Could not read register to set transmission delay left. FAIL\n")); + LOG(logERROR, ("Could not read register to set transmission delay " + "left. FAIL\n")); return 0; } else { Beb_Write32(csp0base, offset, value); @@ -656,35 +678,6 @@ int Beb_SetNetworkParameter(enum NETWORKINDEX mode, int val) { return valueread; } -int Beb_ResetToHardwareSettings() { - - if (!Beb_activated) - return 1; - - // mapping new memory - u_int32_t *csp0base = 0; - u_int32_t value = 0, ret = 1; - - // open file pointer - int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); - if (fd < 0) { - LOG(logERROR, ("Reset to Hardware Settings FAIL\n")); - } else { - value = Beb_Write32(csp0base, MASTERCONFIG_OFFSET, 0); - if (value) { - LOG(logERROR, ("Could not reset to hardware settings\n")); - } else { - ret = 0; - } - } - - // close file pointer - if (fd > 0) - Beb_close(fd, csp0base); - - return ret; -} - u_int32_t Beb_GetFirmwareRevision() { // mapping new memory u_int32_t *csp0base = 0; @@ -697,8 +690,8 @@ u_int32_t Beb_GetFirmwareRevision() { } else { value = Beb_Read32(csp0base, FIRMWARE_VERSION_OFFSET); if (!value) { - LOG(logERROR, - ("Firmware Revision Number does not exist in this version\n")); + LOG(logERROR, ("Firmware Revision Number does not exist in " + "this version\n")); } } @@ -768,7 +761,8 @@ int Beb_InitBebInfos() { // file name at some point struct BebInfo b0; BebInfo_BebInfo(&b0, 0); if (BebInfo_SetSerialAddress( - &b0, 0xff)) { // all bebs for reset and possibly get request data? + &b0, + 0xff)) { // all bebs for reset and possibly get request data? beb_infos[bebInfoSize] = b0; bebInfoSize++; } @@ -794,11 +788,11 @@ int Beb_InitBebInfos() { // file name at some point //loop through file to fill vector. BebInfo* b = new BebInfo(26); b->SetSerialAddress(0); //0xc4000000 -b->SetHeaderInfo(0,"00:50:c2:46:d9:34","129.129.205.78",42000 + 26); // 1 GbE, -ip address can be acquire from the network "arp" +b->SetHeaderInfo(0,"00:50:c2:46:d9:34","129.129.205.78",42000 + 26); // 1 +GbE, ip address can be acquire from the network "arp" b->SetHeaderInfo(1,"00:50:c2:46:d9:35","10.0.26.1",52000 + 26); //10 GbE, everything calculable/setable beb_infos.push_back(b); - */ + */ return Beb_CheckSourceStuffBebInfo(); } @@ -809,9 +803,11 @@ int Beb_SetBebSrcHeaderInfos(unsigned int beb_number, int ten_gig, // so that the values can be reset externally for now.... unsigned int i = 1; /*Beb_GetBebInfoIndex(beb_number);*/ - /******* if (!i) return 0;****************************/ // i must be greater - // than 0, zero is - // the global send + /******* if (!i) return 0;****************************/ // i must be + // greater than + // 0, zero is + // the global + // send BebInfo_SetHeaderInfo(&beb_infos[i], ten_gig, src_mac, src_ip, src_port); LOG(logINFO, ("Printing Beb info number (%d) :\n", i)); @@ -954,7 +950,7 @@ udp_header_type udp_header = { {0x00, 0x00}, //{0x00, 0x11}, {0x00, 0x00} }; - */ + */ if (!Beb_SetMAC(src_mac, &(udp_header.src_mac[0]))) return 0; @@ -1167,8 +1163,8 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, unsigned int nl = Beb_readNLines; unsigned int npackets = (nl * maxnp) / maxnl; if ((nl * maxnp) % maxnl) { - LOG(logERROR, - ("Read N Lines is incorrect. Switching to Full Image Readout\n")); + LOG(logERROR, ("Read N Lines is incorrect. Switching to Full Image " + "Readout\n")); npackets = maxnp; } int in_two_requests = (npackets > MAX_PACKETS_PER_REQUEST) ? 1 : 0; @@ -1270,8 +1266,8 @@ int Beb_Test(unsigned int beb_number) { LOG(logINFO, ("Testing module number: %d\n", beb_number)); // int SetUpUDPHeader(unsigned int beb_number, int ten_gig, unsigned int - // header_number, string dst_mac, string dst_ip, unsigned int dst_port) { - // SetUpUDPHeader(26,0,0,"60:fb:42:f4:e3:d2","129.129.205.186",22000); + // header_number, string dst_mac, string dst_ip, unsigned int dst_port) + // { SetUpUDPHeader(26,0,0,"60:fb:42:f4:e3:d2","129.129.205.186",22000); unsigned int index = Beb_GetBebInfoIndex(beb_number); if (!index) { @@ -1288,9 +1284,10 @@ int Beb_Test(unsigned int beb_number) { } } - // SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, - // int ten_gig, unsigned int dst_number, unsigned int npackets, unsigned - // int packet_size, int stop_read_when_fifo_empty=1); + // SendMultiReadRequest(unsigned int beb_number, unsigned int + // left_right, int ten_gig, unsigned int dst_number, unsigned int + // npackets, unsigned int packet_size, int + // stop_read_when_fifo_empty=1); for (i = 0; i < 64; i++) { if (!Beb_SendMultiReadRequest(beb_number, i % 3 + 1, 0, i, 1, 0, 1)) { LOG(logERROR, ("Error requesting data....\n")); @@ -1532,8 +1529,8 @@ int Beb_GetStartingFrameNumber(uint64_t *retval, int tengigaEnable) { (long long int)left1g, (long long int)right1g)); *retval = (left1g > right1g) ? left1g - : right1g; // give max to set it to when stopping acq - // & different value + : right1g; // give max to set it to when stopping + // acq & different value return -2; // to differentiate between failed address mapping } *retval = left1g; @@ -1559,8 +1556,8 @@ int Beb_GetStartingFrameNumber(uint64_t *retval, int tengigaEnable) { (long long int)left10g, (long long int)right10g)); *retval = (left10g > right10g) ? left10g - : right10g; // give max to set it to when stopping acq - // & different value + : right10g; // give max to set it to when stopping + // acq & different value return -2; // to differentiate between failed address mapping } *retval = left10g; diff --git a/slsDetectorServers/eigerDetectorServer/Beb.h b/slsDetectorServers/eigerDetectorServer/Beb.h index 9c7187bf0..854d28e1b 100644 --- a/slsDetectorServers/eigerDetectorServer/Beb.h +++ b/slsDetectorServers/eigerDetectorServer/Beb.h @@ -36,10 +36,11 @@ unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb); void Beb_GetModuleConfiguration(int *master, int *top, int *normal); int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay); -int Beb_SetMasterViaSoftware(); -int Beb_SetSlaveViaSoftware(); -int Beb_Activate(int enable); -int Beb_GetActivate(); +void Beb_SetTopVariable(int val); +int Beb_SetTop(enum TOPINDEX ind); +int Beb_SetMaster(enum MASTERINDEX ind); +int Beb_SetActivate(int enable); +int Beb_GetActivate(int *retval); int Beb_Set32bitOverflow(int val); int Beb_GetTenGigaFlowControl(); @@ -51,7 +52,6 @@ int Beb_SetTransmissionDelayLeft(int value); int Beb_GetTransmissionDelayRight(); int Beb_SetTransmissionDelayRight(int value); -int Beb_ResetToHardwareSettings(); u_int32_t Beb_GetFirmwareRevision(); u_int32_t Beb_GetFirmwareSoftwareAPIVersion(); void Beb_ResetFrameNumber(); diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.c b/slsDetectorServers/eigerDetectorServer/FebControl.c index f5481fd7b..f5fc22ecb 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.c +++ b/slsDetectorServers/eigerDetectorServer/FebControl.c @@ -2459,29 +2459,110 @@ int Feb_Control_GetInterruptSubframe() { return value[0]; } +int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right) { + uint32_t offset = DAQ_REG_HRDWRE; + unsigned int addr[2] = {0, 0}; + if (left) { + addr[0] = Module_GetTopLeftAddress(&modules[1]); + } + if (right) { + addr[1] = Module_GetTopRightAddress(&modules[1]); + } + char *top_names[] = {TOP_NAMES}; + int i = 0; + for (i = 0; i < 2; ++i) { + if (addr[i] == 0) { + continue; + } + uint32_t value = 0; + if (!Feb_Interface_ReadRegister(addr[i], offset, &value)) { + LOG(logERROR, ("Could not read %s Feb reg to set Top flag\n", + (i == 0 ? "left" : "right"))); + return 0; + } + switch (ind) { + case TOP_HARDWARE: + value &= ~DAQ_REG_HRDWRE_OW_TOP_MSK; + break; + case OW_TOP: + value |= DAQ_REG_HRDWRE_OW_TOP_MSK; + value |= DAQ_REG_HRDWRE_TOP_MSK; + break; + case OW_BOTTOM: + value |= DAQ_REG_HRDWRE_OW_TOP_MSK; + value &= ~DAQ_REG_HRDWRE_TOP_MSK; + break; + default: + LOG(logERROR, ("Unknown top index in Feb: %d\n", ind)); + return 0; + } + if (!Feb_Interface_WriteRegister(addr[i], offset, value, 0, 0)) { + LOG(logERROR, ("Could not set Top flag to %s in %s Feb\n", + top_names[ind], (i == 0 ? "left" : "right"))); + return 0; + } + } + if (left && right) { + LOG(logINFOBLUE, ("%s Top flag to %s Feb\n", + (ind == TOP_HARDWARE ? "Resetting" : "Overwriting"), + top_names[ind])); + } + return 1; +} + +void Feb_Control_SetMasterVariable(int val) { Feb_control_master = val; } + +int Feb_Control_SetMaster(enum MASTERINDEX ind) { + uint32_t offset = DAQ_REG_HRDWRE; + unsigned int addr[2] = {0, 0}; + addr[0] = Module_GetTopLeftAddress(&modules[1]); + addr[1] = Module_GetTopRightAddress(&modules[1]); + char *master_names[] = {MASTER_NAMES}; + int i = 0; + for (i = 0; i < 2; ++i) { + uint32_t value = 0; + if (!Feb_Interface_ReadRegister(addr[i], offset, &value)) { + LOG(logERROR, ("Could not read %s Feb reg to set Master flag\n", + (i == 0 ? "left" : "right"))); + return 0; + } + switch (ind) { + case MASTER_HARDWARE: + value &= ~DAQ_REG_HRDWRE_OW_MASTER_MSK; + break; + case OW_MASTER: + value |= DAQ_REG_HRDWRE_OW_MASTER_MSK; + value |= DAQ_REG_HRDWRE_MASTER_MSK; + break; + case OW_SLAVE: + value |= DAQ_REG_HRDWRE_OW_MASTER_MSK; + value &= ~DAQ_REG_HRDWRE_MASTER_MSK; + break; + default: + LOG(logERROR, ("Unknown master index in Feb: %d\n", ind)); + return 0; + } + + if (!Feb_Interface_WriteRegister(addr[i], offset, value, 0, 0)) { + LOG(logERROR, ("Could not set Master flag to %s in %s Feb\n", + master_names[ind], (i == 0 ? "left" : "right"))); + return 0; + } + } + LOG(logINFOBLUE, ("%s Master flag to %s Feb\n", + (ind == MASTER_HARDWARE ? "Resetting" : "Overwriting"), + master_names[ind])); + return 1; +} + int Feb_Control_SetQuad(int val) { // no bottom for quad if (!Module_TopAddressIsValid(&modules[1])) { return 1; } - uint32_t offset = DAQ_REG_HRDWRE; LOG(logINFO, ("Setting Quad to %d in Feb\n", val)); - unsigned int addr = Module_GetTopRightAddress(&modules[1]); - uint32_t regVal = 0; - if (!Feb_Interface_ReadRegister(addr, offset, ®Val)) { - LOG(logERROR, ("Could not read top right quad reg\n")); - return 0; - } - uint32_t data = - ((val == 0) - ? (regVal & ~DAQ_REG_HRDWRE_OW_MSK) - : ((regVal | DAQ_REG_HRDWRE_OW_MSK) & ~DAQ_REG_HRDWRE_TOP_MSK)); - if (!Feb_Interface_WriteRegister(addr, offset, data, 0, 0)) { - LOG(logERROR, ("Could not write 0x%x to top right quad addr 0x%x\n", - data, offset)); - return 0; - } - return 1; + // only setting on the right feb if quad + return Feb_Control_SetTop(val == 0 ? TOP_HARDWARE : OW_TOP, 0, 1); } int Feb_Control_SetReadNLines(int value) { @@ -2565,6 +2646,7 @@ int Feb_Control_ReadRegister(uint32_t offset, uint32_t *retval) { addr[1] = Module_TopAddressIsValid(&modules[1]) ? Module_GetTopLeftAddress(&modules[1]) : Module_GetBottomLeftAddress(&modules[1]); + uint32_t value[2] = {0, 0}; int run[2] = {0, 0}; diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.h b/slsDetectorServers/eigerDetectorServer/FebControl.h index 4c7bc608a..7968e97c6 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.h +++ b/slsDetectorServers/eigerDetectorServer/FebControl.h @@ -1,5 +1,6 @@ #pragma once #include "FebInterface.h" +#include "slsDetectorServer_defs.h" #include struct Module { @@ -174,6 +175,10 @@ int64_t Feb_Control_GetSubMeasuredPeriod(); int Feb_Control_SoftwareTrigger(); int Feb_Control_SetInterruptSubframe(int val); int Feb_Control_GetInterruptSubframe(); + +int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right); +void Feb_Control_SetMasterVariable(int val); +int Feb_Control_SetMaster(enum MASTERINDEX ind); int Feb_Control_SetQuad(int val); int Feb_Control_SetReadNLines(int value); int Feb_Control_GetReadNLines(); diff --git a/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h b/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h index adf70a425..5c8d1db9c 100644 --- a/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h +++ b/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h @@ -16,21 +16,24 @@ #define DAQ_REG_PARTIAL_READOUT 8 #define DAQ_REG_HRDWRE 12 - -#define DAQ_REG_HRDWRE_OW_OFST (0) -#define DAQ_REG_HRDWRE_OW_MSK (0x00000001 << DAQ_REG_HRDWRE_OW_OFST) +// clang-format off +#define DAQ_REG_HRDWRE_OW_TOP_OFST (0) +#define DAQ_REG_HRDWRE_OW_TOP_MSK (0x00000001 << DAQ_REG_HRDWRE_OW_TOP_OFST) #define DAQ_REG_HRDWRE_TOP_OFST (1) #define DAQ_REG_HRDWRE_TOP_MSK (0x00000001 << DAQ_REG_HRDWRE_TOP_OFST) #define DAQ_REG_HRDWRE_INTRRPT_SF_OFST (2) -#define DAQ_REG_HRDWRE_INTRRPT_SF_MSK \ - (0x00000001 << DAQ_REG_HRDWRE_INTRRPT_SF_OFST) +#define DAQ_REG_HRDWRE_INTRRPT_SF_MSK (0x00000001 << DAQ_REG_HRDWRE_INTRRPT_SF_OFST) +#define DAQ_REG_HRDWRE_OW_MASTER_OFST (3) +#define DAQ_REG_HRDWRE_OW_MASTER_MSK (0x00000001 << DAQ_REG_HRDWRE_OW_MASTER_OFST) +#define DAQ_REG_HRDWRE_MASTER_OFST (4) +#define DAQ_REG_HRDWRE_MASTER_MSK (0x00000001 << DAQ_REG_HRDWRE_MASTER_OFST) -#define DAQ_REG_RO_OFFSET 20 -#define DAQ_REG_STATUS \ - (DAQ_REG_RO_OFFSET + 0) // also pg and fifo status register +#define DAQ_REG_RO_OFFSET 20 +#define DAQ_REG_STATUS (DAQ_REG_RO_OFFSET + 0) // also pg and fifo status register #define FEB_REG_STATUS (DAQ_REG_RO_OFFSET + 3) #define MEAS_SUBPERIOD_REG (DAQ_REG_RO_OFFSET + 4) #define MEAS_PERIOD_REG (DAQ_REG_RO_OFFSET + 5) +// clang-format on #define DAQ_CTRL_RESET 0x80000000 #define DAQ_CTRL_START 0x40000000 @@ -52,10 +55,11 @@ #define DAQ_SERIALIN_SHIFT_IN_32 0x00000100 #define DAQ_LOAD_16ROWS_OF_TRIMBITS 0x00000200 -#define DAQ_IGNORE_INITIAL_CRAP 0x00000400 // crap before readout +// crap before readout +#define DAQ_IGNORE_INITIAL_CRAP 0x00000400 #define DAQ_READOUT_NROWS 0x00000800 -#define DAQ_CLKOUT_LAST_4_BITS_AND_RETURN_TO_START \ - 0x00001000 // last 4 bit of data in the last frame +// last 4 bit of data in the last frame +#define DAQ_CLKOUT_LAST_4_BITS_AND_RETURN_TO_START 0x00001000 #define DAQ_RELEASE_IMAGE_STORE_AFTER_READOUT 0x00002000 #define DAQ_RESET_PIXEL_COUNTERS_AFTER_READOUT 0x00004000 @@ -64,23 +68,24 @@ #define DAQ_CLK_MAIN_CLK_TO_SELECT_NEXT_PIXEL 0x00010000 #define DAQ_SEND_N_TEST_PULSES 0x00020000 -#define DAQ_CHIP_CONTROLLER_HALF_SPEED \ - 0x00040000 // everything at 100 MHz (50MHz ddr readout) -#define DAQ_CHIP_CONTROLLER_QUARTER_SPEED \ - 0x00080000 // everything at 50 MHz (25MHz ddr readout) -#define DAQ_CHIP_CONTROLLER_SUPER_SLOW_SPEED \ - 0x000c0000 // everything at ~200 kHz (200 kHz MHz ddr readout) +// everything at 100 MHz (50MHz ddr readout) +#define DAQ_CHIP_CONTROLLER_HALF_SPEED 0x00040000 +// everything at 50 MHz (25MHz ddr readout) +#define DAQ_CHIP_CONTROLLER_QUARTER_SPEED 0x00080000 +// everything at ~200 kHz (200 kHz MHz ddr readout) +#define DAQ_CHIP_CONTROLLER_SUPER_SLOW_SPEED 0x000c0000 -//#define DAQ_FIFO_ENABLE 0x00100000 commented out as it +//#define DAQ_FIFO_ENABLE 0x00100000 commented out as it // is not used anywhere #define DAQ_REG_CHIP_CMDS_INT_TRIGGER 0x00100000 // direct chip commands to the DAQ_REG_CHIP_CMDS register -#define DAQ_NEXPOSURERS_SAFEST_MODE_ROW_CLK_BEFORE_MODE \ - 0x00200000 // row clk is before main clk readout sequence -#define DAQ_NEXPOSURERS_NORMAL_NONPARALLEL_MODE \ - 0x00400000 // expose ->readout ->expose -> ..., with store is always closed -#define DAQ_NEXPOSURERS_PARALLEL_MODE 0x00600000 // parallel acquire/read mode +// row clk is before main clk readout sequence +#define DAQ_NEXPOSURERS_SAFEST_MODE_ROW_CLK_BEFORE_MODE 0x00200000 +// expose ->readout ->expose -> ..., with store is always closed +#define DAQ_NEXPOSURERS_NORMAL_NONPARALLEL_MODE 0x00400000 +// parallel acquire/read mode +#define DAQ_NEXPOSURERS_PARALLEL_MODE 0x00600000 // DAQ_NEXPOSURERS_READOUT_COMPLETE_IMAGES is old now hard-wired in the firmware // that every image comes with a header #define @@ -91,12 +96,14 @@ #define DAQ_NEXPOSURERS_EXTERNAL_ENABLING_POLARITY 0x02000000 #define DAQ_NEXPOSURERS_EXTERNAL_TRIGGER_POLARITY 0x04000000 -#define DAQ_NEXPOSURERS_INTERNAL_ACQUISITION 0x00000000 // internally controlled -#define DAQ_NEXPOSURERS_EXTERNAL_ACQUISITION_START \ - 0x08000000 // external acquisition start -#define DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START 0x10000000 // external image start -#define DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START_AND_STOP \ - 0x18000000 // externally controlly, external image start and stop +// internally controlled +#define DAQ_NEXPOSURERS_INTERNAL_ACQUISITION 0x00000000 +// external acquisition start +#define DAQ_NEXPOSURERS_EXTERNAL_ACQUISITION_START 0x08000000 +// external image start +#define DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START 0x10000000 +// externally controlly, external image start and stop +#define DAQ_NEXPOSURERS_EXTERNAL_IMAGE_START_AND_STOP 0x18000000 #define DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING 0x20000000 #define DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION 0x40000000 @@ -106,11 +113,12 @@ // chips static bits #define DAQ_STATIC_BIT_PROGRAM 0x00000001 -#define DAQ_STATIC_BIT_M4 0x00000002 // these are the status bits, not bit mode -#define DAQ_STATIC_BIT_M8 0x00000004 // these are the status bits, not bit mode -#define DAQ_STATIC_BIT_M12 \ - 0x00000000 // these are the status bits, not bit mode, ie. "00" is 12 bit - // mode +// these are the status bits, not bit mode +#define DAQ_STATIC_BIT_M4 0x00000002 +#define DAQ_STATIC_BIT_M8 0x00000004 +// these are the status bits, not bit mode, ie. "00" is 12 bit mode +#define DAQ_STATIC_BIT_M12 0x00000000 + #define DAQ_STATIC_BIT_CHIP_TEST 0x00000008 #define DAQ_STATIC_BIT_ROTEST 0x00000010 #define DAQ_CS_BAR_LEFT 0x00000020 @@ -136,18 +144,28 @@ #define CHIP_DATA_OUT_DELAY_REG4 4 #define CHIP_DATA_OUT_DELAY_SET 0x20000000 -// module configuration -#define TOP_BIT_MASK 0x00f -#define MASTER_BIT_MASK 0x200 -#define NORMAL_MODULE_BIT_MASK 0x400 +/** BEB Registers */ -// 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 +// module configuration - XPAR_PLB_GPIO_SYS_BASEADDR +#define BEB_CONFIG_WR_OFST (0x160) // 0x20 * 11 (P11) +#define BEB_CONFIG_MASTER_OFST (0) +#define BEB_CONFIG_MASTER_MSK (0x00000001 << BEB_CONFIG_MASTER_OFST) +#define BEB_CONFIG_OW_MASTER_OFST (1) +#define BEB_CONFIG_OW_MASTER_MSK (0x00000001 << BEB_CONFIG_OW_MASTER_OFST) +#define BEB_CONFIG_ACTIVATE_OFST (2) +#define BEB_CONFIG_ACTIVATE_MSK (0x00000001 << BEB_CONFIG_ACTIVATE_OFST) +#define BEB_CONFIG_TOP_OFST (3) +#define BEB_CONFIG_TOP_MSK (0x00000001 << BEB_CONFIG_TOP_OFST) +#define BEB_CONFIG_OW_TOP_OFST (4) +#define BEB_CONFIG_OW_TOP_MSK (0x00000001 << BEB_CONFIG_OW_TOP_OFST) + +#define BEB_CONFIG_RD_OFST (0x84) +#define BEB_CONFIG_TOP_RD_OFST (0) +#define BEB_CONFIG_TOP_RD_MSK (0x00000001 << BEB_CONFIG_TOP_RD_OFST) +#define BEB_CONFIG_MASTER_RD_OFST (9) +#define BEB_CONFIG_MASTER_RD_MSK (0x00000001 << BEB_CONFIG_MASTER_RD_OFST) +#define BEB_CONFIG_NORMAL_RD_OFST (10) +#define BEB_CONFIG_NORMAL_RD_MSK (0x00000001 << BEB_CONFIG_NORMAL_RD_OFST) #define FPGA_TEMP_OFFSET 0x200 diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index c856bbc73..d47786227 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/config.txt b/slsDetectorServers/eigerDetectorServer/config.txt new file mode 100644 index 000000000..5bd098888 --- /dev/null +++ b/slsDetectorServers/eigerDetectorServer/config.txt @@ -0,0 +1,2 @@ +top 1 +master 1 diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 704dac051..c9e4a71df 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -226,6 +226,19 @@ u_int64_t getFirmwareAPIVersion() { #endif } +void readDetectorNumber() { +#ifndef VIRTUAL + char output[255]; + FILE *sysFile = popen(IDFILECOMMAND, "r"); + fgets(output, sizeof(output), sysFile); + pclose(sysFile); + sscanf(output, "%u", &detid); + if (isControlServer) { + LOG(logINFOBLUE, ("Detector ID: %u\n", detid)); + } +#endif +} + u_int32_t getDetectorNumber() { #ifdef VIRTUAL return 0; @@ -309,85 +322,67 @@ u_int32_t getDetectorIP() { /* initialization */ void initControlServer() { -#ifdef VIRTUAL + LOG(logINFOBLUE, ("Configuring Control server\n")); if (initError == OK) { + readDetectorNumber(); getModuleConfiguration(); - setupDetector(); - } - initCheckDone = 1; - return; -#else - if (initError == OK) { - // Feb and Beb Initializations - getModuleConfiguration(); +#ifndef VIRTUAL + Feb_Control_SetMasterVariable(master); Feb_Interface_FebInterface(); Feb_Control_FebControl(); - // different addresses for top and bottom - if (getFirmwareVersion() < FIRMWARE_VERSION_SAME_TOP_BOT_ADDR) { - Feb_Control_Init(master, top, normal, getDetectorNumber()); - } // same addresses for top and bottom - else { - Feb_Control_Init(master, 1, normal, getDetectorNumber()); - } + Feb_Control_Init(master, 1, normal, getDetectorNumber()); // master of 9M, check high voltage serial communication to blackfin if (master && !normal) { if (Feb_Control_OpenSerialCommunication()) ; // Feb_Control_CloseSerialCommunication(); } LOG(logDEBUG1, ("Control server: FEB Initialization done\n")); + Beb_SetTopVariable(top); Beb_Beb(detid); Beb_SetDetectorNumber(getDetectorNumber()); LOG(logDEBUG1, ("Control server: BEB Initialization done\n")); - +#endif + // also reads config file and deactivates setupDetector(); - // activate (if it gets ip) (later FW will deactivate at startup) - if (getDetectorIP() != 0) { - Beb_Activate(1); - Feb_Control_activate(1); - } else { - Beb_Activate(0); - Feb_Control_activate(0); - } } initCheckDone = 1; -#endif } void initStopServer() { #ifdef VIRTUAL + LOG(logINFOBLUE, ("Configuring Stop server\n")); getModuleConfiguration(); virtual_stop = 0; if (!isControlServer) { ComVirtual_setStop(virtual_stop); } - return; + // get top/master in virtual + readConfigFile(); #else + // wait a few s (control server is setting top/master from config file) + usleep(WAIT_STOP_SERVER_START); + LOG(logINFOBLUE, ("Configuring Stop server\n")); + // exit(-1); + readDetectorNumber(); getModuleConfiguration(); + Feb_Control_SetMasterVariable(master); Feb_Interface_FebInterface(); Feb_Control_FebControl(); - // different addresses for top and bottom - if (getFirmwareVersion() < FIRMWARE_VERSION_SAME_TOP_BOT_ADDR) { - Feb_Control_Init(master, top, normal, getDetectorNumber()); - } // same addresses for top and bottom - else { - Feb_Control_Init(master, 1, normal, getDetectorNumber()); - } + Feb_Control_Init(master, 1, normal, getDetectorNumber()); LOG(logDEBUG1, ("Stop server: FEB Initialization done\n")); - // activate (if it gets ip) (later FW will deactivate at startup) - // also needed for stop server for status - if (getDetectorIP() != 0) { - Beb_Activate(1); - Feb_Control_activate(1); - } else { - Beb_Activate(0); - Feb_Control_activate(0); - } #endif + // client first connect (from shm) will activate + if (setActivate(0) == FAIL) { + LOG(logERROR, ("Could not deactivate in stop server\n")); + } } void getModuleConfiguration() { + if (initError == FAIL) { + return; + } #ifdef VIRTUAL #ifdef VIRTUAL_MASTER master = 1; @@ -400,34 +395,219 @@ void getModuleConfiguration() { top = 0; #endif #endif + #ifdef VIRTUAL_9M normal = 0; #else normal = 1; #endif - LOG(logINFOBLUE, - ("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"), - (master ? "MASTER" : "SLAVE"), (normal ? "NORMAL" : "SPECIAL"))); - return; + #else - int *m = &master; - int *t = ⊤ - int *n = &normal; - Beb_GetModuleConfiguration(m, t, n); + Beb_GetModuleConfiguration(&master, &top, &normal); +#endif if (isControlServer) { LOG(logINFOBLUE, ("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"), (master ? "MASTER" : "SLAVE"), (normal ? "NORMAL" : "SPECIAL"))); } +} - // read detector id - char output[255]; - FILE *sysFile = popen(IDFILECOMMAND, "r"); - fgets(output, sizeof(output), sysFile); - pclose(sysFile); - sscanf(output, "%u", &detid); - if (isControlServer) { - LOG(logINFOBLUE, ("Detector ID: %u\n\n", detid)); +int readConfigFile() { + + if (initError == FAIL) { + return initError; + } + master = -1; + top = -1; + FILE *fd = fopen(CONFIG_FILE, "r"); + if (fd == NULL) { + LOG(logINFO, ("No config file found. Resetting to hardware settings " + "(Top/Master)\n")); + // reset to hardware settings if not in config file (if overwritten) + resetToHardwareSettings(); + return initError; + } + LOG(logINFO, ("Reading config file %s\n", CONFIG_FILE)); + + // Initialization + const size_t LZ = 256; + char line[LZ]; + memset(line, 0, LZ); + char command[LZ]; + + // keep reading a line + while (fgets(line, LZ, fd)) { + // ignore comments + if (line[0] == '#') { + LOG(logDEBUG1, ("Ignoring Comment\n")); + continue; + } + + // ignore empty lines + if (strlen(line) <= 1) { + LOG(logDEBUG1, ("Ignoring Empty line\n")); + continue; + } + + // ignoring lines beginning with space or tab + if (line[0] == ' ' || line[0] == '\t') { + LOG(logDEBUG1, ("Ignoring Lines starting with space or tabs\n")); + continue; + } + + LOG(logDEBUG1, ("Command to process: (size:%d) %.*s\n", strlen(line), + strlen(line) - 1, line)); + memset(command, 0, LZ); + + // top command + if (!strncmp(line, "top", strlen("top"))) { + // cannot scan values + if (sscanf(line, "%s %d", command, &top) != 2) { + sprintf(initErrorMessage, + "Could not scan top commands from on-board server " + "config file. Line:[%s].\n", + line); + break; + } +#ifndef VIRTUAL + enum TOPINDEX ind = (top == 1 ? OW_TOP : OW_BOTTOM); + if (!Beb_SetTop(ind)) { + sprintf( + initErrorMessage, + "Could not overwrite top to %d in Beb from on-board server " + "config file. Line:[%s].\n", + top, line); + break; + } + if (!Feb_Control_SetTop(ind, 1, 1)) { + sprintf( + initErrorMessage, + "Could not overwrite top to %d in Feb from on-board server " + "config file. Line:[%s].\n", + top, line); + break; + } + // validate change + int actual_top = -1, temp = -1, temp2 = -1; + Beb_GetModuleConfiguration(&temp, &actual_top, &temp2); + if (actual_top != top) { + sprintf(initErrorMessage, "Could not set top to %d. Read %d\n", + top, actual_top); + break; + } + Beb_SetTopVariable(top); +#endif + } + + // master command + else if (!strncmp(line, "master", strlen("master"))) { + // cannot scan values + if (sscanf(line, "%s %d", command, &master) != 2) { + sprintf(initErrorMessage, + "Could not scan master commands from on-board server " + "config file. Line:[%s].\n", + line); + break; + } +#ifndef VIRTUAL + enum MASTERINDEX ind = (master == 1 ? OW_MASTER : OW_SLAVE); + if (!Beb_SetMaster(ind)) { + sprintf(initErrorMessage, + "Could not overwrite master to %d in Beb from on-board " + "server " + "config file. Line:[%s].\n", + master, line); + break; + } + if (!Feb_Control_SetMaster(ind)) { + sprintf(initErrorMessage, + "Could not overwrite master to %d in Feb from on-board " + "server " + "config file. Line:[%s].\n", + master, line); + break; + } + // validate change + int actual_master = -1, temp = -1, temp2 = -1; + Beb_GetModuleConfiguration(&actual_master, &temp, &temp2); + if (actual_master != master) { + sprintf(initErrorMessage, + "Could not set master to %d. Read %d\n", master, + actual_master); + break; + } + Feb_Control_SetMasterVariable(master); +#endif + } + + // other commands + else { + sprintf(initErrorMessage, + "Could not scan command from on-board server " + "config file. Line:[%s].\n", + line); + break; + } + } + fclose(fd); + + if (strlen(initErrorMessage)) { + initError = FAIL; + LOG(logERROR, ("%s\n\n", initErrorMessage)); + } else { + LOG(logINFO, ("Successfully read config file\n")); + } + + // reset to hardware settings if not in config file (if overwritten) + resetToHardwareSettings(); + + return initError; +} + +void resetToHardwareSettings() { +#ifndef VIRTUAL + if (initError == FAIL) { + return; + } + // top not set in config file + if (top == -1) { + if (!Beb_SetTop(TOP_HARDWARE)) { + initError = FAIL; + strcpy(initErrorMessage, + "Could not reset Top flag to Beb hardware settings.\n"); + LOG(logERROR, ("%s\n\n", initErrorMessage)); + return; + } + if (!Feb_Control_SetTop(TOP_HARDWARE, 1, 1)) { + initError = FAIL; + strcpy(initErrorMessage, + "Could not reset Top flag to Feb hardware settings.\n"); + LOG(logERROR, ("%s\n\n", initErrorMessage)); + return; + } + int temp = -1, temp2 = -1; + Beb_GetModuleConfiguration(&temp, &top, &temp2); + Beb_SetTopVariable(top); + } + // master not set in config file + if (master == -1) { + if (!Beb_SetMaster(TOP_HARDWARE)) { + initError = FAIL; + strcpy(initErrorMessage, + "Could not reset Master flag to Beb hardware settings.\n"); + LOG(logERROR, ("%s\n\n", initErrorMessage)); + return; + } + if (!Feb_Control_SetMaster(TOP_HARDWARE)) { + initError = FAIL; + strcpy(initErrorMessage, + "Could not reset Master flag to Feb hardware settings.\n"); + LOG(logERROR, ("%s\n\n", initErrorMessage)); + return; + } + int temp = -1, temp2 = -1; + Beb_GetModuleConfiguration(&master, &temp, &temp2); + Feb_Control_SetMasterVariable(master); } #endif } @@ -517,6 +697,20 @@ void setupDetector() { #ifndef VIRTUAL Feb_Control_CheckSetup(); #endif + // force top or master if in config file + if (readConfigFile() == FAIL) { + return; + } + LOG(logINFOBLUE, + ("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"), + (master ? "MASTER" : "SLAVE"), (normal ? "NORMAL" : "SPECIAL"))); + + // client first connect (from shm) will activate + if (setActivate(0) == FAIL) { + initError = FAIL; + sprintf(initErrorMessage, "Could not deactivate\n"); + LOG(logERROR, (initErrorMessage)); + } LOG(logDEBUG1, ("Setup detector done\n\n")); } @@ -1681,16 +1875,38 @@ int getBebFPGATemp() { #endif } -int activate(int enable) { +int setActivate(int enable) { + if (enable < 0) { + LOG(logERROR, ("Invalid activate argument: %d\n", enable)); + return FAIL; + } #ifdef VIRTUAL - if (enable >= 0) - eiger_virtual_activate = enable; - return eiger_virtual_activate; + eiger_virtual_activate = enable; #else - int ret = Beb_Activate(enable); - Feb_Control_activate(ret); - return ret; + if (!Beb_SetActivate(enable)) { + return FAIL; + } + Feb_Control_activate(enable); #endif + if (enable) { + LOG(logINFOGREEN, ("Activated in %s Server!\n", + isControlServer ? " Control" : "Stop")); + } else { + LOG(logINFORED, ("Deactivated in %s Server!\n", + isControlServer ? " Control" : "Stop")); + } + return OK; +} + +int getActivate(int *retval) { +#ifdef VIRTUAL + *retval = eiger_virtual_activate; +#else + if (!Beb_GetActivate(retval)) { + return FAIL; + } +#endif + return OK; } int getTenGigaFlowControl() { @@ -1939,8 +2155,7 @@ void *start_timer(void *arg) { memset(packetData, 0, packetsize); sls_detector_header *header = (sls_detector_header *)(packetData); - header->detType = 3; //(uint16_t)myDetectorType; updated - // when firmware updates + header->detType = (uint16_t)myDetectorType; header->version = SLS_DETECTOR_HEADER_VERSION - 1; header->frameNumber = frameNr + iframes; header->packetNumber = i; @@ -1950,8 +2165,7 @@ void *start_timer(void *arg) { char packetData2[packetsize]; memset(packetData2, 0, packetsize); header = (sls_detector_header *)(packetData2); - header->detType = 3; //(uint16_t)myDetectorType; updated - // when firmware updates + header->detType = (uint16_t)myDetectorType; header->version = SLS_DETECTOR_HEADER_VERSION - 1; header->frameNumber = frameNr + iframes; header->packetNumber = i; @@ -2091,7 +2305,7 @@ int startReadOut() { // for(i=0;i= 0) { + if (setActivate(arg) == FAIL) { + ret = FAIL; + sprintf(mess, "Could not %s\n", + (arg == 0 ? "deactivate" : "activate")); + LOG(logERROR, (mess)); + } + } + if (ret == OK) { + if (getActivate(&retval) == FAIL) { + ret = FAIL; + sprintf(mess, "Could not get activate flag\n"); + LOG(logERROR, (mess)); + } else { + LOG(logDEBUG1, ("Activate: %d\n", retval)); + validate(arg, retval, "set/get activate", DEC); + } + } } #endif return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); @@ -7264,7 +7279,8 @@ int get_receiver_parameters(int file_des) { // activate #ifdef EIGERD - i32 = activate(-1); + i32 = 0; + getActivate(&i32); #else i32 = 0; #endif diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index cc3601d2e..9124ea932 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -791,7 +791,7 @@ class Detector { Result getActive(Positions pos = {}) const; /** [Eiger] */ - void setActive(bool active, Positions pos = {}); + void setActive(const bool active, Positions pos = {}); /** [Eiger] */ Result getRxPadDeactivatedMode(Positions pos = {}) const; diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 5faf17696..3422cde97 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1031,11 +1031,11 @@ Result Detector::getMeasuredSubFramePeriod(Positions pos) const { } Result Detector::getActive(Positions pos) const { - return pimpl->Parallel(&Module::activate, pos, -1); + return pimpl->Parallel(&Module::getActivate, pos); } -void Detector::setActive(bool active, Positions pos) { - pimpl->Parallel(&Module::activate, pos, static_cast(active)); +void Detector::setActive(const bool active, Positions pos) { + pimpl->Parallel(&Module::setActivate, pos, active); } Result Detector::getRxPadDeactivatedMode(Positions pos) const { diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index cd19db752..5cb1c185c 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -515,7 +515,7 @@ void DetectorImpl::readFrameFromReceiver() { nDetPixelsX = nX * nPixelsX; nDetPixelsY = nY * nPixelsY; // det type - eiger = (zHeader.detType == static_cast(3)) + eiger = (zHeader.detType == EIGER) ? true : false; // to be changed to EIGER when // firmware updates its header data diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 472b25ee4..909e92927 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -344,19 +344,19 @@ void Module::setHostname(const std::string &hostname, sls::strcpy_safe(shm()->hostname, hostname.c_str()); auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.close(); - - LOG(logINFO) << "Checking Detector Version Compatibility"; - if (!initialChecks) { - try { - checkDetectorVersionCompatibility(); - } catch (const DetectorError &e) { - LOG(logWARNING) << "Bypassing Initial Checks at your own risk!"; - } - } else { + try { checkDetectorVersionCompatibility(); + LOG(logINFO) << "Detector Version Compatibility - Success"; + } catch (const DetectorError &e) { + if (!initialChecks) { + LOG(logWARNING) << "Bypassing Initial Checks at your own risk!"; + } else { + throw; + } + } + if (shm()->myDetectorType == EIGER) { + setActivate(true); } - - LOG(logINFO) << "Detector connecting - updating!"; } std::string Module::getHostname() const { return shm()->hostname; } @@ -2186,16 +2186,29 @@ void Module::writeAdcRegister(uint32_t addr, uint32_t val) { sendToDetector(F_WRITE_ADC_REG, args, nullptr); } -int Module::activate(int enable) { +bool Module::getActivate() { + int retval = -1, retval2 = -1; + int arg = -1; + sendToDetector(F_ACTIVATE, arg, retval); + sendToDetectorStop(F_ACTIVATE, arg, retval2); + if (retval != retval2) { + std::ostringstream oss; + oss << "Inconsistent activate state. Control Server: " << retval + << ". Stop Server: " << retval2; + throw RuntimeError(oss.str()); + } + return retval; +} + +void Module::setActivate(const bool enable) { int retval = -1; + int arg = static_cast(enable); LOG(logDEBUG1) << "Setting activate flag to " << enable; - sendToDetector(F_ACTIVATE, enable, retval); - sendToDetectorStop(F_ACTIVATE, enable, retval); - LOG(logDEBUG1) << "Activate: " << retval; + sendToDetector(F_ACTIVATE, arg, retval); + sendToDetectorStop(F_ACTIVATE, arg, retval); if (shm()->useReceiverFlag) { sendToReceiver(F_RECEIVER_ACTIVATE, retval, nullptr); } - return retval; } bool Module::getDeactivatedRxrPaddingMode() { diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index f6cb36b41..c7dc1e716 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -1095,12 +1095,8 @@ class Module : public virtual slsDetectorDefs { */ void writeAdcRegister(uint32_t addr, uint32_t val); - /** - * Activates/Deactivates the detector (Eiger only) - * @param enable active (1) or inactive (0), -1 gets - * @returns 0 (inactive) or 1 (active)for activate mode - */ - int activate(int const enable = -1); + bool getActivate(); + void setActivate(const bool enable); bool getDeactivatedRxrPaddingMode(); diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index f4d94ea03..0c70a2b72 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -4,10 +4,10 @@ #define APIRECEIVER 0x200409 #define APIGUI 0x200409 -#define APICTB 0x200508 -#define APIGOTTHARD 0x200508 +#define APICTB 0x200508 +#define APIGOTTHARD 0x200508 #define APIGOTTHARD2 0x200508 -#define APIJUNGFRAU 0x200508 -#define APIMYTHEN3 0x200508 -#define APIMOENCH 0x200508 -#define APIEIGER 0x200508 +#define APIJUNGFRAU 0x200508 +#define APIMYTHEN3 0x200508 +#define APIMOENCH 0x200508 +#define APIEIGER 0x200513