From 13c1f7c2d6d5b0672e60472ae39da62f8ccbaec8 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 8 May 2020 16:31:26 +0200 Subject: [PATCH] WIP --- slsDetectorServers/eigerDetectorServer/Beb.c | 115 ++++------- slsDetectorServers/eigerDetectorServer/Beb.h | 5 +- .../eigerDetectorServer/FebControl.c | 92 +++++++-- .../eigerDetectorServer/FebControl.h | 3 + .../eigerDetectorServer/FebRegisterDefs.h | 108 +++++----- .../eigerDetectorServer/config.txt | 2 + .../slsDetectorFunctionList.c | 187 ++++++++++++++---- .../slsDetectorServer_defs.h | 3 +- .../include/slsDetectorFunctionList.h | 2 +- slsDetectorSoftware/include/Detector.h | 2 +- slsDetectorSoftware/src/Detector.cpp | 6 +- slsDetectorSoftware/src/DetectorImpl.cpp | 2 +- slsDetectorSoftware/src/Module.cpp | 45 +++-- slsDetectorSoftware/src/Module.h | 8 +- 14 files changed, 377 insertions(+), 203 deletions(-) create mode 100644 slsDetectorServers/eigerDetectorServer/config.txt diff --git a/slsDetectorServers/eigerDetectorServer/Beb.c b/slsDetectorServers/eigerDetectorServer/Beb.c index 0513a3949..06d0081ab 100644 --- a/slsDetectorServers/eigerDetectorServer/Beb.c +++ b/slsDetectorServers/eigerDetectorServer/Beb.c @@ -165,16 +165,16 @@ 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,12 +298,9 @@ int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay) { return OK; } -/* do not work at the moment */ -int Beb_SetMasterViaSoftware() { - +int Beb_SetTop(int val) { if (!Beb_activated) return 0; - // mapping new memory u_int32_t *csp0base = 0; u_int32_t value = 0, ret = 1; @@ -311,16 +308,23 @@ int Beb_SetMasterViaSoftware() { // open file pointer int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); if (fd < 0) { - LOG(logERROR, ("Set Master FAIL\n")); + LOG(logERROR, ("Set Top FAIL, could not open fd\n")); } else { - value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET); - value |= MASTER_BIT; - value |= OVERWRITE_HARDWARE_BIT; - int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET, value); + value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST); + value |= BEB_CONFIG_OW_TOP_MSK; + if (val) { + value |= BEB_CONFIG_TOP_MSK; + } else { + value &= ~BEB_CONFIG_TOP_MSK; + } + int newval = Beb_Write32(csp0base, BEB_CONFIG_WR_OFST, value); if (newval != value) { - LOG(logERROR, ("Could not set Master via Software\n")); + LOG(logERROR, ("Could not overwrite Top to %d\n", val)); } else { ret = 0; + LOG(logINFOBLUE, + ("Overwriting BEB Hardware: %s\n", (val ? "Top" : "Bottom"))); + Beb_top = val; } } @@ -331,12 +335,9 @@ int Beb_SetMasterViaSoftware() { return ret; } -/* do not work at the moment */ -int Beb_SetSlaveViaSoftware() { - +int Beb_SetMaster(int val) { if (!Beb_activated) return 0; - // mapping new memory u_int32_t *csp0base = 0; u_int32_t value = 0, ret = 1; @@ -344,16 +345,22 @@ int Beb_SetSlaveViaSoftware() { // open file pointer int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_SYS_BASEADDR); if (fd < 0) { - LOG(logERROR, ("Set Slave FAIL\n")); + LOG(logERROR, ("Set Master FAIL, could not open fd\n")); } else { - value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET); - value &= ~MASTER_BIT; - value |= OVERWRITE_HARDWARE_BIT; - int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET, value); + value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST); + value |= BEB_CONFIG_OW_MASTER_MSK; + if (val) { + value |= BEB_CONFIG_MASTER_MSK; + } else { + value &= ~BEB_CONFIG_MASTER_MSK; + } + int newval = Beb_Write32(csp0base, BEB_CONFIG_WR_OFST, value); if (newval != value) { - LOG(logERROR, ("Could not set Slave via Software\n")); + LOG(logERROR, ("Could not overwrite Master to %d\n", val)); } else { ret = 0; + LOG(logINFOBLUE, + ("Overwriting BEB Hardware: %s\n", (val ? "Master" : "Slave"))); } } @@ -372,38 +379,29 @@ int Beb_Activate(int enable) { // 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")); } else { if (enable > -1) { - value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET); - LOG(logINFO, ("Deactivate register value before:%d\n", value)); + value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST); + LOG(logINFO, ("Activate register value before:%d\n", value)); if (enable) - value &= ~DEACTIVATE_BIT; + value |= BEB_CONFIG_ACTIVATE_MSK; else - value |= DEACTIVATE_BIT; + value &= ~BEB_CONFIG_ACTIVATE_MSK; - int newval = Beb_Write32(csp0base, MASTERCONFIG_OFFSET, value); + int newval = Beb_Write32(csp0base, BEB_CONFIG_WR_OFST, value); if (newval != value) { - if (enable) { - LOG(logERROR, ("Could not activate via Software\n")); - } else { - LOG(logERROR, ("Could not deactivate via Software\n")); - } + LOG(logERROR, ("Could not %s\n", (enable ? "activate" : "deactivate")); } } - value = Beb_Read32(csp0base, MASTERCONFIG_OFFSET); - if (value & DEACTIVATE_BIT) - ret = 0; - else - ret = 1; + value = Beb_Read32(csp0base, BEB_CONFIG_WR_OFST); + ret = (value & BEB_CONFIG_ACTIVATE_MSK) ? 1 : 0; if (enable == -1) { if (ret) { - LOG(logINFOBLUE, - ("Detector is active. Register value:%d\n", value)); + LOG(logINFOBLUE, ("Detector is active\n")); } else { - LOG(logERROR, - ("Detector is deactivated! Register value:%d\n", value)); + LOG(logINFORED, ("Detector is deactivated!\n")); } } } @@ -656,35 +654,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; diff --git a/slsDetectorServers/eigerDetectorServer/Beb.h b/slsDetectorServers/eigerDetectorServer/Beb.h index 9c7187bf0..fb19012b5 100644 --- a/slsDetectorServers/eigerDetectorServer/Beb.h +++ b/slsDetectorServers/eigerDetectorServer/Beb.h @@ -36,8 +36,8 @@ 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_SetTop(int val); +int Beb_SetMaster(int val); int Beb_Activate(int enable); int Beb_GetActivate(); int Beb_Set32bitOverflow(int val); @@ -51,7 +51,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..56a694faf 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.c +++ b/slsDetectorServers/eigerDetectorServer/FebControl.c @@ -2459,29 +2459,87 @@ int Feb_Control_GetInterruptSubframe() { return value[0]; } +int Feb_Control_SetTop(int val, int left, int right) { + uint32_t offset = DAQ_REG_HRDWRE; + unsigned int addr[2] = {0, 0}; + if (left) { + addr[0] = Module_GetTopLeftAddress(&modules[0]); + } + if (right) { + addr[1] = Module_GetTopRightAddress(&modules[0]); + } + int i = 0; + for (i = 0; i < 2; ++i) { + if (addr[i] == 0) { + continue; + } + uint32_t regVal = 0; + if (!Feb_Interface_ReadRegister(addr[i], offset, ®Val)) { + LOG(logERROR, ("Could not read %s DAQ_REG_HRDWRE reg\n", + (i == 0 ? "left" : "right"))); + return 0; + } + regVal |= DAQ_REG_HRDWRE_OW_TOP_MSK; + if (val) { + regVal |= DAQ_REG_HRDWRE_TOP_MSK; + } else { + regVal &= ~DAQ_REG_HRDWRE_TOP_MSK; + } + + if (!Feb_Interface_WriteRegister(addr[i], offset, regVal, 0, 0)) { + LOG(logERROR, + ("Could not overwrite top %d to %s DAQ_REG_HRDWRE reg\n", val, + (i == 0 ? "left" : "right"))); + return 0; + } + } + if (left && right) { + LOG(logINFOBLUE, + ("Overwriting FEB Hardware: %s\n", (val ? "Top" : "Bottom"))); + } + return 1; +} + +int Feb_Control_SetMaster(int val) { + uint32_t offset = DAQ_REG_HRDWRE; + unsigned int addr[2] = {0, 0}; + addr[0] = Module_GetTopLeftAddress(&modules[0]); + addr[1] = Module_GetTopRightAddress(&modules[0]); + int i = 0; + for (i = 0; i < 2; ++i) { + uint32_t regVal = 0; + if (!Feb_Interface_ReadRegister(addr[i], offset, ®Val)) { + LOG(logERROR, ("Could not read %s DAQ_REG_HRDWRE reg\n", + (i == 0 ? "left" : "right"))); + return 0; + } + regVal |= DAQ_REG_HRDWRE_OW_MASTER_MSK; + if (val) { + regVal |= DAQ_REG_HRDWRE_MASTER_MSK; + } else { + regVal &= ~DAQ_REG_HRDWRE_MASTER_MSK; + } + + if (!Feb_Interface_WriteRegister(addr[i], offset, regVal, 0, 0)) { + LOG(logERROR, + ("Could not write master %d to %s DAQ_REG_HRDWRE reg\n", val, + (i == 0 ? "left" : "right"))); + return 0; + } + } + Feb_control_master = 1; + LOG(logINFOBLUE, + ("Overwriting FEB Hardware: %s\n", (val ? "Master" : "Slave"))); + 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; + return Feb_Control_SetTop(val, 0, 1); } int Feb_Control_SetReadNLines(int value) { diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.h b/slsDetectorServers/eigerDetectorServer/FebControl.h index 4c7bc608a..a09c4cec0 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.h +++ b/slsDetectorServers/eigerDetectorServer/FebControl.h @@ -174,6 +174,9 @@ int64_t Feb_Control_GetSubMeasuredPeriod(); int Feb_Control_SoftwareTrigger(); int Feb_Control_SetInterruptSubframe(int val); int Feb_Control_GetInterruptSubframe(); + +int Feb_Control_SetTop(int val, int left, int right); +int Feb_Control_SetMaster(int val); 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..b6c668429 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_OW_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/config.txt b/slsDetectorServers/eigerDetectorServer/config.txt new file mode 100644 index 000000000..0730144cf --- /dev/null +++ b/slsDetectorServers/eigerDetectorServer/config.txt @@ -0,0 +1,2 @@ +top 0 +master 0 \ No newline at end of file diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 704dac051..71fae959e 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -314,6 +314,8 @@ void initControlServer() { getModuleConfiguration(); setupDetector(); } + eiger_virtual_activate = 0; + LOG(logINFORED, ("Deactivated!\n")); initCheckDone = 1; return; #else @@ -341,14 +343,9 @@ void initControlServer() { LOG(logDEBUG1, ("Control server: BEB Initialization done\n")); 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); - } + // client first connect (from shm) will activate + Beb_Activate(0); + Feb_Control_activate(0); } initCheckDone = 1; #endif @@ -361,6 +358,8 @@ void initStopServer() { if (!isControlServer) { ComVirtual_setStop(virtual_stop); } + eiger_virtual_activate = 0; + LOG(logINFORED, ("Deactivated!\n")); return; #else getModuleConfiguration(); @@ -375,15 +374,9 @@ void initStopServer() { 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); - } + // client first connect (from shm) will activate + Beb_Activate(0); + Feb_Control_activate(0); #endif } @@ -405,21 +398,7 @@ void getModuleConfiguration() { #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); - 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"); @@ -429,7 +408,140 @@ void getModuleConfiguration() { if (isControlServer) { LOG(logINFOBLUE, ("Detector ID: %u\n\n", detid)); } + + Beb_GetModuleConfiguration(&master, &top, &normal); #endif + + if (readConfigFile() == FAIL) { + return; + } + if (isControlServer) { + LOG(logINFOBLUE, + ("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"), + (master ? "MASTER" : "SLAVE"), (normal ? "NORMAL" : "SPECIAL"))); + } +} + +int readConfigFile() { + + if (initError == FAIL) { + return initError; + } + + FILE *fd = fopen(CONFIG_FILE, "r"); + if (fd == NULL) { + return OK; + } + 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 + if (Beb_SetTop(top) == FAIL) { + 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(top, 1, 1) == FAIL) { + sprintf( + initErrorMessage, + "Could not overwrite top to %d in Feb from on-board server " + "config file. Line:[%s].\n", + top, line); + break; + } +#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 + if (Beb_SetMaster(master) == FAIL) { + 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(master) == FAIL) { + sprintf(initErrorMessage, + "Could not overwrite master to %d in Feb from on-board " + "server " + "config file. Line:[%s].\n", + master, line); + break; + } +#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")); + } + return initError; } /* set up detector */ @@ -1685,6 +1797,11 @@ int activate(int enable) { #ifdef VIRTUAL if (enable >= 0) eiger_virtual_activate = enable; + if (eiger_virtual_activate == 0) { + LOG(logINFORED, ("Deactivated!\n")); + } else { + LOG(logINFOGREEN, ("Activated!\n")); + } return eiger_virtual_activate; #else int ret = Beb_Activate(enable); @@ -1939,8 +2056,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 +2066,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 +2206,7 @@ int startReadOut() { // for(i=0;i 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 100a86fa0..d8c38ada5 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 e47b0728f..8955492c8 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -346,19 +346,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; } @@ -2457,16 +2457,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 77f672099..5b8fdec84 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();