diff --git a/RELEASE.txt b/RELEASE.txt index ee767353c..c5b81f899 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -38,6 +38,9 @@ This document describes the differences between 5.2.0 and 5.1.0 releases. 1. Bad Channels moved to a new register + + Jungfrau- many Features + 2. Resolved Issues @@ -59,7 +62,7 @@ This document describes the differences between 5.2.0 and 5.1.0 releases. detector server to reset core until firmware release. - +getAutoCompDisable->getAutoComparatorDisable 3. Firmware Requirements ======================== diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 819522a56..b47699d11 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -2013,14 +2013,39 @@ class Detector(CppDetectorApi): Note ----- - By default, the on-chip gain switching is active during the entire exposure. This mode disables the on-chip gain switching comparator automatically after 93.75% of exposure time (only for longer than 100us).\n + By default, the on-chip gain switching is active during the entire exposure. This mode disables the on-chip gain switching comparator automatically after 93.75% of exposure time (only for longer than 100us). The % is only for chipv1.0, the duration can be set for chipv1.1.\n Default is 0 or this mode disabled (comparator enabled throughout). 1 enables mode. 0 disables mode. """ - return self.getAutoCompDisable() + return self.getAutoComparatorDisable() @auto_comp_disable.setter def auto_comp_disable(self, value): - ut.set_using_dict(self.setAutoCompDisable, value) + ut.set_using_dict(self.setAutoComparatorDisable, value) + + @property + @element + def comp_disable_time(self): + """[Jungfrau] Time before end of exposure when comparator is disabled. + + Note + ----- + It is only possible for chipv1.1. + :getter: always returns in seconds. To get in datetime.delta, use getComparatorDisableTime + + Example + ----------- + >>> d.comp_disable_time = 1.05 + >>> d.comp_disable_time = datetime.timedelta(minutes = 3, seconds = 1.23) + >>> d.comp_disable_time + 181.23 + >>> d.getComparatorDisableTime() + [datetime.timedelta(seconds=181, microseconds=230000)] + """ + return ut.reduce_time(self.getComparatorDisableTime()) + + @comp_disable_time.setter + def comp_disable_time(self, value): + ut.set_time_using_dict(self.setComparatorDisableTime, value) @property diff --git a/python/src/detector.cpp b/python/src/detector.cpp index 4b3200ce0..6980fc55f 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -970,13 +970,21 @@ void init_det(py::module &m) { (void (Detector::*)(sls::Positions)) & Detector::resetTemperatureEvent, py::arg() = Positions{}) - .def("getAutoCompDisable", + .def("getAutoComparatorDisable", (Result(Detector::*)(sls::Positions) const) & - Detector::getAutoCompDisable, + Detector::getAutoComparatorDisable, py::arg() = Positions{}) - .def("setAutoCompDisable", + .def("setAutoComparatorDisable", (void (Detector::*)(bool, sls::Positions)) & - Detector::setAutoCompDisable, + Detector::setAutoComparatorDisable, + py::arg(), py::arg() = Positions{}) + .def("getComparatorDisableTime", + (Result(Detector::*)(sls::Positions) const) & + Detector::getComparatorDisableTime, + py::arg() = Positions{}) + .def("setComparatorDisableTime", + (void (Detector::*)(sls::ns, sls::Positions)) & + Detector::setComparatorDisableTime, py::arg(), py::arg() = Positions{}) .def("getNumberOfAdditionalStorageCells", (Result(Detector::*)(sls::Positions) const) & diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 6c92644f8..d03e8a9f5 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -1662,6 +1662,32 @@ int autoCompDisable(int on) { EXT_DAQ_CTRL_CMP_LGC_ENBL_OFST); } +int setComparatorDisableTime(int64_t val) { + if (getChipVersion() != 11) { + return FAIL; + } + if (val < 0) { + LOG(logERROR, + ("Invalid comp disable time: %lld ns\n", (long long int)val)); + return FAIL; + } + LOG(logINFO, ("Setting comp disable time %lld ns\n", (long long int)val)); + val *= (1E-3 * CLK_RUN); + bus_w(COMP_DSBLE_TIME_REG, val); + + // validate for tolerance + int64_t retval = getComparatorDisableTime(); + val /= (1E-3 * CLK_RUN); + if (val != retval) { + return FAIL; + } + return OK; +} + +int64_t getComparatorDisableTime() { + return bus_r(COMP_DSBLE_TIME_REG) / (1E-3 * CLK_RUN); +} + void configureASICTimer() { LOG(logINFO, ("Configuring ASIC Timer\n")); bus_w(ASIC_CTRL_REG, (bus_r(ASIC_CTRL_REG) & ~ASIC_CTRL_PRCHRG_TMR_MSK) | diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index b971e56ad..de06ff9ff 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -450,6 +450,8 @@ int powerChip(int on); int isChipConfigured(); void configureChip(); int autoCompDisable(int on); +int setComparatorDisableTime(int64_t val); +int64_t getComparatorDisableTime(); void configureASICTimer(); int setClockDivider(enum CLKINDEX ind, int val); int getClockDivider(enum CLKINDEX ind); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index d1f0aa6e6..594de8402 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -258,4 +258,6 @@ int get_chip_version(int); int get_default_dac(int); int set_default_dac(int); int get_gain_mode(int); -int set_gain_mode(int); \ No newline at end of file +int set_gain_mode(int); +int get_comp_disable_time(int); +int set_comp_disable_time(int); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 35668d4c9..eb3887bfb 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -384,6 +384,8 @@ void function_table() { flist[F_SET_DEFAULT_DAC] = &set_default_dac; flist[F_GET_GAIN_MODE] = &get_gain_mode; flist[F_SET_GAIN_MODE] = &set_gain_mode; + flist[F_GET_COMP_DISABLE_TIME] = &get_comp_disable_time; + flist[F_SET_COMP_DISABLE_TIME] = &set_comp_disable_time; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -8613,3 +8615,61 @@ int set_gain_mode(int file_des) { #endif return Server_SendResult(file_des, INT32, NULL, 0); } + +int get_comp_disable_time(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int64_t retval = -1; +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // get only + if (getChipVersion() != 11) { + ret = FAIL; + strcpy(mess, + "Cannot get comparator disable time. Only valid for chipv1.1\n"); + LOG(logERROR, (mess)); + } else { + retval = getComparatorDisableTime(); + LOG(logDEBUG1, + ("retval comp disable time %lld ns\n", (long long int)retval)); + } +#endif + return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); +} + +int set_comp_disable_time(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int64_t arg = -1; + if (receiveData(file_des, &arg, sizeof(arg), INT64) < 0) + return printSocketReadError(); + LOG(logDEBUG1, ("Setting comp disable time %lld ns\n", (long long int)arg)); + +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + if (getChipVersion() != 11) { + ret = FAIL; + strcpy(mess, "Cannot get comparator disable time. Only valid for " + "chipv1.1\n"); + LOG(logERROR, (mess)); + } else { + ret = setComparatorDisableTime(arg); + int64_t retval = getComparatorDisableTime(); + LOG(logDEBUG1, ("retval get comp disable time %lld ns\n", + (long long int)retval)); + if (ret == FAIL) { + sprintf(mess, + "Could not set comp disable time. Set %lld ns, read " + "%lld ns.\n", + (long long int)arg, (long long int)retval); + LOG(logERROR, (mess)); + } + } + } +#endif + return Server_SendResult(file_des, INT64, NULL, 0); +} \ No newline at end of file diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index dc4f6c6ba..988f8b174 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -1127,18 +1127,26 @@ class Detector { void resetTemperatureEvent(Positions pos = {}); /** [Jungfrau] */ - Result getAutoCompDisable(Positions pos = {}) const; + Result getAutoComparatorDisable(Positions pos = {}) const; /** [Jungfrau] Advanced * //TODO naming - * By default, the on-chip gain switching is active during the entire - * exposure. This mode disables the on-chip gain switching comparator - * automatically after 93.75% of exposure time (only for longer than - * 100us).\n - * Default is false or this mode disabled(comparator enabled throughout). - * true enables mode. 0 disables mode. + * By default, the on-chip gain switching is active during the + * entire exposure. This mode disables the on-chip gain switching comparator + * automatically after 93.75% of exposure time (only for longer than 100us). + * The % is for chipv1.0. One can set the duration for chipv1.1 using + * setComparatorDisableTime\n Default is false or this mode + * disabled(comparator enabled throughout). true enables mode. 0 disables + * mode. */ - void setAutoCompDisable(bool value, Positions pos = {}); + void setAutoComparatorDisable(bool value, Positions pos = {}); + + /** [Jungfrau] */ + Result getComparatorDisableTime(Positions pos = {}) const; + + /** [Jungfrau] Time before end of exposure when comparator is disabled. It + * is only possible for chipv1.1.*/ + void setComparatorDisableTime(ns t, Positions pos = {}); /** [Jungfrau] Advanced TODO naming */ Result getNumberOfAdditionalStorageCells(Positions pos = {}) const; diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 9ada9ea09..106897719 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -926,6 +926,7 @@ class CmdProxy { {"temp_control", &CmdProxy::temp_control}, {"temp_event", &CmdProxy::TemperatureEvent}, {"auto_comp_disable", &CmdProxy::auto_comp_disable}, + {"comp_disable_time", &CmdProxy::comp_disable_time}, {"storagecells", &CmdProxy::storagecells}, {"storagecell_start", &CmdProxy::storagecell_start}, {"storagecell_delay", &CmdProxy::storagecell_delay}, @@ -1837,14 +1838,22 @@ class CmdProxy { "cleared."); INTEGER_COMMAND_VEC_ID( - auto_comp_disable, getAutoCompDisable, setAutoCompDisable, + auto_comp_disable, getAutoComparatorDisable, setAutoComparatorDisable, StringTo, "[0, 1]\n\t[Jungfrau] Auto comparator disable mode. By default, the " "on-chip gain switching is active during the entire exposure.This mode " "disables the on - chip gain switching comparator automatically after " - "93.75% of exposure time (only for longer than 100us). \n\tDefault is " - "0 or this mode disabled(comparator enabled throughout). 1 enables " - "mode. 0 disables mode. "); + "93.75% (only for chipv1.0) of exposure time (only for longer than " + "100us). It is possible to set the duration for chipv1.1 using " + "comp_disable_time command.\n\tDefault is 0 or this mode " + "disabled(comparator enabled throughout). 1 enables mode. 0 disables " + "mode. "); + + TIME_COMMAND(comp_disable_time, getComparatorDisableTime, + setComparatorDisableTime, + "[duration] [(optional unit) ns|us|ms|s]\n\t[Jungfrau] Time " + "before end of exposure when comparator is disabled. It is " + "only possible for chipv1.1."); INTEGER_COMMAND_SET_NOID_GET_ID( storagecells, getNumberOfAdditionalStorageCells, diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index ea889fff2..ddd7253f2 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1451,14 +1451,22 @@ void Detector::resetTemperatureEvent(Positions pos) { pimpl->Parallel(&Module::resetTemperatureEvent, pos); } -Result Detector::getAutoCompDisable(Positions pos) const { +Result Detector::getAutoComparatorDisable(Positions pos) const { return pimpl->Parallel(&Module::getAutoComparatorDisableMode, pos); } -void Detector::setAutoCompDisable(bool value, Positions pos) { +void Detector::setAutoComparatorDisable(bool value, Positions pos) { pimpl->Parallel(&Module::setAutoComparatorDisableMode, pos, value); } +Result Detector::getComparatorDisableTime(Positions pos) const { + return pimpl->Parallel(&Module::getComparatorDisableTime, pos); +} + +void Detector::setComparatorDisableTime(ns t, Positions pos) { + pimpl->Parallel(&Module::setComparatorDisableTime, pos, t.count()); +} + Result Detector::getNumberOfAdditionalStorageCells(Positions pos) const { return pimpl->Parallel(&Module::getNumberOfAdditionalStorageCells, pos); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index ac9ecc212..cac7590ea 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1577,6 +1577,14 @@ void Module::setAutoComparatorDisableMode(bool val) { sendToDetector(F_AUTO_COMP_DISABLE, static_cast(val)); } +int64_t Module::getComparatorDisableTime() const { + return sendToDetector(F_GET_COMP_DISABLE_TIME); +} + +void Module::setComparatorDisableTime(int64_t value) { + sendToDetector(F_SET_COMP_DISABLE_TIME, value, nullptr); +} + int Module::getNumberOfAdditionalStorageCells() const { return sendToDetector(F_GET_NUM_ADDITIONAL_STORAGE_CELLS); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index d7f75fef3..6855d91b5 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -363,6 +363,8 @@ class Module : public virtual slsDetectorDefs { void resetTemperatureEvent(); bool getAutoComparatorDisableMode() const; void setAutoComparatorDisableMode(bool val); + int64_t getComparatorDisableTime() const; + void setComparatorDisableTime(int64_t value); int getNumberOfAdditionalStorageCells() const; void setNumberOfAdditionalStorageCells(int value); int getStorageCellStart() const; diff --git a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp index f894e4105..521b0faee 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp @@ -258,7 +258,7 @@ TEST_CASE("auto_comp_disable", "[.cmd]") { CmdProxy proxy(&det); auto det_type = det.getDetectorType().squash(); if (det_type == defs::JUNGFRAU) { - auto prev_val = det.getAutoCompDisable(); + auto prev_val = det.getAutoComparatorDisable(); { std::ostringstream oss; proxy.Call("auto_comp_disable", {"0"}, -1, PUT, oss); @@ -275,7 +275,7 @@ TEST_CASE("auto_comp_disable", "[.cmd]") { REQUIRE(oss.str() == "auto_comp_disable 1\n"); } for (int i = 0; i != det.size(); ++i) { - det.setAutoCompDisable(prev_val[i], {i}); + det.setAutoComparatorDisable(prev_val[i], {i}); } } else { REQUIRE_THROWS(proxy.Call("auto_comp_disable", {}, -1, GET)); @@ -283,6 +283,36 @@ TEST_CASE("auto_comp_disable", "[.cmd]") { } } +TEST_CASE("comp_disable_time", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU) { + auto prev_val = det.getComparatorDisableTime(); + { + std::ostringstream oss; + proxy.Call("comp_disable_time", {"125ns"}, -1, PUT, oss); + REQUIRE(oss.str() == "comp_disable_time 125ns\n"); + } + { + std::ostringstream oss; + proxy.Call("comp_disable_time", {}, -1, GET, oss); + REQUIRE(oss.str() == "comp_disable_time 125ns\n"); + } + { + std::ostringstream oss; + proxy.Call("comp_disable_time", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "comp_disable_time 0\n"); + } + for (int i = 0; i != det.size(); ++i) { + det.setComparatorDisableTime(prev_val[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("comp_disable_time", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("comp_disable_time", {"0"}, -1, PUT)); + } +} + TEST_CASE("storagecells", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index 0a955cec0..952843f21 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -235,6 +235,8 @@ enum detFuncs { F_SET_DEFAULT_DAC, F_GET_GAIN_MODE, F_SET_GAIN_MODE, + F_GET_COMP_DISABLE_TIME, + F_SET_COMP_DISABLE_TIME, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this @@ -576,6 +578,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_DEFAULT_DAC: return "F_SET_DEFAULT_DAC"; case F_GET_GAIN_MODE: return "F_GET_GAIN_MODE"; case F_SET_GAIN_MODE: return "F_SET_GAIN_MODE"; + case F_GET_COMP_DISABLE_TIME: return "F_GET_COMP_DISABLE_TIME"; + case F_SET_COMP_DISABLE_TIME: return "F_SET_COMP_DISABLE_TIME"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";