diff --git a/.clang-tidy b/.clang-tidy index 6e94d11e4..be4381b08 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -18,7 +18,8 @@ Checks: '*, -google-readability-todo, -google-readability-braces-around-statements, -modernize-use-trailing-return-type, - -readability-isolate-declaration' + -readability-isolate-declaration, + -llvmlibc-*' HeaderFilterRegex: \.h AnalyzeTemporaryDtors: false diff --git a/RELEASE.txt b/RELEASE.txt index ee767353c..508eba076 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,10 @@ This document describes the differences between 5.2.0 and 5.1.0 releases. detector server to reset core until firmware release. - +getAutoCompDisable->getAutoComparatorDisable +filter->filterResistor +setBottom->setFlipRows +currentsource expects currentsrcparameters structure instread of bool 3. Firmware Requirements ======================== diff --git a/python/scripts/test_virtual.py b/python/scripts/test_virtual.py index e58d1c958..2024194ac 100644 --- a/python/scripts/test_virtual.py +++ b/python/scripts/test_virtual.py @@ -101,15 +101,11 @@ def test_module_size(virtual_jf_detectors): def test_settings(virtual_jf_detectors): d = ExperimentalDetector() - assert d.settings == detectorSettings.DYNAMICGAIN + assert d.settings == detectorSettings.GAIN0 gain_list = [ - detectorSettings.FIXGAIN1, - detectorSettings.FIXGAIN2, - detectorSettings.FORCESWITCHG1, - detectorSettings.FORCESWITCHG2, - detectorSettings.DYNAMICHG0, - detectorSettings.DYNAMICGAIN, + detectorSettings.GAIN0, + detectorSettings.HIGHGAIN0, ] # Set all viable gain for Jungfrau to make sure nothing is crashing @@ -117,15 +113,14 @@ def test_settings(virtual_jf_detectors): d.settings = gain assert d.settings == gain - d.setSettings(detectorSettings.FORCESWITCHG1, [1]) + d.setSettings(detectorSettings.GAIN0, [1]) assert d.settings == [ - detectorSettings.DYNAMICGAIN, - detectorSettings.FORCESWITCHG1, - detectorSettings.DYNAMICGAIN, + detectorSettings.GAIN0, + detectorSettings.HIGHGAIN0, ] - d.settings = detectorSettings.DYNAMICGAIN - assert d.settings == detectorSettings.DYNAMICGAIN + d.settings = detectorSettings.GAIN0 + assert d.settings == detectorSettings.GAIN0 def test_frames(virtual_jf_detectors): d = ExperimentalDetector() @@ -161,4 +156,34 @@ def test_period(virtual_jf_detectors): d.period = t assert d.period == 10e-6 - \ No newline at end of file +def test_gainmode(virtual_jf_detectors): + d = ExperimentalDetector() + assert d.gainMode == gainMode.NORMAL_GAIN_MODE + + gain_list = [ + gainMode.DYNAMIC, + gainMode.FORCE_SWITCH_G1, + gainMode.FORCE_SWITCH_G2, + gainMode.FIX_G1, + gainMode.FIX_G2, + gainMode.FIX_G0 + ] + + # Set all viable gain for Jungfrau to make sure nothing is crashing + for gain in gain_list: + d.gainMode = gain + assert d.gainMode == gain + + d.setGainMode(gainMode.FORCE_SWITCH_G1, [1]) + assert d.gainMode == [ + gainMode.DYNAMIC, + gainMode.FORCE_SWITCH_G1, + gainMode.FORCE_SWITCH_G2, + gainMode.FIX_G1, + gainMode.FIX_G2, + gainMode.FIX_G0 + ] + + d.gainMode = gainMode.FORCE_SWITCH_G1 + assert d.gainMode == gainMode.FORCE_SWITCH_G1 + diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 8826ea6f8..cf5f7f023 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -311,7 +311,7 @@ class Detector(CppDetectorApi): ----- [Eiger] Use threshold command to load settings - [Jungfrau] DYNAMICGAIN, DYNAMICHG0, FIXGAIN1, FIXGAIN2, FORCESWITCHG1, FORCESWITCHG2 \n + [Jungfrau] GAIN0, HIGHGAIN0 \n [Gotthard] DYNAMICGAIN, HIGHGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN \n [Gotthard2] DYNAMICGAIN, FIXGAIN1, FIXGAIN2 \n [Moench] G1_HIGHGAIN, G1_LOWGAIN, G2_HIGHCAP_HIGHGAIN, G2_HIGHCAP_LOWGAIN, G2_LOWCAP_HIGHGAIN, G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN \n @@ -370,7 +370,7 @@ class Detector(CppDetectorApi): Note ---- [Moench] Default is disabled. \n - [Jungfrau] Default is disabled. Get will return power status. Can be off if temperature event occured (temperature over temp_threshold with temp_control enabled. \n + [Jungfrau] Default is disabled. Get will return power status. Can be off if temperature event occured (temperature over temp_threshold with temp_control enabled. Will configure chip (only chip v1.1).\n [Mythen3][Gotthard2] Default is 1. If module not connected or wrong module, powerchip will fail. """ return self.getPowerChip() @@ -1992,6 +1992,20 @@ class Detector(CppDetectorApi): Jungfrau specific """ + @property + @element + def chipversion(self): + """ + [Jungfrau] Chip version of module. Can be 1.0 or 1.1. + + Example + ------- + >>> d.chipversion + '1.0' + """ + return self.getChipVersion() + + @property @element def auto_comp_disable(self): @@ -1999,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 @@ -2026,7 +2065,7 @@ class Detector(CppDetectorApi): [Jungfrau] Number of additional storage cells. Note ---- - For advanced users only. \n + Only for chip v1.0. For advanced users only. \n Options: 0 - 15. Default is 0. The #images = #frames x #triggers x (#storagecells + 1) """ @@ -2045,7 +2084,7 @@ class Detector(CppDetectorApi): Note ---- For advanced users only. - Options 0-15. Default is 15. \n + Options 0-max. max is 15 (default) for chipv1.0 and 3 (default) for chipv1.1. \n """ return self.getStorageCellStart() @@ -2059,7 +2098,7 @@ class Detector(CppDetectorApi): [Jungfrau] Additional time delay between 2 consecutive exposures in burst mode, accepts either a value in seconds or datetime.timedelta Note ----- - For advanced users only \n + Only applicable for chipv1.0. For advanced users only \n Value: 0-1638375 ns (resolution of 25ns) \n :getter: always returns in seconds. To get in datetime.delta, use getStorageCellDelay @@ -2151,6 +2190,26 @@ class Detector(CppDetectorApi): def selinterface(self, i): ut.set_using_dict(self.selectUDPInterface, i) + @property + def gainmodelist(self): + """List of gainmode implemented for this detector.""" + return self.getGainModeList() + + @property + def gainmode(self): + """ + [Jungfrau] Detector gain mode. Enum: gainMode + Note + ----- + [Jungfrau] DYNAMIC, FORCE_SWITCH_G1, FORCE_SWITCH_G2, FIX_G1, FIX_G2, FIX_G0 \n + CAUTION: Do not use FIX_G0 without caution, you can damage the detector!!! + """ + return element_if_equal(self.getGainMode()) + + @gainmode.setter + def gainmode(self, value): + self.setGainMode(value) + """ ---------------------------<<>>--------------------------- """ @@ -2179,18 +2238,37 @@ class Detector(CppDetectorApi): @property @element - def filter(self): - """[Gotthard2] Set filter resistor. + def filterresistor(self): + """ + [Gotthard2][Jungfrau] Set filter resistor. Increasing values for increasing " + "resistance. Note ---- - Default is 0. Options: 0-3. + Advanced user command. + [Gotthard2] Default is 0. Options: 0-3. + [Jungfrau] Default is 1. Options: 0-1. """ - return self.getFilter() + return self.getFilterResistor() - @filter.setter - def filter(self, value): - ut.set_using_dict(self.setFilter, value) + @filterresistor.setter + def filterresistor(self, value): + ut.set_using_dict(self.setFilterResistor, value) + @property + @element + def filtercell(self): + """ + [Jungfrau] Set filter capacitor. + Note + ---- + [Jungfrau] Options: 0-12. Default: 0. Advanced user command. + """ + return self.getFilterCell() + + @filtercell.setter + def filtercell(self, value): + ut.set_using_dict(self.setFilterCell, value) + @property def maxclkphaseshift(self): """ diff --git a/python/slsdet/enums.py b/python/slsdet/enums.py index 48c2d51b3..fdbfe7d2f 100644 --- a/python/slsdet/enums.py +++ b/python/slsdet/enums.py @@ -1,17 +1,20 @@ +""" +Automatically improt all enums from slsDetectorDefs and give an +alias with their name in the enum module. All names from the enum +module is later imported into slsdet + +Example: detectorType = _slsdet.slsDetectorDefs.detectorType +Usage can later be: + +from slsdet import detectorType +if dt === detectorType.EIGER: + #do something + +""" + import _slsdet -runStatus = _slsdet.slsDetectorDefs.runStatus -speedLevel = _slsdet.slsDetectorDefs.speedLevel -detectorType = _slsdet.slsDetectorDefs.detectorType -frameDiscardPolicy = _slsdet.slsDetectorDefs.frameDiscardPolicy -fileFormat = _slsdet.slsDetectorDefs.fileFormat -dimension = _slsdet.slsDetectorDefs.dimension -externalSignalFlag = _slsdet.slsDetectorDefs.externalSignalFlag -timingMode = _slsdet.slsDetectorDefs.timingMode -dacIndex = _slsdet.slsDetectorDefs.dacIndex -detectorSettings = _slsdet.slsDetectorDefs.detectorSettings -clockIndex = _slsdet.slsDetectorDefs.clockIndex -readoutMode = _slsdet.slsDetectorDefs.readoutMode -burstMode = _slsdet.slsDetectorDefs.burstMode -timingSourceType = _slsdet.slsDetectorDefs.timingSourceType -M3_GainCaps = _slsdet.slsDetectorDefs.M3_GainCaps \ No newline at end of file +for name, cls in _slsdet.slsDetectorDefs.__dict__.items(): + if isinstance(cls, type): + exec(f'{name} = {cls.__module__}.{cls.__qualname__}') + diff --git a/python/src/detector.cpp b/python/src/detector.cpp index f6b7f71bc..5ee258e2c 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -354,9 +354,28 @@ void init_det(py::module &m) { py::arg(), py::arg() = Positions{}) .def("getDacList", (std::vector(Detector::*)() const) & Detector::getDacList) - .def("setDefaultDacs", - (void (Detector::*)(sls::Positions)) & Detector::setDefaultDacs, - py::arg() = Positions{}) + .def("getDefaultDac", + (Result(Detector::*)(defs::dacIndex, sls::Positions)) & + Detector::getDefaultDac, + py::arg(), py::arg() = Positions{}) + .def("setDefaultDac", + (void (Detector::*)(defs::dacIndex, int, sls::Positions)) & + Detector::setDefaultDac, + py::arg(), py::arg(), py::arg() = Positions{}) + .def("getDefaultDac", + (Result(Detector::*)(defs::dacIndex, defs::detectorSettings, + sls::Positions)) & + Detector::getDefaultDac, + py::arg(), py::arg(), py::arg() = Positions{}) + .def("setDefaultDac", + (void (Detector::*)(defs::dacIndex, int, defs::detectorSettings, + sls::Positions)) & + Detector::setDefaultDac, + py::arg(), py::arg(), py::arg(), py::arg() = Positions{}) + .def("resetToDefaultDacs", + (void (Detector::*)(const bool, sls::Positions)) & + Detector::resetToDefaultDacs, + py::arg(), py::arg() = Positions{}) .def("getDAC", (Result(Detector::*)(defs::dacIndex, bool, sls::Positions) const) & @@ -829,12 +848,12 @@ void init_det(py::module &m) { (void (Detector::*)(bool, sls::Positions)) & Detector::setOverFlowMode, py::arg(), py::arg() = Positions{}) - .def("getBottom", + .def("getFlipRows", (Result(Detector::*)(sls::Positions) const) & - Detector::getBottom, + Detector::getFlipRows, py::arg() = Positions{}) - .def("setBottom", - (void (Detector::*)(bool, sls::Positions)) & Detector::setBottom, + .def("setFlipRows", + (void (Detector::*)(bool, sls::Positions)) & Detector::setFlipRows, py::arg(), py::arg() = Positions{}) .def("getRateCorrection", (Result(Detector::*)(sls::Positions) const) & @@ -923,6 +942,10 @@ void init_det(py::module &m) { sls::Positions)) & Detector::setDataStream, py::arg(), py::arg(), py::arg() = Positions{}) + .def("getChipVersion", + (Result(Detector::*)(sls::Positions) const) & + Detector::getChipVersion, + py::arg() = Positions{}) .def("getThresholdTemperature", (Result(Detector::*)(sls::Positions) const) & Detector::getThresholdTemperature, @@ -947,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) & @@ -979,6 +1010,17 @@ void init_det(py::module &m) { (void (Detector::*)(sls::ns, sls::Positions)) & Detector::setStorageCellDelay, py::arg(), py::arg() = Positions{}) + .def("getGainModeList", + (std::vector(Detector::*)() const) & + Detector::getGainModeList) + .def("getGainMode", + (Result(Detector::*)(sls::Positions) const) & + Detector::getGainMode, + py::arg() = Positions{}) + .def("setGainMode", + (void (Detector::*)(defs::gainMode, sls::Positions)) & + Detector::setGainMode, + py::arg(), py::arg() = Positions{}) .def("getROI", (Result(Detector::*)(sls::Positions) const) & Detector::getROI, @@ -1054,12 +1096,21 @@ void init_det(py::module &m) { .def("setCDSGain", (void (Detector::*)(bool, sls::Positions)) & Detector::setCDSGain, py::arg(), py::arg() = Positions{}) - .def("getFilter", + .def("getFilterResistor", (Result(Detector::*)(sls::Positions) const) & - Detector::getFilter, + Detector::getFilterResistor, py::arg() = Positions{}) - .def("setFilter", - (void (Detector::*)(int, sls::Positions)) & Detector::setFilter, + .def("setFilterResistor", + (void (Detector::*)(int, sls::Positions)) & + Detector::setFilterResistor, + py::arg(), py::arg() = Positions{}) + .def("getFilterCell", + (Result(Detector::*)(sls::Positions) const) & + Detector::getFilterCell, + py::arg() = Positions{}) + .def("setFilterCell", + (void (Detector::*)(int, sls::Positions)) & + Detector::setFilterCell, py::arg(), py::arg() = Positions{}) .def("getCurrentSource", (Result(Detector::*)(sls::Positions) const) & diff --git a/python/src/enums.cpp b/python/src/enums.cpp index f6f2e8a38..2aada8f5c 100644 --- a/python/src/enums.cpp +++ b/python/src/enums.cpp @@ -210,13 +210,9 @@ void init_enums(py::module &m) { .value("LOWGAIN", slsDetectorDefs::detectorSettings::LOWGAIN) .value("MEDIUMGAIN", slsDetectorDefs::detectorSettings::MEDIUMGAIN) .value("VERYHIGHGAIN", slsDetectorDefs::detectorSettings::VERYHIGHGAIN) - .value("DYNAMICHG0", slsDetectorDefs::detectorSettings::DYNAMICHG0) + .value("HIGHGAIN0", slsDetectorDefs::detectorSettings::HIGHGAIN0) .value("FIXGAIN1", slsDetectorDefs::detectorSettings::FIXGAIN1) .value("FIXGAIN2", slsDetectorDefs::detectorSettings::FIXGAIN2) - .value("FORCESWITCHG1", - slsDetectorDefs::detectorSettings::FORCESWITCHG1) - .value("FORCESWITCHG2", - slsDetectorDefs::detectorSettings::FORCESWITCHG2) .value("VERYLOWGAIN", slsDetectorDefs::detectorSettings::VERYLOWGAIN) .value("G1_HIGHGAIN", slsDetectorDefs::detectorSettings::G1_HIGHGAIN) .value("G1_LOWGAIN", slsDetectorDefs::detectorSettings::G1_LOWGAIN) @@ -230,6 +226,7 @@ void init_enums(py::module &m) { slsDetectorDefs::detectorSettings::G2_LOWCAP_LOWGAIN) .value("G4_HIGHGAIN", slsDetectorDefs::detectorSettings::G4_HIGHGAIN) .value("G4_LOWGAIN", slsDetectorDefs::detectorSettings::G4_LOWGAIN) + .value("GAIN0", slsDetectorDefs::detectorSettings::GAIN0) .value("UNDEFINED", slsDetectorDefs::detectorSettings::UNDEFINED) .value("UNINITIALIZED", slsDetectorDefs::detectorSettings::UNINITIALIZED) @@ -309,4 +306,13 @@ void init_enums(py::module &m) { .value("DEFAULT_ALGORITHM", slsDetectorDefs::vetoAlgorithm::DEFAULT_ALGORITHM) .export_values(); + + py::enum_(Defs, "gainMode") + .value("DYNAMIC", slsDetectorDefs::gainMode::DYNAMIC) + .value("FORCE_SWITCH_G1", slsDetectorDefs::gainMode::FORCE_SWITCH_G1) + .value("FORCE_SWITCH_G2", slsDetectorDefs::gainMode::FORCE_SWITCH_G2) + .value("FIX_G1", slsDetectorDefs::gainMode::FIX_G1) + .value("FIX_G2", slsDetectorDefs::gainMode::FIX_G2) + .value("FIX_G0", slsDetectorDefs::gainMode::FIX_G0) + .export_values(); } diff --git a/slsDetectorGui/forms/form_tab_settings.ui b/slsDetectorGui/forms/form_tab_settings.ui index 2f20a5edb..32890e2d0 100755 --- a/slsDetectorGui/forms/form_tab_settings.ui +++ b/slsDetectorGui/forms/form_tab_settings.ui @@ -7,7 +7,7 @@ 0 0 775 - 345 + 380 @@ -32,7 +32,7 @@ Form - + false @@ -51,7 +51,7 @@ - + false @@ -70,7 +70,7 @@ - + false @@ -109,7 +109,7 @@ - + false @@ -146,7 +146,7 @@ - + false @@ -183,7 +183,7 @@ - + false @@ -205,7 +205,7 @@ - + Qt::Vertical @@ -221,7 +221,7 @@ - + true @@ -334,7 +334,7 @@ - + false @@ -356,7 +356,7 @@ - + false @@ -393,7 +393,7 @@ - + Qt::Horizontal @@ -409,7 +409,7 @@ - + false @@ -431,7 +431,7 @@ - + false @@ -514,7 +514,7 @@ - Dynamic HG0 + High Gain 0 @@ -527,16 +527,6 @@ Fix Gain 2 - - - Force Switch G1 - - - - - Force Switch G2 - - Very Low Gain @@ -582,6 +572,11 @@ G4_LG + + + Gain 0 + + Undefined @@ -594,6 +589,86 @@ + + + + false + + + + 110 + 0 + + + + + 110 + 16777215 + + + + Gain Mode: + + + + + + + false + + + + 0 + 0 + + + + + 140 + 25 + + + + + 140 + 16777215 + + + + <html><head/><body><p>Gain Mode of the detector</p><p> #gainmode#</p><p><br/></p><p>Fix G0 is to be used with utmost caution. Can damage the detector!</p></body></html> + + + + Dynamic Gain + + + + + Force Switch G1 + + + + + Force Switch G2 + + + + + Fix G1 + + + + + Fix G2 + + + + + Fix G0 + + + + diff --git a/slsDetectorGui/include/qTabSettings.h b/slsDetectorGui/include/qTabSettings.h index 52915747e..d4ec2f73a 100644 --- a/slsDetectorGui/include/qTabSettings.h +++ b/slsDetectorGui/include/qTabSettings.h @@ -10,9 +10,12 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { qTabSettings(QWidget *parent, sls::Detector *detector); ~qTabSettings(); void Refresh(); + public slots: + void SetExportMode(bool exportMode); private slots: void SetSettings(int index); + void SetGainMode(int index); void SetDynamicRange(int index); void SetThresholdEnergy(int index); void SetThresholdEnergies(); @@ -21,9 +24,12 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { private: void SetupWidgetWindow(); void SetupDetectorSettings(); + void SetupGainMode(); + void ShowFixG0(bool expertMode); void Initialization(); void GetSettings(); + void GetGainMode(); void GetDynamicRange(); void GetThresholdEnergy(); void GetThresholdEnergies(); @@ -40,11 +46,9 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, - DYNAMICHG0, + HIGHGAIN0, FIXGAIN1, FIXGAIN2, - FORCESWITCHG1, - FORCESWITCHG2, VERLOWGAIN, G1_HIGHGAIN, G1_LOWGAIN, @@ -54,9 +58,21 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN, + GAIN0, UNDEFINED, UNINITIALIZED, NUMSETTINGS }; + + enum { + DYNAMIC, + FORCE_SWITCH_G1, + FORCE_SWITCH_G2, + FIX_G1, + FIX_G2, + FIX_G0 + }; + bool isVisibleFixG0{false}; + enum { DYNAMICRANGE_32, DYNAMICRANGE_16, DYNAMICRANGE_8, DYNAMICRANGE_4 }; }; diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index 2ca2c1291..634def39e 100644 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -340,6 +340,7 @@ void qDetectorMain::EnableModes(QAction *action) { actionLoadTrimbits->setVisible(enable && (detType == slsDetectorDefs::EIGER || detType == slsDetectorDefs::MYTHEN3)); + tabSettings->SetExportMode(enable); LOG(logINFO) << "Expert Mode: " << qDefs::stringEnable(enable); } diff --git a/slsDetectorGui/src/qTabMeasurement.cpp b/slsDetectorGui/src/qTabMeasurement.cpp index f9510e0cd..19aa42bf7 100644 --- a/slsDetectorGui/src/qTabMeasurement.cpp +++ b/slsDetectorGui/src/qTabMeasurement.cpp @@ -213,23 +213,16 @@ void qTabMeasurement::SetupTimingMode() { index[i] = model->index(i, comboTimingMode->modelColumn(), comboTimingMode->rootModelIndex()); item[i] = model->itemFromIndex(index[i]); + item[i]->setEnabled(false); } - - item[(int)GATED]->setEnabled(false); - item[(int)BURST_TRIGGER]->setEnabled(false); - item[(int)TRIGGER_GATED]->setEnabled(false); - switch (det->getDetectorType().squash()) { - case slsDetectorDefs::EIGER: - item[(int)GATED]->setEnabled(true); - item[(int)BURST_TRIGGER]->setEnabled(true); - break; - case slsDetectorDefs::MYTHEN3: - item[(int)GATED]->setEnabled(true); - item[(int)TRIGGER_GATED]->setEnabled(true); - break; - default: - break; + try { + auto res = det->getTimingModeList(); + for (auto it : res) { + item[(int)it]->setEnabled(true); + } } + CATCH_DISPLAY(std::string("Could not setup timing mode"), + "qTabMeasurement::SetupTimingMode") } } diff --git a/slsDetectorGui/src/qTabSettings.cpp b/slsDetectorGui/src/qTabSettings.cpp index 84fd53de8..677b1864b 100644 --- a/slsDetectorGui/src/qTabSettings.cpp +++ b/slsDetectorGui/src/qTabSettings.cpp @@ -71,6 +71,9 @@ void qTabSettings::SetupWidgetWindow() { comboDynamicRange->setEnabled(true); lblThreshold->setEnabled(true); spinThreshold->setEnabled(true); + } else if (detType == slsDetectorDefs::JUNGFRAU) { + lblGainMode->setEnabled(true); + comboGainMode->setEnabled(true); } // default settings for the disabled @@ -83,82 +86,83 @@ void qTabSettings::SetupWidgetWindow() { spinThreshold2->setValue(-1); spinThreshold3->setValue(-1); } + + // default for gain mode + if (comboGainMode->isEnabled()) { + SetupGainMode(); + } + Initialization(); // default for the disabled GetDynamicRange(); Refresh(); } +void qTabSettings::SetExportMode(bool exportMode) { + if (comboGainMode->isVisible()) { + ShowFixG0(exportMode); + } +} + void qTabSettings::SetupDetectorSettings() { + comboSettings->setCurrentIndex(UNINITIALIZED); + + // enable only those available to detector QStandardItemModel *model = qobject_cast(comboSettings->model()); + const int numSettings = comboSettings->count(); if (model) { - QModelIndex index[NUMSETTINGS]; - QStandardItem *item[NUMSETTINGS]; - for (int i = 0; i < NUMSETTINGS; ++i) { + std::vector index(numSettings); + std::vector item(numSettings); + for (size_t i = 0; i < index.size(); ++i) { index[i] = model->index(i, comboSettings->modelColumn(), comboSettings->rootModelIndex()); item[i] = model->itemFromIndex(index[i]); item[i]->setEnabled(false); } - switch (det->getDetectorType().squash()) { - case slsDetectorDefs::EIGER: - item[(int)STANDARD]->setEnabled(true); - item[(int)HIGHGAIN]->setEnabled(true); - item[(int)LOWGAIN]->setEnabled(true); - item[(int)VERYHIGHGAIN]->setEnabled(true); - item[(int)VERLOWGAIN]->setEnabled(true); - break; - case slsDetectorDefs::GOTTHARD: - item[(int)HIGHGAIN]->setEnabled(true); - item[(int)DYNAMICGAIN]->setEnabled(true); - item[(int)LOWGAIN]->setEnabled(true); - item[(int)MEDIUMGAIN]->setEnabled(true); - item[(int)VERYHIGHGAIN]->setEnabled(true); - break; - case slsDetectorDefs::JUNGFRAU: - item[(int)DYNAMICGAIN]->setEnabled(true); - item[(int)DYNAMICHG0]->setEnabled(true); - item[(int)FIXGAIN1]->setEnabled(true); - item[(int)FIXGAIN2]->setEnabled(true); - item[(int)FORCESWITCHG1]->setEnabled(true); - item[(int)FORCESWITCHG2]->setEnabled(true); - break; - case slsDetectorDefs::GOTTHARD2: - item[(int)DYNAMICGAIN]->setEnabled(true); - item[(int)FIXGAIN1]->setEnabled(true); - item[(int)FIXGAIN2]->setEnabled(true); - break; - case slsDetectorDefs::MOENCH: - item[(int)G1_HIGHGAIN]->setEnabled(true); - item[(int)G1_LOWGAIN]->setEnabled(true); - item[(int)G2_HIGHCAP_HIGHGAIN]->setEnabled(true); - item[(int)G2_HIGHCAP_LOWGAIN]->setEnabled(true); - item[(int)G2_LOWCAP_HIGHGAIN]->setEnabled(true); - item[(int)G2_LOWCAP_LOWGAIN]->setEnabled(true); - item[(int)G4_HIGHGAIN]->setEnabled(true); - item[(int)G4_LOWGAIN]->setEnabled(true); - break; - case slsDetectorDefs::MYTHEN3: - item[(int)STANDARD]->setEnabled(true); - item[(int)FAST]->setEnabled(true); - item[(int)HIGHGAIN]->setEnabled(true); - break; - default: - LOG(logDEBUG) << "Unknown detector type. Exiting GUI."; - qDefs::Message(qDefs::CRITICAL, - "Unknown detector type. Exiting GUI.", - "qTabSettings::SetupDetectorSettings"); - exit(-1); + try { + auto res = det->getSettingsList(); + for (auto it : res) { + item[(int)it]->setEnabled(true); + } } + CATCH_DISPLAY(std::string("Could not setup settings"), + "qTabSettings::SetupDetectorSettings") } } +void qTabSettings::SetupGainMode() { + comboGainMode->setCurrentIndex(DYNAMIC); + ShowFixG0(false); +} + +void qTabSettings::ShowFixG0(bool expertMode) { + LOG(logINFO) << (expertMode ? "Showing" : "Hiding") << " FIX_G0"; + + // enable.disable Fix G0 + QStandardItemModel *model = + qobject_cast(comboGainMode->model()); + const int numSettings = comboGainMode->count(); + if (model) { + std::vector index(numSettings); + std::vector item(numSettings); + index[FIX_G0] = model->index(FIX_G0, comboGainMode->modelColumn(), + comboGainMode->rootModelIndex()); + item[FIX_G0] = model->itemFromIndex(index[FIX_G0]); + item[FIX_G0]->setEnabled(expertMode); + } + isVisibleFixG0 = expertMode; +} + void qTabSettings::Initialization() { // Settings if (comboSettings->isEnabled()) connect(comboSettings, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSettings(int))); + // Gain mode + if (comboGainMode->isEnabled()) + connect(comboGainMode, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetGainMode(int))); // Dynamic Range if (comboDynamicRange->isEnabled()) @@ -202,7 +206,7 @@ void qTabSettings::GetSettings() { comboSettings->setCurrentIndex(UNINITIALIZED); break; default: - if ((int)retval < -1 || (int)retval >= NUMSETTINGS) { + if ((int)retval < -1 || (int)retval >= comboSettings->count()) { throw sls::RuntimeError(std::string("Unknown settings: ") + std::to_string(retval)); } @@ -230,6 +234,60 @@ void qTabSettings::SetSettings(int index) { } } +void qTabSettings::GetGainMode() { + LOG(logDEBUG) << "Getting gain mode"; + disconnect(comboGainMode, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetGainMode(int))); + try { + auto retval = det->getGainMode().tsquash( + "Inconsistent gain mode for all detectors."); + if ((int)retval < 0 || (int)retval >= comboGainMode->count()) { + throw sls::RuntimeError(std::string("Unknown gain mode: ") + + std::to_string(retval)); + } + // warning when using fix_g0 and not in export mode + if ((int)retval == FIX_G0 && !isVisibleFixG0) { + std::string message = + "You are not in Expert Mode and Gain Mode is in FIX_G0. " + "
Could damage the detector when used without " + "caution! "; + qDefs::Message(qDefs::WARNING, message, + "qTabSettings::GetGainMode"); + LOG(logWARNING) << message; + } + comboGainMode->setCurrentIndex((int)retval); + } + CATCH_DISPLAY("Could not get gain mode.", "qTabSettings::GetGainMode") + connect(comboGainMode, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetGainMode(int))); +} + +void qTabSettings::SetGainMode(int index) { + // warning for fix_G0 even in export mode + if (index == FIX_G0) { + if (qDefs::Message( + qDefs::QUESTION, + "You are in Export mode, " + "
but setting Gain Mode to FIX_G0 could " + "damage the detector!
Proceed and set " + "gainmode to FIX_G0 anyway?", + "qTabSettings::SetGainMode") == slsDetectorDefs::FAIL) { + GetGainMode(); + return; + } + } + + LOG(logINFO) << "Setting Gain Mode to " + << comboGainMode->currentText().toAscii().data(); + auto val = static_cast(index); + try { + + det->setGainMode(val); + } + CATCH_HANDLE("Could not set gain mode.", "qTabSettings::SetGainMode", this, + &qTabSettings::GetGainMode) +} + void qTabSettings::GetDynamicRange() { LOG(logDEBUG) << "Getting dynamic range"; disconnect(comboDynamicRange, SIGNAL(activated(int)), this, @@ -402,6 +460,10 @@ void qTabSettings::Refresh() { GetSettings(); } + if (comboGainMode->isEnabled()) { + GetGainMode(); + } + if (comboDynamicRange->isEnabled()) { GetDynamicRange(); } diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index 514e55395..301d57710 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index 18c12fa54..28eec26af 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 73b337ada..284ac07a8 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -93,6 +93,7 @@ int eiger_virtual_interrupt_subframe = 0; int eiger_virtual_left_datastream = 1; int eiger_virtual_right_datastream = 1; #endif +int defaultDacValues[NDAC] = DEFAULT_DAC_VALS; int isInitCheckDone() { return initCheckDone; } @@ -434,8 +435,9 @@ int readConfigFile() { master = -1; top = -1; - char fname[128]; - if (getAbsPath(fname, 128, CONFIG_FILE) == FAIL) { + const int fileNameSize = 128; + char fname[fileNameSize]; + if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) { return FAIL; } @@ -684,7 +686,7 @@ void allocateDetectorStructureMemory() { void setupDetector() { allocateDetectorStructureMemory(); - setDefaultDacs(); + resetToDefaultDacs(0); #ifdef VIRTUAL sharedMemory_setStatus(IDLE); #endif @@ -746,21 +748,53 @@ void setupDetector() { LOG(logDEBUG1, ("Setup detector done\n\n")); } -int setDefaultDacs() { +int resetToDefaultDacs(int hardReset) { + // reset defaults to hardcoded defaults + if (hardReset) { + const int vals[] = DEFAULT_DAC_VALS; + for (int i = 0; i < NDAC; ++i) { + defaultDacValues[i] = vals[i]; + } + } + // reset dacs to defaults int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); - const int defaultvals[NDAC] = DEFAULT_DAC_VALS; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultvals[i], 0); - if ((detectorModules)->dacs[i] != defaultvals[i]) { + setDAC((enum DACINDEX)i, defaultDacValues[i], 0); + if ((detectorModules)->dacs[i] != defaultDacValues[i]) { ret = FAIL; LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultvals[i], (detectorModules)->dacs[i])); + defaultDacValues[i], (detectorModules)->dacs[i])); } } return ret; } +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + + char *dac_names[] = {DAC_NAMES}; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} + /* advanced read/write reg */ int writeRegister(uint32_t offset, uint32_t data) { #ifdef VIRTUAL diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index 86f1b7fb6..3094bc128 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 971875f29..2ece73d9d 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -49,6 +49,7 @@ int highvoltage = 0; int dacValues[NDAC] = {}; int onChipdacValues[ONCHIP_NDAC][NCHIP] = {}; int defaultDacValues[NDAC] = {}; +int hardCodedDefaultDacValues[NDAC] = {}; int defaultOnChipdacValues[ONCHIP_NDAC][NCHIP] = {}; int injectedChannelsOffset = 0; int injectedChannelsIncrement = 0; @@ -62,7 +63,7 @@ int64_t numTriggersReg = 1; int64_t delayReg = 0; int64_t numBurstsReg = 1; int64_t burstPeriodReg = 0; -int filter = 0; +int filterResistor = 0; int cdsGain = 0; int detPos[2] = {}; @@ -387,12 +388,13 @@ void setupDetector() { delayReg = 0; numBurstsReg = 1; burstPeriodReg = 0; - filter = 0; + filterResistor = 0; cdsGain = 0; memset(clkPhase, 0, sizeof(clkPhase)); memset(dacValues, 0, sizeof(dacValues)); for (int i = 0; i < NDAC; ++i) { defaultDacValues[i] = -1; + hardCodedDefaultDacValues[i] = -1; } for (int i = 0; i < ONCHIP_NDAC; ++i) { for (int j = 0; j < NCHIP; ++j) { @@ -465,7 +467,7 @@ void setupDetector() { return; } setBurstMode(DEFAULT_BURST_MODE); - setFilter(DEFAULT_FILTER); + setFilterResistor(DEFAULT_FILTER_RESISTOR); setCDSGain(DEFAILT_CDS_GAIN); setSettings(DEFAULT_SETTINGS); @@ -481,7 +483,14 @@ void setupDetector() { setCurrentSource(DEFAULT_CURRENT_SOURCE); } -int setDefaultDacs() { +int resetToDefaultDacs(int hardReset) { + // reset defaults to hardcoded defaults + if (hardReset) { + for (int i = 0; i < NDAC; ++i) { + defaultDacValues[i] = hardCodedDefaultDacValues[i]; + } + } + // reset dacs to defaults int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); for (int i = 0; i < NDAC; ++i) { @@ -515,6 +524,31 @@ int setDefaultDacs() { return ret; } +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + + char *dac_names[] = {DAC_NAMES}; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} + int readConfigFile() { if (initError == FAIL) { @@ -530,8 +564,9 @@ int readConfigFile() { usleep(INITIAL_STARTUP_WAIT); - char fname[128]; - if (getAbsPath(fname, 128, CONFIG_FILE) == FAIL) { + const int fileNameSize = 128; + char fname[fileNameSize]; + if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) { return FAIL; } @@ -805,6 +840,7 @@ int readConfigFile() { // set default dac variables defaultDacValues[idac] = value; + hardCodedDefaultDacValues[idac] = value; // set dac setDAC(idac, value, 0); @@ -2422,7 +2458,7 @@ int setBurstMode(enum burstMode burst) { } int configureASICGlobalSettings() { - int value = ((filter << ASIC_FILTER_OFST) & ASIC_FILTER_MSK) | + int value = ((filterResistor << ASIC_FILTER_OFST) & ASIC_FILTER_MSK) | ((cdsGain << ASIC_CDS_GAIN_OFST) & ASIC_CDS_GAIN_MSK); switch (burstMode) { case BURST_INTERNAL: @@ -2437,9 +2473,9 @@ int configureASICGlobalSettings() { value |= (ASIC_CONT_MODE_MSK | ASIC_EXT_TIMING_MSK); break; } - LOG(logINFO, ("\tSending Global Chip settings:0x%x (filter:%d, " + LOG(logINFO, ("\tSending Global Chip settings:0x%x (filterResistor:%d, " "cdsgain:%d)\n", - value, filter, cdsGain)); + value, filterResistor, cdsGain)); const int padding = 6; // due to address (4) to make it byte aligned const int lenTotalBits = padding + ASIC_GLOBAL_SETT_MAX_BITS + @@ -2515,17 +2551,17 @@ int setCDSGain(int enable) { int getCDSGain() { return cdsGain; } -int setFilter(int value) { - if (value < 0 || value > ASIC_FILTER_MAX_VALUE) { - LOG(logERROR, ("Invalid filter value %d\n", value)); +int setFilterResistor(int value) { + if (value < 0 || value > ASIC_FILTER_MAX_RES_VALUE) { + LOG(logERROR, ("Invalid filter resistor value %d\n", value)); return FAIL; } - filter = value; - LOG(logINFO, ("Setting Filter to %d\n", filter)); + filterResistor = value; + LOG(logINFO, ("Setting Filter Resistor to %d\n", filterResistor)); return configureASICGlobalSettings(); } -int getFilter() { return filter; } +int getFilterResistor() { return filterResistor; } void setCurrentSource(int value) { uint32_t addr = ASIC_CONFIG_REG; diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/gotthard2DetectorServer/slsDetectorServer_defs.h index 91293d7e3..46124e855 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorServer_defs.h @@ -35,7 +35,7 @@ /** Default Parameters */ #define DEFAULT_BURST_MODE (BURST_INTERNAL) -#define DEFAULT_FILTER (0) +#define DEFAULT_FILTER_RESISTOR (0) #define DEFAILT_CDS_GAIN (0) #define DEFAULT_NUM_FRAMES (1) #define DEFAULT_NUM_CYCLES (1) @@ -149,7 +149,7 @@ enum PLLINDEX { READOUT_PLL, SYSTEM_PLL }; #define ASIC_CONT_MODE_MSK (0x1 << ASIC_CONT_MODE_OFST) #define ASIC_FILTER_OFST (3) #define ASIC_FILTER_MSK (0x3 << ASIC_FILTER_OFST) -#define ASIC_FILTER_MAX_VALUE (3) +#define ASIC_FILTER_MAX_RES_VALUE (3) #define ASIC_CDS_GAIN_OFST (5) #define ASIC_CDS_GAIN_MSK (0x1 << ASIC_CDS_GAIN_OFST) diff --git a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer index 5bc77a6cd..fe0608984 100755 Binary files a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer and b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer differ diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index db55c29e1..1f7e5104d 100644 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -45,6 +45,7 @@ int detPos[2] = {}; int detectorFirstServer = 1; int dacValues[NDAC] = {}; +int defaultDacValues[NDAC] = DEFAULT_DAC_VALS; enum detectorSettings thisSettings = UNINITIALIZED; enum externalSignalFlag signalMode = 0; @@ -405,7 +406,7 @@ void setupDetector() { DAC_MAX_MV); LTC2620_Disable(); LTC2620_Configure(); - setDefaultDacs(); + resetToDefaultDacs(0); // temp bus_w(TEMP_SPI_IN_REG, TEMP_SPI_IN_IDLE_MSK); @@ -433,21 +434,53 @@ void setupDetector() { setDelayAfterTrigger(DEFAULT_DELAY); } -int setDefaultDacs() { +int resetToDefaultDacs(int hardReset) { + // reset defaults to hardcoded defaults + if (hardReset) { + const int vals[] = DEFAULT_DAC_VALS; + for (int i = 0; i < NDAC; ++i) { + defaultDacValues[i] = vals[i]; + } + } + // reset dacs to defaults int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); - const int defaultvals[NDAC] = DEFAULT_DAC_VALS; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultvals[i], 0); - if (dacValues[i] != defaultvals[i]) { + setDAC((enum DACINDEX)i, defaultDacValues[i], 0); + if (dacValues[i] != defaultDacValues[i]) { ret = FAIL; LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultvals[i], dacValues[i])); + defaultDacValues[i], dacValues[i])); } } return ret; } +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + + char *dac_names[] = {DAC_NAMES}; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} + uint32_t writeRegister16And32(uint32_t offset, uint32_t data) { if (((offset << MEM_MAP_SHIFT) == CONTROL_REG) || ((offset << MEM_MAP_SHIFT) == FIFO_DATA_REG)) { @@ -588,8 +621,9 @@ void setGbitReadout() { } int readConfigFile() { - char fname[128]; - if (getAbsPath(fname, 128, CONFIG_FILE) == FAIL) { + const int fileNameSize = 128; + char fname[fileNameSize]; + if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) { return FAIL; } diff --git a/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt b/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt index ded49a47c..2d1a6fd12 100644 --- a/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt +++ b/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt @@ -36,4 +36,6 @@ set_target_properties(jungfrauDetectorServer_virtual PROPERTIES install(TARGETS jungfrauDetectorServer_virtual EXPORT "${TARGETS_EXPORT_NAME}" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} -) \ No newline at end of file +) + +configure_file(config_jungfrau.txt ${CMAKE_BINARY_DIR}/bin/config_jungfrau.txt COPYONLY) diff --git a/slsDetectorServers/jungfrauDetectorServer/Makefile b/slsDetectorServers/jungfrauDetectorServer/Makefile index 1a225159c..551b9137c 100755 --- a/slsDetectorServers/jungfrauDetectorServer/Makefile +++ b/slsDetectorServers/jungfrauDetectorServer/Makefile @@ -32,6 +32,7 @@ $(PROGS): $(OBJS) mkdir -p $(DESTDIR) $(CC) -o $@ $^ $(CFLAGS) $(LDLIBS) mv $(PROGS) $(DESTDIR) + cp config_jungfrau.txt $(DESTDIR) rm *.gdb rm $(main_src)*.o diff --git a/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h b/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h index 15764d237..c6c0eae69 100644 --- a/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h +++ b/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h @@ -1,498 +1,475 @@ #pragma once +// clang-format off /* Definitions for FPGA*/ #define MEM_MAP_SHIFT 1 /* FPGA Version register */ -#define FPGA_VERSION_REG (0x00 << MEM_MAP_SHIFT) +#define FPGA_VERSION_REG (0x00 << MEM_MAP_SHIFT) -#define FPGA_COMPILATION_DATE_OFST (0) -#define FPGA_COMPILATION_DATE_MSK (0x00FFFFFF << FPGA_COMPILATION_DATE_OFST) -#define DETECTOR_TYPE_OFST (24) -#define DETECTOR_TYPE_MSK (0x000000FF << DETECTOR_TYPE_OFST) +#define FPGA_COMPILATION_DATE_OFST (0) +#define FPGA_COMPILATION_DATE_MSK (0x00FFFFFF << FPGA_COMPILATION_DATE_OFST) +#define DETECTOR_TYPE_OFST (24) +#define DETECTOR_TYPE_MSK (0x000000FF << DETECTOR_TYPE_OFST) /* Fix pattern register */ -#define FIX_PATT_REG (0x01 << MEM_MAP_SHIFT) +#define FIX_PATT_REG (0x01 << MEM_MAP_SHIFT) -#define FIX_PATT_VAL (0xACDC2014) +#define FIX_PATT_VAL (0xACDC2014) /* Status register */ -#define STATUS_REG (0x02 << MEM_MAP_SHIFT) +#define STATUS_REG (0x02 << MEM_MAP_SHIFT) -#define RUN_BUSY_OFST (0) -#define RUN_BUSY_MSK (0x00000001 << RUN_BUSY_OFST) -#define WAITING_FOR_TRIGGER_OFST (3) -#define WAITING_FOR_TRIGGER_MSK (0x00000001 << WAITING_FOR_TRIGGER_OFST) -#define DELAYBEFORE_OFST (4) // Not used in software -#define DELAYBEFORE_MSK (0x00000001 << DELAYBEFORE_OFST) // Not used in software -#define DELAYAFTER_OFST (5) // Not used in software -#define DELAYAFTER_MSK (0x00000001 << DELAYAFTER_OFST) // Not used in software -#define STOPPED_OFST (15) -#define STOPPED_MSK (0x00000001 << STOPPED_OFST) -#define RUNMACHINE_BUSY_OFST (17) -#define RUNMACHINE_BUSY_MSK (0x00000001 << RUNMACHINE_BUSY_OFST) +#define RUN_BUSY_OFST (0) +#define RUN_BUSY_MSK (0x00000001 << RUN_BUSY_OFST) +#define WAITING_FOR_TRIGGER_OFST (3) +#define WAITING_FOR_TRIGGER_MSK (0x00000001 << WAITING_FOR_TRIGGER_OFST) +#define DELAYBEFORE_OFST (4) // Not used in software +#define DELAYBEFORE_MSK (0x00000001 << DELAYBEFORE_OFST) // Not used in software +#define DELAYAFTER_OFST (5) // Not used in software +#define DELAYAFTER_MSK (0x00000001 << DELAYAFTER_OFST) // Not used in software +#define STOPPED_OFST (15) +#define STOPPED_MSK (0x00000001 << STOPPED_OFST) +#define RUNMACHINE_BUSY_OFST (17) +#define RUNMACHINE_BUSY_MSK (0x00000001 << RUNMACHINE_BUSY_OFST) /* Look at me register */ -#define LOOK_AT_ME_REG \ - (0x03 << MEM_MAP_SHIFT) // Not used in firmware or software +#define LOOK_AT_ME_REG (0x03 << MEM_MAP_SHIFT) // Not used in firmware or software /* System Status register */ -#define SYSTEM_STATUS_REG (0x04 << MEM_MAP_SHIFT) // Not used in software +#define SYSTEM_STATUS_REG (0x04 << MEM_MAP_SHIFT) // Not used in software -#define DDR3_CAL_DONE_OFST (0) // Not used in software -#define DDR3_CAL_DONE_MSK \ - (0x00000001 << DDR3_CAL_DONE_OFST) // Not used in software -#define DDR3_CAL_FAIL_OFST (1) // Not used in software -#define DDR3_CAL_FAIL_MSK \ - (0x00000001 << DDR3_CAL_FAIL_OFST) // Not used in software -#define DDR3_INIT_DONE_OFST (2) // Not used in software -#define DDR3_INIT_DONE_MSK \ - (0x00000001 << DDR3_INIT_DONE_OFST) // Not used in software -#define RECONFIG_PLL_LCK_OFST (3) // Not used in software -#define RECONFIG_PLL_LCK_MSK \ - (0x00000001 << RECONFIG_PLL_LCK_OFST) // Not used in software -#define PLL_A_LCK_OFST (4) // Not used in software -#define PLL_A_LCK_MSK (0x00000001 << PLL_A_LCK_OFST) // Not used in software -#define DD3_PLL_LCK_OFST (5) // Not used in software -#define DD3_PLL_LCK_MSK (0x00000001 << DD3_PLL_LCK_OFST) // Not used in software +#define DDR3_CAL_DONE_OFST (0) // Not used in software +#define DDR3_CAL_DONE_MSK (0x00000001 << DDR3_CAL_DONE_OFST) // Not used in software +#define DDR3_CAL_FAIL_OFST (1) // Not used in software +#define DDR3_CAL_FAIL_MSK (0x00000001 << DDR3_CAL_FAIL_OFST) // Not used in software +#define DDR3_INIT_DONE_OFST (2) // Not used in software +#define DDR3_INIT_DONE_MSK (0x00000001 << DDR3_INIT_DONE_OFST) // Not used in software +#define RECONFIG_PLL_LCK_OFST (3) // Not used in software +#define RECONFIG_PLL_LCK_MSK (0x00000001 << RECONFIG_PLL_LCK_OFST) // Not used in software +#define PLL_A_LCK_OFST (4) // Not used in software +#define PLL_A_LCK_MSK (0x00000001 << PLL_A_LCK_OFST) // Not used in software +#define DD3_PLL_LCK_OFST (5) // Not used in software +#define DD3_PLL_LCK_MSK (0x00000001 << DD3_PLL_LCK_OFST) // Not used in software /* Module Control Board Serial Number Register */ -#define MOD_SERIAL_NUM_REG (0x0A << MEM_MAP_SHIFT) +#define MOD_SERIAL_NUM_REG (0x0A << MEM_MAP_SHIFT) -#define HARDWARE_SERIAL_NUM_OFST (0) -#define HARDWARE_SERIAL_NUM_MSK (0x000000FF << HARDWARE_SERIAL_NUM_OFST) -#define HARDWARE_VERSION_NUM_OFST (16) -#define HARDWARE_VERSION_NUM_MSK (0x0000003F << HARDWARE_VERSION_NUM_OFST) -#define HARDWARE_VERSION_2_VAL \ - ((0x2 << HARDWARE_VERSION_NUM_OFST) & HARDWARE_VERSION_NUM_MSK) +#define HARDWARE_SERIAL_NUM_OFST (0) +#define HARDWARE_SERIAL_NUM_MSK (0x000000FF << HARDWARE_SERIAL_NUM_OFST) +#define HARDWARE_VERSION_NUM_OFST (16) +#define HARDWARE_VERSION_NUM_MSK (0x0000003F << HARDWARE_VERSION_NUM_OFST) +#define HARDWARE_VERSION_2_VAL ((0x2 << HARDWARE_VERSION_NUM_OFST) & HARDWARE_VERSION_NUM_MSK) /* API Version Register */ -#define API_VERSION_REG (0x0F << MEM_MAP_SHIFT) +#define API_VERSION_REG (0x0F << MEM_MAP_SHIFT) -#define API_VERSION_OFST (0) -#define API_VERSION_MSK (0x00FFFFFF << API_VERSION_OFST) -#define API_VERSION_DETECTOR_TYPE_OFST (24) // Not used in software -#define API_VERSION_DETECTOR_TYPE_MSK \ - (0x000000FF << API_VERSION_DETECTOR_TYPE_OFST) // Not used in software +#define API_VERSION_OFST (0) +#define API_VERSION_MSK (0x00FFFFFF << API_VERSION_OFST) +#define API_VERSION_DETECTOR_TYPE_OFST (24) // Not used in software +#define API_VERSION_DETECTOR_TYPE_MSK (0x000000FF << API_VERSION_DETECTOR_TYPE_OFST) // Not used in software /* Time from Start 64 bit register */ -#define TIME_FROM_START_LSB_REG (0x10 << MEM_MAP_SHIFT) -#define TIME_FROM_START_MSB_REG (0x11 << MEM_MAP_SHIFT) +#define TIME_FROM_START_LSB_REG (0x10 << MEM_MAP_SHIFT) +#define TIME_FROM_START_MSB_REG (0x11 << MEM_MAP_SHIFT) /* Get Delay 64 bit register */ -#define GET_DELAY_LSB_REG (0x12 << MEM_MAP_SHIFT) // different kind of delay -#define GET_DELAY_MSB_REG (0x13 << MEM_MAP_SHIFT) // different kind of delay +#define GET_DELAY_LSB_REG (0x12 << MEM_MAP_SHIFT) // different kind of delay +#define GET_DELAY_MSB_REG (0x13 << MEM_MAP_SHIFT) // different kind of delay /* Get Triggers 64 bit register */ -#define GET_CYCLES_LSB_REG (0x14 << MEM_MAP_SHIFT) -#define GET_CYCLES_MSB_REG (0x15 << MEM_MAP_SHIFT) +#define GET_CYCLES_LSB_REG (0x14 << MEM_MAP_SHIFT) +#define GET_CYCLES_MSB_REG (0x15 << MEM_MAP_SHIFT) /* Get Frames 64 bit register */ -#define GET_FRAMES_LSB_REG (0x16 << MEM_MAP_SHIFT) -#define GET_FRAMES_MSB_REG (0x17 << MEM_MAP_SHIFT) +#define GET_FRAMES_LSB_REG (0x16 << MEM_MAP_SHIFT) +#define GET_FRAMES_MSB_REG (0x17 << MEM_MAP_SHIFT) /* Get Period 64 bit register tT = T x 50 ns */ -#define GET_PERIOD_LSB_REG (0x18 << MEM_MAP_SHIFT) -#define GET_PERIOD_MSB_REG (0x19 << MEM_MAP_SHIFT) +#define GET_PERIOD_LSB_REG (0x18 << MEM_MAP_SHIFT) +#define GET_PERIOD_MSB_REG (0x19 << MEM_MAP_SHIFT) /** Get Temperature Carlos, incorrectl as get gates */ -#define GET_TEMPERATURE_TMP112_REG \ - (0x1c << MEM_MAP_SHIFT) // (after multiplying by 625) in 10ths of +#define GET_TEMPERATURE_TMP112_REG (0x1c << MEM_MAP_SHIFT) // (after multiplying by 625) in 10ths of // millidegrees of TMP112 -#define TEMPERATURE_VALUE_BIT (0) -#define TEMPERATURE_VALUE_MSK (0x000007FF << TEMPERATURE_VALUE_BIT) -#define TEMPERATURE_POLARITY_BIT (11) -#define TEMPERATURE_POLARITY_MSK (0x00000001 << TEMPERATURE_POLARITY_BIT) +#define TEMPERATURE_VALUE_BIT (0) +#define TEMPERATURE_VALUE_MSK (0x000007FF << TEMPERATURE_VALUE_BIT) +#define TEMPERATURE_POLARITY_BIT (11) +#define TEMPERATURE_POLARITY_MSK (0x00000001 << TEMPERATURE_POLARITY_BIT) + +/* Config Status Register for chip 1.1 */ +#define CONFIG_V11_STATUS_REG (0x1D << MEM_MAP_SHIFT) + +#define CONFIG_V11_STATUS_FLTR_CLL_OFST (0) +#define CONFIG_V11_STATUS_FLTR_CLL_MSK (0x00000FFF << CONFIG_V11_STATUS_FLTR_CLL_OFST) +#define CONFIG_V11_STATUS_STRG_CLL_OFST (12) +#define CONFIG_V11_STATUS_STRG_CLL_MSK (0x0000000F << CONFIG_V11_STATUS_STRG_CLL_OFST) +// CSM mode = high current (100%), low current (16%) +#define CONFIG_V11_STATUS_CRRNT_SRC_LOW_OFST (19) +#define CONFIG_V11_STATUS_CRRNT_SRC_LOW_MSK (0x00000001 << CONFIG_V11_STATUS_CRRNT_SRC_LOW_OFST) +#define CONFIG_V11_STATUS_FLTR_RSSTR_SMLR_OFST (21) +#define CONFIG_V11_STATUS_FLTR_RSSTR_SMLR_MSK (0x00000001 << CONFIG_V11_STATUS_FLTR_RSSTR_SMLR_OFST) +#define CONFIG_V11_STATUS_AUTO_MODE_OVRRD_OFST (23) +#define CONFIG_V11_STATUS_AUTO_MODE_OVRRD_MSK (0x00000001 << CONFIG_V11_STATUS_AUTO_MODE_OVRRD_OFST) /* Get Frames from Start 64 bit register (frames from last reset using * CONTROL_CRST) */ -#define FRAMES_FROM_START_LSB_REG (0x22 << MEM_MAP_SHIFT) -#define FRAMES_FROM_START_MSB_REG (0x23 << MEM_MAP_SHIFT) +#define FRAMES_FROM_START_LSB_REG (0x22 << MEM_MAP_SHIFT) +#define FRAMES_FROM_START_MSB_REG (0x23 << MEM_MAP_SHIFT) /* Get Starting Frame Number */ -#define GET_FRAME_NUMBER_LSB_REG (0x24 << MEM_MAP_SHIFT) -#define GET_FRAME_NUMBER_MSB_REG (0x25 << MEM_MAP_SHIFT) +#define GET_FRAME_NUMBER_LSB_REG (0x24 << MEM_MAP_SHIFT) +#define GET_FRAME_NUMBER_MSB_REG (0x25 << MEM_MAP_SHIFT) /* Measurement Time 64 bit register (timestamp at a frame start until reset)*/ -#define START_FRAME_TIME_LSB_REG (0x26 << MEM_MAP_SHIFT) -#define START_FRAME_TIME_MSB_REG (0x27 << MEM_MAP_SHIFT) +#define START_FRAME_TIME_LSB_REG (0x26 << MEM_MAP_SHIFT) +#define START_FRAME_TIME_MSB_REG (0x27 << MEM_MAP_SHIFT) /* SPI (Serial Peripheral Interface) Register */ -#define SPI_REG (0x40 << MEM_MAP_SHIFT) +#define SPI_REG (0x40 << MEM_MAP_SHIFT) -#define SPI_DAC_SRL_DGTL_OTPT_OFST (0) -#define SPI_DAC_SRL_DGTL_OTPT_MSK (0x00000001 << SPI_DAC_SRL_DGTL_OTPT_OFST) -#define SPI_DAC_SRL_CLK_OTPT_OFST (1) -#define SPI_DAC_SRL_CLK_OTPT_MSK (0x00000001 << SPI_DAC_SRL_CLK_OTPT_OFST) -#define SPI_DAC_SRL_CS_OTPT_OFST (2) -#define SPI_DAC_SRL_CS_OTPT_MSK (0x00000001 << SPI_DAC_SRL_CS_OTPT_OFST) -#define SPI_HV_SRL_DGTL_OTPT_OFST (8) -#define SPI_HV_SRL_DGTL_OTPT_MSK (0x00000001 << SPI_HV_SRL_DGTL_OTPT_OFST) -#define SPI_HV_SRL_CLK_OTPT_OFST (9) -#define SPI_HV_SRL_CLK_OTPT_MSK (0x00000001 << SPI_HV_SRL_CLK_OTPT_OFST) -#define SPI_HV_SRL_CS_OTPT_OFST (10) -#define SPI_HV_SRL_CS_OTPT_MSK (0x00000001 << SPI_HV_SRL_CS_OTPT_OFST) +#define SPI_DAC_SRL_DGTL_OTPT_OFST (0) +#define SPI_DAC_SRL_DGTL_OTPT_MSK (0x00000001 << SPI_DAC_SRL_DGTL_OTPT_OFST) +#define SPI_DAC_SRL_CLK_OTPT_OFST (1) +#define SPI_DAC_SRL_CLK_OTPT_MSK (0x00000001 << SPI_DAC_SRL_CLK_OTPT_OFST) +#define SPI_DAC_SRL_CS_OTPT_OFST (2) +#define SPI_DAC_SRL_CS_OTPT_MSK (0x00000001 << SPI_DAC_SRL_CS_OTPT_OFST) +#define SPI_HV_SRL_DGTL_OTPT_OFST (8) +#define SPI_HV_SRL_DGTL_OTPT_MSK (0x00000001 << SPI_HV_SRL_DGTL_OTPT_OFST) +#define SPI_HV_SRL_CLK_OTPT_OFST (9) +#define SPI_HV_SRL_CLK_OTPT_MSK (0x00000001 << SPI_HV_SRL_CLK_OTPT_OFST) +#define SPI_HV_SRL_CS_OTPT_OFST (10) +#define SPI_HV_SRL_CS_OTPT_MSK (0x00000001 << SPI_HV_SRL_CS_OTPT_OFST) /* ADC SPI (Serial Peripheral Interface) Register */ -#define ADC_SPI_REG (0x41 << MEM_MAP_SHIFT) +#define ADC_SPI_REG (0x41 << MEM_MAP_SHIFT) -#define ADC_SPI_SRL_CLK_OTPT_OFST (0) -#define ADC_SPI_SRL_CLK_OTPT_MSK (0x00000001 << ADC_SPI_SRL_CLK_OTPT_OFST) -#define ADC_SPI_SRL_DT_OTPT_OFST (1) -#define ADC_SPI_SRL_DT_OTPT_MSK (0x00000001 << ADC_SPI_SRL_DT_OTPT_OFST) -#define ADC_SPI_SRL_CS_OTPT_OFST (2) -#define ADC_SPI_SRL_CS_OTPT_MSK (0x0000000F << ADC_SPI_SRL_CS_OTPT_OFST) +#define ADC_SPI_SRL_CLK_OTPT_OFST (0) +#define ADC_SPI_SRL_CLK_OTPT_MSK (0x00000001 << ADC_SPI_SRL_CLK_OTPT_OFST) +#define ADC_SPI_SRL_DT_OTPT_OFST (1) +#define ADC_SPI_SRL_DT_OTPT_MSK (0x00000001 << ADC_SPI_SRL_DT_OTPT_OFST) +#define ADC_SPI_SRL_CS_OTPT_OFST (2) +#define ADC_SPI_SRL_CS_OTPT_MSK (0x0000000F << ADC_SPI_SRL_CS_OTPT_OFST) /* ADC offset Register */ -#define ADC_OFST_REG (0x42 << MEM_MAP_SHIFT) +#define ADC_OFST_REG (0x42 << MEM_MAP_SHIFT) /* ADC Port Invert Register */ -#define ADC_PORT_INVERT_REG (0x43 << MEM_MAP_SHIFT) +#define ADC_PORT_INVERT_REG (0x43 << MEM_MAP_SHIFT) -#define ADC_PORT_INVERT_ADC_0_OFST (0) -#define ADC_PORT_INVERT_ADC_0_MSK (0x000000FF << ADC_PORT_INVERT_ADC_0_OFST) -#define ADC_PORT_INVERT_ADC_1_OFST (8) -#define ADC_PORT_INVERT_ADC_1_MSK (0x000000FF << ADC_PORT_INVERT_ADC_1_OFST) -#define ADC_PORT_INVERT_ADC_2_OFST (16) -#define ADC_PORT_INVERT_ADC_2_MSK (0x000000FF << ADC_PORT_INVERT_ADC_2_OFST) -#define ADC_PORT_INVERT_ADC_3_OFST (24) -#define ADC_PORT_INVERT_ADC_3_MSK (0x000000FF << ADC_PORT_INVERT_ADC_3_OFST) +#define ADC_PORT_INVERT_ADC_0_OFST (0) +#define ADC_PORT_INVERT_ADC_0_MSK (0x000000FF << ADC_PORT_INVERT_ADC_0_OFST) +#define ADC_PORT_INVERT_ADC_1_OFST (8) +#define ADC_PORT_INVERT_ADC_1_MSK (0x000000FF << ADC_PORT_INVERT_ADC_1_OFST) +#define ADC_PORT_INVERT_ADC_2_OFST (16) +#define ADC_PORT_INVERT_ADC_2_MSK (0x000000FF << ADC_PORT_INVERT_ADC_2_OFST) +#define ADC_PORT_INVERT_ADC_3_OFST (24) +#define ADC_PORT_INVERT_ADC_3_MSK (0x000000FF << ADC_PORT_INVERT_ADC_3_OFST) /* Configuration Register */ -#define CONFIG_REG (0x4D << MEM_MAP_SHIFT) +#define CONFIG_REG (0x4D << MEM_MAP_SHIFT) // readout timer (from chip) to stabilize (esp in burst acquisition mode) tRDT = // (RDT + 1) * 25ns -#define CONFIG_RDT_TMR_OFST (0) -#define CONFIG_RDT_TMR_MSK (0x0000FFFF << CONFIG_RDT_TMR_OFST) -#define CONFIG_OPRTN_MDE_2_X_10GbE_OFST (16) -#define CONFIG_OPRTN_MDE_2_X_10GbE_MSK \ - (0x00000001 << CONFIG_OPRTN_MDE_2_X_10GbE_OFST) +#define CONFIG_RDT_TMR_OFST (0) +#define CONFIG_RDT_TMR_MSK (0x0000FFFF << CONFIG_RDT_TMR_OFST) // if 0, outer is the primary interface -#define CONFIG_INNR_PRIMRY_INTRFCE_OFST (17) -#define CONFIG_INNR_PRIMRY_INTRFCE_MSK \ - (0x00000001 << CONFIG_INNR_PRIMRY_INTRFCE_OFST) -#define CONFIG_READOUT_SPEED_OFST (20) -#define CONFIG_READOUT_SPEED_MSK (0x00000003 << CONFIG_READOUT_SPEED_OFST) -#define CONFIG_QUARTER_SPEED_10MHZ_VAL \ - ((0x0 << CONFIG_READOUT_SPEED_OFST) & CONFIG_READOUT_SPEED_MSK) -#define CONFIG_HALF_SPEED_20MHZ_VAL \ - ((0x1 << CONFIG_READOUT_SPEED_OFST) & CONFIG_READOUT_SPEED_MSK) -#define CONFIG_FULL_SPEED_40MHZ_VAL \ - ((0x2 << CONFIG_READOUT_SPEED_OFST) & CONFIG_READOUT_SPEED_MSK) -#define CONFIG_TDMA_ENABLE_OFST (24) -#define CONFIG_TDMA_ENABLE_MSK (0x00000001 << CONFIG_TDMA_ENABLE_OFST) -#define CONFIG_TDMA_TIMESLOT_OFST (25) // 1ms -#define CONFIG_TDMA_TIMESLOT_MSK (0x0000001F << CONFIG_TDMA_TIMESLOT_OFST) -#define CONFIG_ETHRNT_FLW_CNTRL_OFST (31) -#define CONFIG_ETHRNT_FLW_CNTRL_MSK (0x00000001 << CONFIG_ETHRNT_FLW_CNTRL_OFST) +// bottom via port 0 (outer) +#define CONFIG_OPRTN_MDE_2_X_10GbE_OFST (16) +#define CONFIG_OPRTN_MDE_2_X_10GbE_MSK (0x00000001 << CONFIG_OPRTN_MDE_2_X_10GbE_OFST) +#define CONFIG_INNR_PRIMRY_INTRFCE_OFST (17) +#define CONFIG_INNR_PRIMRY_INTRFCE_MSK (0x00000001 << CONFIG_INNR_PRIMRY_INTRFCE_OFST) +#define CONFIG_READOUT_SPEED_OFST (20) +#define CONFIG_READOUT_SPEED_MSK (0x00000003 << CONFIG_READOUT_SPEED_OFST) +#define CONFIG_QUARTER_SPEED_10MHZ_VAL ((0x0 << CONFIG_READOUT_SPEED_OFST) & CONFIG_READOUT_SPEED_MSK) +#define CONFIG_HALF_SPEED_20MHZ_VAL ((0x1 << CONFIG_READOUT_SPEED_OFST) & CONFIG_READOUT_SPEED_MSK) +#define CONFIG_FULL_SPEED_40MHZ_VAL ((0x2 << CONFIG_READOUT_SPEED_OFST) & CONFIG_READOUT_SPEED_MSK) +#define CONFIG_TDMA_ENABLE_OFST (24) +#define CONFIG_TDMA_ENABLE_MSK (0x00000001 << CONFIG_TDMA_ENABLE_OFST) +#define CONFIG_TDMA_TIMESLOT_OFST (25) // 1ms +#define CONFIG_TDMA_TIMESLOT_MSK (0x0000001F << CONFIG_TDMA_TIMESLOT_OFST) +#define CONFIG_BOTTOM_INVERT_STREAM_OFST (30) +#define CONFIG_BOTTOM_INVERT_STREAM_MSK (0x00000001 << CONFIG_BOTTOM_INVERT_STREAM_OFST) +#define CONFIG_ETHRNT_FLW_CNTRL_OFST (31) +#define CONFIG_ETHRNT_FLW_CNTRL_MSK (0x00000001 << CONFIG_ETHRNT_FLW_CNTRL_OFST) /* External Signal Register */ -#define EXT_SIGNAL_REG (0x4E << MEM_MAP_SHIFT) +#define EXT_SIGNAL_REG (0x4E << MEM_MAP_SHIFT) -#define EXT_SIGNAL_OFST (0) -#define EXT_SIGNAL_MSK (0x00000001 << EXT_SIGNAL_OFST) +#define EXT_SIGNAL_OFST (0) +#define EXT_SIGNAL_MSK (0x00000001 << EXT_SIGNAL_OFST) /* Control Register */ -#define CONTROL_REG (0x4F << MEM_MAP_SHIFT) +#define CONTROL_REG (0x4F << MEM_MAP_SHIFT) -#define CONTROL_START_ACQ_OFST (0) -#define CONTROL_START_ACQ_MSK (0x00000001 << CONTROL_START_ACQ_OFST) -#define CONTROL_STOP_ACQ_OFST (1) -#define CONTROL_STOP_ACQ_MSK (0x00000001 << CONTROL_STOP_ACQ_OFST) -#define CONTROL_CORE_RST_OFST (10) -#define CONTROL_CORE_RST_MSK (0x00000001 << CONTROL_CORE_RST_OFST) -#define CONTROL_PERIPHERAL_RST_OFST (11) // DDR3 HMem Ctrlr, GBE, Temp -#define CONTROL_PERIPHERAL_RST_MSK \ - (0x00000001 << CONTROL_PERIPHERAL_RST_OFST) // DDR3 HMem Ctrlr, GBE, Temp -#define CONTROL_DDR3_MEM_RST_OFST \ - (12) // only PHY, not DDR3 PLL ,Not used in software -#define CONTROL_DDR3_MEM_RST_MSK \ - (0x00000001 << CONTROL_DDR3_MEM_RST_OFST) // only PHY, not DDR3 PLL ,Not - // used in software -#define CONTROL_ACQ_FIFO_CLR_OFST (14) -#define CONTROL_ACQ_FIFO_CLR_MSK (0x00000001 << CONTROL_ACQ_FIFO_CLR_OFST) -#define CONTROL_STORAGE_CELL_NUM_OFST (16) -#define CONTROL_STORAGE_CELL_NUM_MSK \ - (0x0000000F << CONTROL_STORAGE_CELL_NUM_OFST) -#define CONTROL_RX_ADDTNL_ENDPTS_NUM_OFST (20) -#define CONTROL_RX_ADDTNL_ENDPTS_NUM_MSK \ - (0x0000003F << CONTROL_RX_ADDTNL_ENDPTS_NUM_OFST) -#define CONTROL_RX_ENDPTS_START_OFST (26) -#define CONTROL_RX_ENDPTS_START_MSK (0x0000003F << CONTROL_RX_ENDPTS_START_OFST) +#define CONTROL_START_ACQ_OFST (0) +#define CONTROL_START_ACQ_MSK (0x00000001 << CONTROL_START_ACQ_OFST) +#define CONTROL_STOP_ACQ_OFST (1) +#define CONTROL_STOP_ACQ_MSK (0x00000001 << CONTROL_STOP_ACQ_OFST) +#define CONTROL_CORE_RST_OFST (10) +#define CONTROL_CORE_RST_MSK (0x00000001 << CONTROL_CORE_RST_OFST) +#define CONTROL_PERIPHERAL_RST_OFST (11) // DDR3 HMem Ctrlr, GBE, Temp +#define CONTROL_PERIPHERAL_RST_MSK (0x00000001 << CONTROL_PERIPHERAL_RST_OFST) // DDR3 HMem Ctrlr, GBE, Temp +#define CONTROL_DDR3_MEM_RST_OFST (12) // only PHY, not DDR3 PLL ,Not used in software +#define CONTROL_DDR3_MEM_RST_MSK (0x00000001 << CONTROL_DDR3_MEM_RST_OFST) // only PHY, not DDR3 PLL ,Not used in software +#define CONTROL_ACQ_FIFO_CLR_OFST (14) +#define CONTROL_ACQ_FIFO_CLR_MSK (0x00000001 << CONTROL_ACQ_FIFO_CLR_OFST) +#define CONTROL_STORAGE_CELL_NUM_OFST (16) +#define CONTROL_STORAGE_CELL_NUM_MSK (0x0000000F << CONTROL_STORAGE_CELL_NUM_OFST) +#define CONTROL_RX_ADDTNL_ENDPTS_NUM_OFST (20) +#define CONTROL_RX_ADDTNL_ENDPTS_NUM_MSK (0x0000003F << CONTROL_RX_ADDTNL_ENDPTS_NUM_OFST) +#define CONTROL_RX_ENDPTS_START_OFST (26) +#define CONTROL_RX_ENDPTS_START_MSK (0x0000003F << CONTROL_RX_ENDPTS_START_OFST) /* Reconfiguratble PLL Paramater Register */ -#define PLL_PARAM_REG (0x50 << MEM_MAP_SHIFT) +#define PLL_PARAM_REG (0x50 << MEM_MAP_SHIFT) /* Reconfiguratble PLL Control Regiser */ -#define PLL_CNTRL_REG (0x51 << MEM_MAP_SHIFT) +#define PLL_CNTRL_REG (0x51 << MEM_MAP_SHIFT) -#define PLL_CNTRL_RCNFG_PRMTR_RST_OFST (0) // parameter reset -#define PLL_CNTRL_RCNFG_PRMTR_RST_MSK \ - (0x00000001 << PLL_CNTRL_RCNFG_PRMTR_RST_OFST) // parameter reset -#define PLL_CNTRL_WR_PRMTR_OFST (2) -#define PLL_CNTRL_WR_PRMTR_MSK (0x00000001 << PLL_CNTRL_WR_PRMTR_OFST) -#define PLL_CNTRL_PLL_RST_OFST (3) -#define PLL_CNTRL_PLL_RST_MSK (0x00000001 << PLL_CNTRL_PLL_RST_OFST) -#define PLL_CNTRL_DBIT_WR_PRMTR_OFST (5) -#define PLL_CNTRL_DBIT_WR_PRMTR_MSK (0x00000001 << PLL_CNTRL_DBIT_WR_PRMTR_OFST) -#define PLL_CNTRL_ADDR_OFST (16) -#define PLL_CNTRL_ADDR_MSK (0x0000003F << PLL_CNTRL_ADDR_OFST) +#define PLL_CNTRL_RCNFG_PRMTR_RST_OFST (0) // parameter reset +#define PLL_CNTRL_RCNFG_PRMTR_RST_MSK (0x00000001 << PLL_CNTRL_RCNFG_PRMTR_RST_OFST) // parameter reset +#define PLL_CNTRL_WR_PRMTR_OFST (2) +#define PLL_CNTRL_WR_PRMTR_MSK (0x00000001 << PLL_CNTRL_WR_PRMTR_OFST) +#define PLL_CNTRL_PLL_RST_OFST (3) +#define PLL_CNTRL_PLL_RST_MSK (0x00000001 << PLL_CNTRL_PLL_RST_OFST) +#define PLL_CNTRL_DBIT_WR_PRMTR_OFST (5) +#define PLL_CNTRL_DBIT_WR_PRMTR_MSK (0x00000001 << PLL_CNTRL_DBIT_WR_PRMTR_OFST) +#define PLL_CNTRL_ADDR_OFST (16) +#define PLL_CNTRL_ADDR_MSK (0x0000003F << PLL_CNTRL_ADDR_OFST) + +/* Config Register for chip 1.1 */ +#define CONFIG_V11_REG (0x58 << MEM_MAP_SHIFT) + +#define CONFIG_V11_FLTR_CLL_OFST (0) +#define CONFIG_V11_FLTR_CLL_MSK (0x00000FFF << CONFIG_V11_FLTR_CLL_OFST) +#define CONFIG_V11_STRG_CLL_OFST (12) +#define CONFIG_V11_STRG_CLL_MSK (0x0000000F << CONFIG_V11_STRG_CLL_OFST) +// CSM mode = high current (100%), low current (16%) +#define CONFIG_V11_CRRNT_SRC_LOW_OFST (19) +#define CONFIG_V11_CRRNT_SRC_LOW_MSK (0x00000001 << CONFIG_V11_CRRNT_SRC_LOW_OFST) +#define CONFIG_V11_FLTR_RSSTR_SMLR_OFST (21) +#define CONFIG_V11_FLTR_RSSTR_SMLR_MSK (0x00000001 << CONFIG_V11_FLTR_RSSTR_SMLR_OFST) +#define CONFIG_V11_AUTO_MODE_OVRRD_OFST (23) +#define CONFIG_V11_AUTO_MODE_OVRRD_MSK (0x00000001 << CONFIG_V11_AUTO_MODE_OVRRD_OFST) /* Sample Register */ -#define SAMPLE_REG (0x59 << MEM_MAP_SHIFT) +#define SAMPLE_REG (0x59 << MEM_MAP_SHIFT) -#define SAMPLE_ADC_SAMPLE_SEL_OFST (0) -#define SAMPLE_ADC_SAMPLE_SEL_MSK (0x00000007 << SAMPLE_ADC_SAMPLE_SEL_OFST) -#define SAMPLE_ADC_SAMPLE_0_VAL \ - ((0x0 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) -#define SAMPLE_ADC_SAMPLE_1_VAL \ - ((0x1 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) -#define SAMPLE_ADC_SAMPLE_2_VAL \ - ((0x2 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) -#define SAMPLE_ADC_SAMPLE_3_VAL \ - ((0x3 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) -#define SAMPLE_ADC_SAMPLE_4_VAL \ - ((0x4 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) -#define SAMPLE_ADC_SAMPLE_5_VAL \ - ((0x5 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) -#define SAMPLE_ADC_SAMPLE_6_VAL \ - ((0x6 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) -#define SAMPLE_ADC_SAMPLE_7_VAL \ - ((0x7 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) +#define SAMPLE_ADC_SAMPLE_SEL_OFST (0) +#define SAMPLE_ADC_SAMPLE_SEL_MSK (0x00000007 << SAMPLE_ADC_SAMPLE_SEL_OFST) +#define SAMPLE_ADC_SAMPLE_0_VAL ((0x0 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) +#define SAMPLE_ADC_SAMPLE_1_VAL ((0x1 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) +#define SAMPLE_ADC_SAMPLE_2_VAL ((0x2 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) +#define SAMPLE_ADC_SAMPLE_3_VAL ((0x3 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) +#define SAMPLE_ADC_SAMPLE_4_VAL ((0x4 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) +#define SAMPLE_ADC_SAMPLE_5_VAL ((0x5 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) +#define SAMPLE_ADC_SAMPLE_6_VAL ((0x6 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) +#define SAMPLE_ADC_SAMPLE_7_VAL ((0x7 << SAMPLE_ADC_SAMPLE_SEL_OFST) & SAMPLE_ADC_SAMPLE_SEL_MSK) // Decimation = ADF + 1 -#define SAMPLE_ADC_DECMT_FACTOR_OFST (4) -#define SAMPLE_ADC_DECMT_FACTOR_MSK (0x00000007 << SAMPLE_ADC_DECMT_FACTOR_OFST) -#define SAMPLE_ADC_DECMT_FACTOR_0_VAL \ - ((0x0 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) -#define SAMPLE_ADC_DECMT_FACTOR_1_VAL \ - ((0x1 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) -#define SAMPLE_ADC_DECMT_FACTOR_2_VAL \ - ((0x2 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) -#define SAMPLE_ADC_DECMT_FACTOR_3_VAL \ - ((0x3 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) -#define SAMPLE_ADC_DECMT_FACTOR_4_VAL \ - ((0x4 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) -#define SAMPLE_ADC_DECMT_FACTOR_5_VAL \ - ((0x5 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) -#define SAMPLE_ADC_DECMT_FACTOR_6_VAL \ - ((0x6 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) -#define SAMPLE_ADC_DECMT_FACTOR_7_VAL \ - ((0x7 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) +#define SAMPLE_ADC_DECMT_FACTOR_OFST (4) +#define SAMPLE_ADC_DECMT_FACTOR_MSK (0x00000007 << SAMPLE_ADC_DECMT_FACTOR_OFST) +#define SAMPLE_ADC_DECMT_FACTOR_0_VAL ((0x0 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) +#define SAMPLE_ADC_DECMT_FACTOR_1_VAL ((0x1 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) +#define SAMPLE_ADC_DECMT_FACTOR_2_VAL ((0x2 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) +#define SAMPLE_ADC_DECMT_FACTOR_3_VAL ((0x3 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) +#define SAMPLE_ADC_DECMT_FACTOR_4_VAL ((0x4 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) +#define SAMPLE_ADC_DECMT_FACTOR_5_VAL ((0x5 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) +#define SAMPLE_ADC_DECMT_FACTOR_6_VAL ((0x6 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) +#define SAMPLE_ADC_DECMT_FACTOR_7_VAL ((0x7 << SAMPLE_ADC_DECMT_FACTOR_OFST) & SAMPLE_ADC_DECMT_FACTOR_MSK) -#define SAMPLE_DGTL_SAMPLE_SEL_OFST (8) -#define SAMPLE_DGTL_SAMPLE_SEL_MSK (0x0000000F << SAMPLE_DGTL_SAMPLE_SEL_OFST) -#define SAMPLE_DGTL_SAMPLE_0_VAL \ - ((0x0 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_1_VAL \ - ((0x1 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_2_VAL \ - ((0x2 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_3_VAL \ - ((0x3 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_4_VAL \ - ((0x4 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_5_VAL \ - ((0x5 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_6_VAL \ - ((0x6 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_7_VAL \ - ((0x7 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_8_VAL \ - ((0x8 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_9_VAL \ - ((0x9 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_10_VAL \ - ((0xa << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_11_VAL \ - ((0xb << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_12_VAL \ - ((0xc << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_13_VAL \ - ((0xd << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_14_VAL \ - ((0xe << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_SAMPLE_15_VAL \ - ((0xf << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_SEL_OFST (8) +#define SAMPLE_DGTL_SAMPLE_SEL_MSK (0x0000000F << SAMPLE_DGTL_SAMPLE_SEL_OFST) +#define SAMPLE_DGTL_SAMPLE_0_VAL ((0x0 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_1_VAL ((0x1 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_2_VAL ((0x2 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_3_VAL ((0x3 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_4_VAL ((0x4 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_5_VAL ((0x5 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_6_VAL ((0x6 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_7_VAL ((0x7 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_8_VAL ((0x8 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_9_VAL ((0x9 << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_10_VAL ((0xa << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_11_VAL ((0xb << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_12_VAL ((0xc << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_13_VAL ((0xd << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_14_VAL ((0xe << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) +#define SAMPLE_DGTL_SAMPLE_15_VAL ((0xf << SAMPLE_DGTL_SAMPLE_SEL_OFST) & SAMPLE_DGTL_SAMPLE_SEL_MSK) -#define SAMPLE_DGTL_DECMT_FACTOR_OFST (12) -#define SAMPLE_DGTL_DECMT_FACTOR_MSK \ - (0x00000003 << SAMPLE_DGTL_DECMT_FACTOR_OFST) -#define SAMPLE_DECMT_FACTOR_FULL_VAL \ - ((0x0 << SAMPLE_DGTL_DECMT_FACTOR_OFST) & SAMPLE_DGTL_DECMT_FACTOR_MSK) -#define SAMPLE_DECMT_FACTOR_HALF_VAL \ - ((0x1 << SAMPLE_DGTL_DECMT_FACTOR_OFST) & SAMPLE_DGTL_DECMT_FACTOR_MSK) -#define SAMPLE_DECMT_FACTOR_QUARTER_VAL \ - ((0x2 << SAMPLE_DGTL_DECMT_FACTOR_OFST) & SAMPLE_DGTL_DECMT_FACTOR_MSK) +#define SAMPLE_DGTL_DECMT_FACTOR_OFST (12) +#define SAMPLE_DGTL_DECMT_FACTOR_MSK (0x00000003 << SAMPLE_DGTL_DECMT_FACTOR_OFST) +#define SAMPLE_DECMT_FACTOR_FULL_VAL ((0x0 << SAMPLE_DGTL_DECMT_FACTOR_OFST) & SAMPLE_DGTL_DECMT_FACTOR_MSK) +#define SAMPLE_DECMT_FACTOR_HALF_VAL ((0x1 << SAMPLE_DGTL_DECMT_FACTOR_OFST) & SAMPLE_DGTL_DECMT_FACTOR_MSK) +#define SAMPLE_DECMT_FACTOR_QUARTER_VAL ((0x2 << SAMPLE_DGTL_DECMT_FACTOR_OFST) & SAMPLE_DGTL_DECMT_FACTOR_MSK) + +/** Current Source Column 0 (0 - 31)) */ +#define CRRNT_SRC_COL_LSB_REG (0x5A << MEM_MAP_SHIFT) + +/** Current Source Column 1 (32 - 63) */ +#define CRRNT_SRC_COL_MSB_REG (0x5B << MEM_MAP_SHIFT) /** Vref Comp Mod Register */ -#define EXT_DAQ_CTRL_REG (0x5C << MEM_MAP_SHIFT) +#define EXT_DAQ_CTRL_REG (0x5C << MEM_MAP_SHIFT) -#define EXT_DAQ_CTRL_VREF_COMP_OFST (0) -#define EXT_DAQ_CTRL_VREF_COMP_MSK (0x00000FFF << EXT_DAQ_CTRL_VREF_COMP_OFST) -#define EXT_DAQ_CTRL_CMP_LGC_ENBL_OFST (15) -#define EXT_DAQ_CTRL_CMP_LGC_ENBL_MSK \ - (0x00000001 << EXT_DAQ_CTRL_CMP_LGC_ENBL_OFST) -#define EXT_DAQ_CTRL_INPT_DETECT_OFST (16) -#define EXT_DAQ_CTRL_INPT_DETECT_MSK \ - (0x00000007 << EXT_DAQ_CTRL_INPT_DETECT_OFST) -#define EXT_DAQ_CTRL_INPT_DETECT_ENBL_OFST (19) -#define EXT_DAQ_CTRL_INPT_DETECT_ENBL_MSK \ - (0x00000001 << EXT_DAQ_CTRL_INPT_DETECT_ENBL_OFST) +#define EXT_DAQ_CTRL_VREF_COMP_OFST (0) +#define EXT_DAQ_CTRL_VREF_COMP_MSK (0x00000FFF << EXT_DAQ_CTRL_VREF_COMP_OFST) +#define EXT_DAQ_CTRL_CMP_LGC_ENBL_OFST (15) +#define EXT_DAQ_CTRL_CMP_LGC_ENBL_MSK (0x00000001 << EXT_DAQ_CTRL_CMP_LGC_ENBL_OFST) +#define EXT_DAQ_CTRL_INPT_DETECT_OFST (16) +#define EXT_DAQ_CTRL_INPT_DETECT_MSK (0x00000007 << EXT_DAQ_CTRL_INPT_DETECT_OFST) +#define EXT_DAQ_CTRL_INPT_DETECT_ENBL_OFST (19) +#define EXT_DAQ_CTRL_INPT_DETECT_ENBL_MSK (0x00000001 << EXT_DAQ_CTRL_INPT_DETECT_ENBL_OFST) /** DAQ Register */ -#define DAQ_REG (0x5D << MEM_MAP_SHIFT) +#define DAQ_REG (0x5D << MEM_MAP_SHIFT) -#define DAQ_SETTINGS_MSK \ - (DAQ_HIGH_GAIN_MSK | DAQ_FIX_GAIN_MSK | DAQ_FRCE_SWTCH_GAIN_MSK) -#define DAQ_HIGH_GAIN_OFST (0) -#define DAQ_HIGH_GAIN_MSK (0x00000001 << DAQ_HIGH_GAIN_OFST) -#define DAQ_FIX_GAIN_DYNMC_VAL ((0x0 << DAQ_HIGH_GAIN_OFST) & DAQ_HIGH_GAIN_MSK) -#define DAQ_FIX_GAIN_HIGHGAIN_VAL \ - ((0x1 << DAQ_HIGH_GAIN_OFST) & DAQ_HIGH_GAIN_MSK) -#define DAQ_FIX_GAIN_OFST (1) -#define DAQ_FIX_GAIN_MSK (0x00000003 << DAQ_FIX_GAIN_OFST) -#define DAQ_FIX_GAIN_STG_1_VAL ((0x1 << DAQ_FIX_GAIN_OFST) & DAQ_FIX_GAIN_MSK) -#define DAQ_FIX_GAIN_STG_2_VAL ((0x3 << DAQ_FIX_GAIN_OFST) & DAQ_FIX_GAIN_MSK) -#define DAQ_CMP_RST_OFST (4) -#define DAQ_CMP_RST_MSK (0x00000001 << DAQ_CMP_RST_OFST) -#define DAQ_STRG_CELL_SLCT_OFST (8) -#define DAQ_STRG_CELL_SLCT_MSK (0x0000000F << DAQ_STRG_CELL_SLCT_OFST) -#define DAQ_FRCE_SWTCH_GAIN_OFST (12) -#define DAQ_FRCE_SWTCH_GAIN_MSK (0x00000003 << DAQ_FRCE_SWTCH_GAIN_OFST) -#define DAQ_FRCE_GAIN_STG_1_VAL \ - ((0x1 << DAQ_FRCE_SWTCH_GAIN_OFST) & DAQ_FRCE_SWTCH_GAIN_MSK) -#define DAQ_FRCE_GAIN_STG_2_VAL \ - ((0x3 << DAQ_FRCE_SWTCH_GAIN_OFST) & DAQ_FRCE_SWTCH_GAIN_MSK) -#define DAQ_ELCTRN_CLLCTN_MDE_OFST (14) -#define DAQ_ELCTRN_CLLCTN_MDE_MSK (0x00000001 << DAQ_ELCTRN_CLLCTN_MDE_OFST) -#define DAQ_G2_CNNT_OFST (15) -#define DAQ_G2_CNNT_MSK (0x00000001 << DAQ_G2_CNNT_OFST) -#define DAQ_CRRNT_SRC_ENBL_OFST (16) -#define DAQ_CRRNT_SRC_ENBL_MSK (0x00000001 << DAQ_CRRNT_SRC_ENBL_OFST) -#define DAQ_CRRNT_SRC_CLMN_FIX_OFST (17) -#define DAQ_CRRNT_SRC_CLMN_FIX_MSK (0x00000001 << DAQ_CRRNT_SRC_CLMN_FIX_OFST) -#define DAQ_CRRNT_SRC_CLMN_SLCT_OFST (20) -#define DAQ_CRRNT_SRC_CLMN_SLCT_MSK (0x0000003F << DAQ_CRRNT_SRC_CLMN_SLCT_OFST) +// dynamic gain (default) +#define DAQ_HIGH_GAIN_OFST (0) +#define DAQ_HIGH_GAIN_MSK (0x00000001 << DAQ_HIGH_GAIN_OFST) +#define DAQ_FIX_GAIN_OFST (1) +#define DAQ_FIX_GAIN_MSK (0x00000003 << DAQ_FIX_GAIN_OFST) +#define DAQ_FIX_GAIN_STG_1_VAL ((0x1 << DAQ_FIX_GAIN_OFST) & DAQ_FIX_GAIN_MSK) +#define DAQ_FIX_GAIN_STG_2_VAL ((0x3 << DAQ_FIX_GAIN_OFST) & DAQ_FIX_GAIN_MSK) +#define DAQ_CMP_RST_OFST (4) +#define DAQ_CMP_RST_MSK (0x00000001 << DAQ_CMP_RST_OFST) +#define DAQ_STRG_CELL_SLCT_OFST (8) +#define DAQ_STRG_CELL_SLCT_MSK (0x0000000F << DAQ_STRG_CELL_SLCT_OFST) +#define DAQ_FRCE_SWTCH_GAIN_OFST (12) +#define DAQ_FRCE_SWTCH_GAIN_MSK (0x00000003 << DAQ_FRCE_SWTCH_GAIN_OFST) +#define DAQ_FRCE_GAIN_STG_0_VAL ((0x0 << DAQ_FRCE_SWTCH_GAIN_OFST) & DAQ_FRCE_SWTCH_GAIN_MSK) +#define DAQ_FRCE_GAIN_STG_1_VAL ((0x1 << DAQ_FRCE_SWTCH_GAIN_OFST) & DAQ_FRCE_SWTCH_GAIN_MSK) +#define DAQ_FRCE_GAIN_STG_2_VAL ((0x3 << DAQ_FRCE_SWTCH_GAIN_OFST) & DAQ_FRCE_SWTCH_GAIN_MSK) +#define DAQ_ELCTRN_CLLCTN_MDE_OFST (14) +#define DAQ_ELCTRN_CLLCTN_MDE_MSK (0x00000001 << DAQ_ELCTRN_CLLCTN_MDE_OFST) +#define DAQ_G2_CNNT_OFST (15) +#define DAQ_G2_CNNT_MSK (0x00000001 << DAQ_G2_CNNT_OFST) +#define DAQ_CRRNT_SRC_ENBL_OFST (16) +#define DAQ_CRRNT_SRC_ENBL_MSK (0x00000001 << DAQ_CRRNT_SRC_ENBL_OFST) +#define DAQ_CRRNT_SRC_CLMN_FIX_OFST (17) +#define DAQ_CRRNT_SRC_CLMN_FIX_MSK (0x00000001 << DAQ_CRRNT_SRC_CLMN_FIX_OFST) +#define DAQ_CRRNT_SRC_CLMN_SLCT_OFST (20) +#define DAQ_CRRNT_SRC_CLMN_SLCT_MSK (0x0000003F << DAQ_CRRNT_SRC_CLMN_SLCT_OFST) +#define DAQ_GAIN_MODE_MASK (DAQ_FRCE_SWTCH_GAIN_MSK | DAQ_FIX_GAIN_MSK | DAQ_CMP_RST_MSK) /** Chip Power Register */ -#define CHIP_POWER_REG (0x5E << MEM_MAP_SHIFT) +#define CHIP_POWER_REG (0x5E << MEM_MAP_SHIFT) -#define CHIP_POWER_ENABLE_OFST (0) -#define CHIP_POWER_ENABLE_MSK (0x00000001 << CHIP_POWER_ENABLE_OFST) -#define CHIP_POWER_STATUS_OFST (1) -#define CHIP_POWER_STATUS_MSK (0x00000001 << CHIP_POWER_STATUS_OFST) +#define CHIP_POWER_ENABLE_OFST (0) +#define CHIP_POWER_ENABLE_MSK (0x00000001 << CHIP_POWER_ENABLE_OFST) +#define CHIP_POWER_STATUS_OFST (1) +#define CHIP_POWER_STATUS_MSK (0x00000001 << CHIP_POWER_STATUS_OFST) /** Temperature Control Register */ -#define TEMP_CTRL_REG (0x5F << MEM_MAP_SHIFT) +#define TEMP_CTRL_REG (0x5F << MEM_MAP_SHIFT) -#define TEMP_CTRL_PROTCT_THRSHLD_OFST (0) -#define TEMP_CTRL_PROTCT_THRSHLD_MSK \ - (0x000007FF << TEMP_CTRL_PROTCT_THRSHLD_OFST) -#define TEMP_CTRL_PROTCT_ENABLE_OFST (16) -#define TEMP_CTRL_PROTCT_ENABLE_MSK (0x00000001 << TEMP_CTRL_PROTCT_ENABLE_OFST) +#define TEMP_CTRL_PROTCT_THRSHLD_OFST (0) +#define TEMP_CTRL_PROTCT_THRSHLD_MSK (0x000007FF << TEMP_CTRL_PROTCT_THRSHLD_OFST) +#define TEMP_CTRL_PROTCT_ENABLE_OFST (16) +#define TEMP_CTRL_PROTCT_ENABLE_MSK (0x00000001 << TEMP_CTRL_PROTCT_ENABLE_OFST) // set when temp higher than over threshold, write 1 to clear it -#define TEMP_CTRL_OVR_TMP_EVNT_OFST (31) -#define TEMP_CTRL_OVR_TMP_EVNT_MSK (0x00000001 << TEMP_CTRL_OVR_TMP_EVNT_OFST) +#define TEMP_CTRL_OVR_TMP_EVNT_OFST (31) +#define TEMP_CTRL_OVR_TMP_EVNT_MSK (0x00000001 << TEMP_CTRL_OVR_TMP_EVNT_OFST) /* Set Delay 64 bit register */ -#define SET_DELAY_LSB_REG (0x60 << MEM_MAP_SHIFT) // different kind of delay -#define SET_DELAY_MSB_REG (0x61 << MEM_MAP_SHIFT) // different kind of delay +#define SET_DELAY_LSB_REG (0x60 << MEM_MAP_SHIFT) // different kind of delay +#define SET_DELAY_MSB_REG (0x61 << MEM_MAP_SHIFT) // different kind of delay /* Set Triggers 64 bit register */ -#define SET_CYCLES_LSB_REG (0x62 << MEM_MAP_SHIFT) -#define SET_CYCLES_MSB_REG (0x63 << MEM_MAP_SHIFT) +#define SET_CYCLES_LSB_REG (0x62 << MEM_MAP_SHIFT) +#define SET_CYCLES_MSB_REG (0x63 << MEM_MAP_SHIFT) /* Set Frames 64 bit register */ -#define SET_FRAMES_LSB_REG (0x64 << MEM_MAP_SHIFT) -#define SET_FRAMES_MSB_REG (0x65 << MEM_MAP_SHIFT) +#define SET_FRAMES_LSB_REG (0x64 << MEM_MAP_SHIFT) +#define SET_FRAMES_MSB_REG (0x65 << MEM_MAP_SHIFT) /* Set Period 64 bit register tT = T x 50 ns */ -#define SET_PERIOD_LSB_REG (0x66 << MEM_MAP_SHIFT) -#define SET_PERIOD_MSB_REG (0x67 << MEM_MAP_SHIFT) +#define SET_PERIOD_LSB_REG (0x66 << MEM_MAP_SHIFT) +#define SET_PERIOD_MSB_REG (0x67 << MEM_MAP_SHIFT) /* Set Exptime 64 bit register eEXP = Exp x 25 ns */ -#define SET_EXPTIME_LSB_REG (0x68 << MEM_MAP_SHIFT) -#define SET_EXPTIME_MSB_REG (0x69 << MEM_MAP_SHIFT) +#define SET_EXPTIME_LSB_REG (0x68 << MEM_MAP_SHIFT) +#define SET_EXPTIME_MSB_REG (0x69 << MEM_MAP_SHIFT) /* Starting Frame number 64 bit register */ -#define FRAME_NUMBER_LSB_REG (0x6A << MEM_MAP_SHIFT) -#define FRAME_NUMBER_MSB_REG (0x6B << MEM_MAP_SHIFT) +#define FRAME_NUMBER_LSB_REG (0x6A << MEM_MAP_SHIFT) +#define FRAME_NUMBER_MSB_REG (0x6B << MEM_MAP_SHIFT) + +/* Comparator disable time (chipv1.1) 32 bit register tT = T x 25 ns +Time before end of exposure when comparator is disabled */ +#define COMP_DSBLE_TIME_REG (0x6C << MEM_MAP_SHIFT) + /* Trigger Delay 32 bit register */ -#define SET_TRIGGER_DELAY_LSB_REG (0x70 << MEM_MAP_SHIFT) -#define SET_TRIGGER_DELAY_MSB_REG (0x71 << MEM_MAP_SHIFT) +#define SET_TRIGGER_DELAY_LSB_REG (0x70 << MEM_MAP_SHIFT) +#define SET_TRIGGER_DELAY_MSB_REG (0x71 << MEM_MAP_SHIFT) /** Module row coordinates */ -#define COORD_ROW_REG (0x7C << MEM_MAP_SHIFT) +#define COORD_ROW_REG (0x7C << MEM_MAP_SHIFT) -#define COORD_ROW_OUTER_OFST (0) -#define COORD_ROW_OUTER_MSK (0x0000FFFF << COORD_ROW_OUTER_OFST) -#define COORD_ROW_INNER_OFST (16) -#define COORD_ROW_INNER_MSK (0x0000FFFF << COORD_ROW_INNER_OFST) +#define COORD_ROW_OUTER_OFST (0) +#define COORD_ROW_OUTER_MSK (0x0000FFFF << COORD_ROW_OUTER_OFST) +#define COORD_ROW_INNER_OFST (16) +#define COORD_ROW_INNER_MSK (0x0000FFFF << COORD_ROW_INNER_OFST) /** Module column coordinates */ -#define COORD_COL_REG (0x7D << MEM_MAP_SHIFT) +#define COORD_COL_REG (0x7D << MEM_MAP_SHIFT) -#define COORD_COL_OUTER_OFST (0) -#define COORD_COL_OUTER_MSK (0x0000FFFF << COORD_COL_OUTER_OFST) -#define COORD_COL_INNER_OFST (16) -#define COORD_COL_INNER_MSK (0x0000FFFF << COORD_COL_INNER_OFST) +#define COORD_COL_OUTER_OFST (0) +#define COORD_COL_OUTER_MSK (0x0000FFFF << COORD_COL_OUTER_OFST) +#define COORD_COL_INNER_OFST (16) +#define COORD_COL_INNER_MSK (0x0000FFFF << COORD_COL_INNER_OFST) /** Module column coordinates */ -#define COORD_RESERVED_REG (0x7E << MEM_MAP_SHIFT) +#define COORD_RESERVED_REG (0x7E << MEM_MAP_SHIFT) -#define COORD_RESERVED_OUTER_OFST (0) -#define COORD_RESERVED_OUTER_MSK (0x0000FFFF << COORD_RESERVED_OUTER_OFST) -#define COORD_RESERVED_INNER_OFST (16) -#define COORD_RESERVED_INNER_MSK (0x0000FFFF << COORD_RESERVED_INNER_OFST) +#define COORD_RESERVED_OUTER_OFST (0) +#define COORD_RESERVED_OUTER_MSK (0x0000FFFF << COORD_RESERVED_OUTER_OFST) +#define COORD_RESERVED_INNER_OFST (16) +#define COORD_RESERVED_INNER_MSK (0x0000FFFF << COORD_RESERVED_INNER_OFST) /* ASIC Control Register */ -#define ASIC_CTRL_REG (0x7F << MEM_MAP_SHIFT) +#define ASIC_CTRL_REG (0x7F << MEM_MAP_SHIFT) // tPC = (PCT + 1) * 25ns -#define ASIC_CTRL_PRCHRG_TMR_OFST (0) -#define ASIC_CTRL_PRCHRG_TMR_MSK (0x000000FF << ASIC_CTRL_PRCHRG_TMR_OFST) -#define ASIC_CTRL_PRCHRG_TMR_VAL \ - ((0x1F << ASIC_CTRL_PRCHRG_TMR_OFST) & ASIC_CTRL_PRCHRG_TMR_MSK) +#define ASIC_CTRL_PRCHRG_TMR_OFST (0) +#define ASIC_CTRL_PRCHRG_TMR_MSK (0x000000FF << ASIC_CTRL_PRCHRG_TMR_OFST) +#define ASIC_CTRL_PRCHRG_TMR_VAL ((0x1F << ASIC_CTRL_PRCHRG_TMR_OFST) & ASIC_CTRL_PRCHRG_TMR_MSK) // tDS = (DST + 1) * 25ns -#define ASIC_CTRL_DS_TMR_OFST (8) -#define ASIC_CTRL_DS_TMR_MSK (0x000000FF << ASIC_CTRL_DS_TMR_OFST) -#define ASIC_CTRL_DS_TMR_VAL \ - ((0x1F << ASIC_CTRL_DS_TMR_OFST) & ASIC_CTRL_DS_TMR_MSK) +#define ASIC_CTRL_DS_TMR_OFST (8) +#define ASIC_CTRL_DS_TMR_MSK (0x000000FF << ASIC_CTRL_DS_TMR_OFST) +#define ASIC_CTRL_DS_TMR_VAL ((0x1F << ASIC_CTRL_DS_TMR_OFST) & ASIC_CTRL_DS_TMR_MSK) // tET = (ET + 1) * 25ns (increase timeout range between 2 consecutive storage // cells) -#define ASIC_CTRL_EXPSRE_TMR_OFST (16) -#define ASIC_CTRL_EXPSRE_TMR_MSK (0x0000FFFF << ASIC_CTRL_EXPSRE_TMR_OFST) -#define ASIC_CTRL_EXPSRE_TMR_MAX_VAL (0x0000FFFF / (CLK_RUN * 1E-3)) +#define ASIC_CTRL_EXPSRE_TMR_OFST (16) +#define ASIC_CTRL_EXPSRE_TMR_MSK (0x0000FFFF << ASIC_CTRL_EXPSRE_TMR_OFST) +#define ASIC_CTRL_EXPSRE_TMR_MAX_VAL (0x0000FFFF / (CLK_RUN * 1E-3)) /* ADC 0 Deserializer Control */ -#define ADC_DSRLZR_0_REG (0xF0 << MEM_MAP_SHIFT) -#define ADC_DSRLZR_0_RFRSH_ALGNMNT_OFST (31) /* Refresh alignment */ -#define ADC_DSRLZR_0_RFRSH_ALGNMNT_MSK \ - (0x00000001 << ADC_DSRLZR_0_RFRSH_ALGNMNT_OFST) +#define ADC_DSRLZR_0_REG (0xF0 << MEM_MAP_SHIFT) +#define ADC_DSRLZR_0_RFRSH_ALGNMNT_OFST (31) /* Refresh alignment */ +#define ADC_DSRLZR_0_RFRSH_ALGNMNT_MSK (0x00000001 << ADC_DSRLZR_0_RFRSH_ALGNMNT_OFST) /* ADC 0 Deserializer Control */ -#define ADC_DSRLZR_1_REG (0xF1 << MEM_MAP_SHIFT) -#define ADC_DSRLZR_1_RFRSH_ALGNMNT_OFST (31) -#define ADC_DSRLZR_1_RFRSH_ALGNMNT_MSK \ - (0x00000001 << ADC_DSRLZR_1_RFRSH_ALGNMNT_OFST) +#define ADC_DSRLZR_1_REG (0xF1 << MEM_MAP_SHIFT) +#define ADC_DSRLZR_1_RFRSH_ALGNMNT_OFST (31) +#define ADC_DSRLZR_1_RFRSH_ALGNMNT_MSK (0x00000001 << ADC_DSRLZR_1_RFRSH_ALGNMNT_OFST) /* ADC 0 Deserializer Control */ -#define ADC_DSRLZR_2_REG (0xF2 << MEM_MAP_SHIFT) -#define ADC_DSRLZR_2_RFRSH_ALGNMNT_OFST (31) -#define ADC_DSRLZR_2_RFRSH_ALGNMNT_MSK \ - (0x00000001 << ADC_DSRLZR_2_RFRSH_ALGNMNT_OFST) +#define ADC_DSRLZR_2_REG (0xF2 << MEM_MAP_SHIFT) +#define ADC_DSRLZR_2_RFRSH_ALGNMNT_OFST (31) +#define ADC_DSRLZR_2_RFRSH_ALGNMNT_MSK (0x00000001 << ADC_DSRLZR_2_RFRSH_ALGNMNT_OFST) /* ADC 0 Deserializer Control */ -#define ADC_DSRLZR_3_REG (0xF3 << MEM_MAP_SHIFT) -#define ADC_DSRLZR_3_RFRSH_ALGNMNT_OFST (31) -#define ADC_DSRLZR_3_RFRSH_ALGNMNT_MSK \ - (0x00000001 << ADC_DSRLZR_3_RFRSH_ALGNMNT_OFST) +#define ADC_DSRLZR_3_REG (0xF3 << MEM_MAP_SHIFT) +#define ADC_DSRLZR_3_RFRSH_ALGNMNT_OFST (31) +#define ADC_DSRLZR_3_RFRSH_ALGNMNT_MSK (0x00000001 << ADC_DSRLZR_3_RFRSH_ALGNMNT_OFST) /* Round Robin */ -#define RXR_ENDPOINTS_MAX (64) -#define RXR_ENDPOINT_OUTER_START_REG (0x1000 << MEM_MAP_SHIFT) -#define RXR_ENDPOINT_INNER_START_REG (0x2000 << MEM_MAP_SHIFT) +#define RXR_ENDPOINTS_MAX (64) +#define RXR_ENDPOINT_OUTER_START_REG (0x1000 << MEM_MAP_SHIFT) +#define RXR_ENDPOINT_INNER_START_REG (0x2000 << MEM_MAP_SHIFT) -#define RXR_ENDPOINT_OFST (0x10 << MEM_MAP_SHIFT) +#define RXR_ENDPOINT_OFST (0x10 << MEM_MAP_SHIFT) + +// clang-format on diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index 09de78144..5ccefab6a 100755 Binary files a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer and b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer differ diff --git a/slsDetectorServers/jungfrauDetectorServer/config_jungfrau.txt b/slsDetectorServers/jungfrauDetectorServer/config_jungfrau.txt new file mode 100755 index 000000000..48fea871e --- /dev/null +++ b/slsDetectorServers/jungfrauDetectorServer/config_jungfrau.txt @@ -0,0 +1,4 @@ + + +#chip version version (multiplied by 10) +chipversion 11 diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index f9ac4032e..ba07af16d 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -43,8 +43,13 @@ int virtual_image_test_mode = 0; enum detectorSettings thisSettings = UNINITIALIZED; int highvoltage = 0; int dacValues[NDAC] = {}; +int defaultDacValues[] = DEFAULT_DAC_VALS; +int defaultDacValue_G0[] = SPECIAL_DEFAULT_DYNAMIC_GAIN_VALS; +int defaultDacValue_HG0[] = SPECIAL_DEFAULT_DYNAMICHG0_GAIN_VALS; int32_t clkPhase[NUM_CLOCKS] = {}; int detPos[4] = {}; +int chipVersion = 10; // (1.0) +int chipConfigured = 0; int isInitCheckDone() { return initCheckDone; } @@ -101,6 +106,7 @@ void basictests() { if (fwversion >= MIN_REQRD_VRSN_T_RD_API) sw_fw_apiversion = getFirmwareAPIVersion(); + LOG(logINFOBLUE, ("************ Jungfrau Server *********************\n" "Hardware Version:\t\t 0x%x\n" @@ -283,12 +289,17 @@ u_int16_t getHardwareSerialNumber() { // is board 1.0?, with value 2 (resistor network) int isHardwareVersion2() { +#ifdef VIRTUAL + return 0; +#endif return (((bus_r(MOD_SERIAL_NUM_REG) & HARDWARE_VERSION_NUM_MSK) == HARDWARE_VERSION_2_VAL) ? 1 : 0); } +int getChipVersion() { return chipVersion; } + u_int32_t getDetectorNumber() { #ifdef VIRTUAL return 0; @@ -379,10 +390,16 @@ void setupDetector() { for (int i = 0; i < NUM_CLOCKS; ++i) { clkPhase[i] = 0; } + chipConfigured = 0; #ifdef VIRTUAL sharedMemory_setStatus(IDLE); #endif + // get chip version + if (readConfigFile() == FAIL) { + return; + } + ALTERA_PLL_ResetPLL(); resetCore(); resetPeripheral(); @@ -409,7 +426,7 @@ void setupDetector() { DAC_MAX_MV); LTC2620_Disable(); LTC2620_Configure(); - setDefaultDacs(); + resetToDefaultDacs(0); // altera pll ALTERA_PLL_SetDefines( @@ -434,15 +451,21 @@ void setupDetector() { // Initialization of acquistion parameters setSettings(DEFAULT_SETTINGS); + setGainMode(DEFAULT_GAINMODE); setNumFrames(DEFAULT_NUM_FRAMES); setNumTriggers(DEFAULT_NUM_CYCLES); setExpTime(DEFAULT_EXPTIME); setPeriod(DEFAULT_PERIOD); setDelayAfterTrigger(DEFAULT_DELAY); - setNumAdditionalStorageCells(DEFAULT_NUM_STRG_CLLS); - setStorageCellDelay(DEFAULT_STRG_CLL_DLY); - selectStoragecellStart(DEFAULT_STRG_CLL_STRT); + if (getChipVersion() == 11) { + selectStoragecellStart(DEFAULT_STRG_CLL_STRT_CHIP11); + } else { + setNumAdditionalStorageCells(DEFAULT_NUM_STRG_CLLS); + selectStoragecellStart(DEFAULT_STRG_CLL_STRT); + // not applicable for chipv1.1 + setStorageCellDelay(DEFAULT_STRG_CLL_DLY); + } /*setClockDivider(RUN_CLK, HALF_SPEED); depends if all the previous stuff * works*/ setTiming(DEFAULT_TIMING_MODE); @@ -451,21 +474,259 @@ void setupDetector() { // temp threshold and reset event setThresholdTemperature(DEFAULT_TMP_THRSHLD); setTemperatureEvent(0); + setFlipRows(DEFAULT_FLIP_ROWS); + if (getChipVersion() == 11) { + setFilterResistor(DEFAULT_FILTER_RESISTOR); + setFilterCell(DEFAULT_FILTER_CELL); + } + disableCurrentSource(); } -int setDefaultDacs() { - int ret = OK; - LOG(logINFOBLUE, ("Setting Default Dac values\n")); - const int defaultvals[NDAC] = DEFAULT_DAC_VALS; +int resetToDefaultDacs(int hardReset) { + LOG(logINFOBLUE, ("Resetting %s to Default Dac values\n", + (hardReset == 1 ? "hard" : ""))); + + // reset defaults to hardcoded defaults + if (hardReset) { + const int vals[] = DEFAULT_DAC_VALS; + for (int i = 0; i < NDAC; ++i) { + defaultDacValues[i] = vals[i]; + } + const int vals_G0[] = SPECIAL_DEFAULT_DYNAMIC_GAIN_VALS; + for (int i = 0; i < NSPECIALDACS; ++i) { + defaultDacValue_G0[i] = vals_G0[i]; + } + const int vals_HG0[] = SPECIAL_DEFAULT_DYNAMICHG0_GAIN_VALS; + for (int i = 0; i < NSPECIALDACS; ++i) { + defaultDacValue_HG0[i] = vals_HG0[i]; + } + } + + // remember settings + enum detectorSettings oldSettings = thisSettings; + + // reset dacs to defaults + const int specialDacs[] = SPECIALDACINDEX; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultvals[i], 0); - if (dacValues[i] != defaultvals[i]) { - ret = FAIL; + int value = defaultDacValues[i]; + + for (int j = 0; j < NSPECIALDACS; ++j) { + // special dac: replace default value + if (specialDacs[j] == i) { + switch (oldSettings) { + case GAIN0: + value = defaultDacValue_G0[j]; + break; + case HIGHGAIN0: + value = defaultDacValue_HG0[j]; + break; + default: + break; + } + break; + } + } + + // set to defualt + setDAC((enum DACINDEX)i, value, 0); + if (dacValues[i] != value) { LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultvals[i], dacValues[i])); + value, dacValues[i])); + return FAIL; } } - return ret; + return OK; +} + +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + + // settings only for special dacs + if (sett != UNDEFINED) { + const int specialDacs[] = SPECIALDACINDEX; + // find special dac index + for (int i = 0; i < NSPECIALDACS; ++i) { + if ((int)index == specialDacs[i]) { + switch (sett) { + case GAIN0: + *retval = defaultDacValue_G0[i]; + return OK; + case HIGHGAIN0: + *retval = defaultDacValue_HG0[i]; + return OK; + // unknown settings + default: + return FAIL; + } + } + } + // not a special dac + return FAIL; + } + + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + char *dac_names[] = {DAC_NAMES}; + + // settings only for special dacs + if (sett != UNDEFINED) { + const int specialDacs[] = SPECIALDACINDEX; + // find special dac index + for (int i = 0; i < NSPECIALDACS; ++i) { + if ((int)index == specialDacs[i]) { + switch (sett) { + case GAIN0: + LOG(logINFO, ("Setting Default Dac [%d - %s, gain0]: %d\n", + (int)index, dac_names[index], value)); + defaultDacValue_G0[i] = value; + return OK; + case HIGHGAIN0: + LOG(logINFO, + ("Setting Default Dac [%d - %s, highgain0]: %d\n", + (int)index, dac_names[index], value)); + defaultDacValue_HG0[i] = value; + return OK; + // unknown settings + default: + return FAIL; + } + } + } + // not a special dac + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} + +int readConfigFile() { + + if (initError == FAIL) { + return initError; + } + + const int fileNameSize = 128; + char fname[fileNameSize]; + if (getAbsPath(fname, fileNameSize, CONFIG_FILE) == FAIL) { + return FAIL; + } + + // open config file + FILE *fd = fopen(fname, "r"); + if (fd == NULL) { + sprintf(initErrorMessage, + "Could not open on-board detector server config file [%s].\n", + CONFIG_FILE); + initError = FAIL; + LOG(logERROR, ("%s\n\n", initErrorMessage)); + return FAIL; + } + + LOG(logINFOBLUE, ("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; + } + + // removing leading spaces + if (line[0] == ' ' || line[0] == '\t') { + int len = strlen(line); + // find first valid character + int i = 0; + for (i = 0; i < len; ++i) { + if (line[i] != ' ' && line[i] != '\t') { + break; + } + } + // ignore the line full of spaces (last char \n) + if (i >= len - 1) { + LOG(logDEBUG1, ("Ignoring line full of spaces\n")); + continue; + } + // copying only valid char + char temp[LZ]; + memset(temp, 0, LZ); + memcpy(temp, line + i, strlen(line) - i); + memset(line, 0, LZ); + memcpy(line, temp, strlen(temp)); + LOG(logDEBUG1, ("Removing leading spaces.\n")); + } + + LOG(logDEBUG1, ("Command to process: (size:%d) %.*s\n", strlen(line), + strlen(line) - 1, line)); + memset(command, 0, LZ); + + // chipversion command + if (!strncmp(line, "chipversion", strlen("chipversion"))) { + int version = 0; + + // cannot scan values + if (sscanf(line, "%s %d", command, &version) != 2) { + sprintf( + initErrorMessage, + "Could not scan chipversion commands from on-board server " + "config file. Line:[%s].\n", + line); + break; + } + // validations + if (version != 10 && version != 11) { + sprintf(initErrorMessage, + "Could not set chip version from on-board server " + "config file. Invalid chip version %d. Line:[%s].\n", + version, line); + break; + } + + // validations + chipVersion = version; + LOG(logINFOBLUE, ("Chip Version: v%.01f\n", chipVersion / 10.0)); + + // version 1.1 and HW 1.0 (version reg value = 2) is incompatible + if (chipVersion == 11 && isHardwareVersion2()) { + strcpy(initErrorMessage, + "Chip version 1.1 (from on-board config file) is incompatible with old board (v1.0). Please update board or correct on-board config file.\n"); + break; + } + } + + memset(line, 0, LZ); + } + fclose(fd); + + if (strlen(initErrorMessage)) { + initError = FAIL; + LOG(logERROR, ("%s\n\n", initErrorMessage)); + } else { + LOG(logINFOBLUE, ("Successfully read config file\n")); + } + return initError; } /* firmware functions (resets) */ @@ -523,14 +784,57 @@ uint32_t getADCInvertRegister() { /* parameters - timer */ int selectStoragecellStart(int pos) { + int value = pos; + uint32_t addr = DAQ_REG; + uint32_t mask = DAQ_STRG_CELL_SLCT_MSK; + int offset = DAQ_STRG_CELL_SLCT_OFST; + if (getChipVersion() == 11) { + // set the bit + value = 1 << pos; + addr = CONFIG_V11_REG; + mask = CONFIG_V11_STRG_CLL_MSK; + offset = CONFIG_V11_STRG_CLL_OFST; + } if (pos >= 0) { LOG(logINFO, ("Setting storage cell start: %d\n", pos)); - bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_STRG_CELL_SLCT_MSK); - bus_w(DAQ_REG, bus_r(DAQ_REG) | ((pos << DAQ_STRG_CELL_SLCT_OFST) & - DAQ_STRG_CELL_SLCT_MSK)); + bus_w(addr, bus_r(addr) & ~mask); + bus_w(addr, bus_r(addr) | ((value << offset) & mask)); + // should not do a get to verify (status register does not update + // immediately during acquisition) + if (getChipVersion() == 11) { + return pos; + } + } + + // read value back + // chipv1.1, writing and reading registers are different +#ifndef VIRTUAL + if (getChipVersion() == 11) { + addr = CONFIG_V11_STATUS_REG; + mask = CONFIG_V11_STATUS_STRG_CLL_MSK; + offset = CONFIG_V11_STATUS_STRG_CLL_OFST; + } +#endif + int retval = ((bus_r(addr) & mask) >> offset); + if (getChipVersion() == 11) { + // get which bit + int max = getMaxStoragecellStart(); + for (int i = 0; i != max + 1; ++i) { + if (retval & (1 << i)) { + return i; + } + } + } + // chip v1.0 + return retval; +} + +int getMaxStoragecellStart() { + if (getChipVersion() == 11) { + return MAX_STORAGE_CELL_CHIP11_VAL; + } else { + return MAX_STORAGE_CELL_VAL; } - return ((bus_r(DAQ_REG) & DAQ_STRG_CELL_SLCT_MSK) >> - DAQ_STRG_CELL_SLCT_OFST); } int setNextFrameNumber(uint64_t value) { @@ -749,95 +1053,140 @@ enum detectorSettings setSettings(enum detectorSettings sett) { if (sett == UNINITIALIZED) return thisSettings; + int *dacVals = NULL; // set settings switch (sett) { - case DYNAMICGAIN: - bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK); + case GAIN0: + bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_HIGH_GAIN_MSK); LOG(logINFO, - ("Set settings - Dyanmic Gain, DAQ Reg: 0x%x\n", bus_r(DAQ_REG))); + ("Set settings - Gain 0 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); + dacVals = defaultDacValue_G0; break; - case DYNAMICHG0: - bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK); - bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FIX_GAIN_HIGHGAIN_VAL); - LOG(logINFO, ("Set settings - Dyanmic High Gain 0, DAQ Reg: 0x%x\n", - bus_r(DAQ_REG))); - break; - case FIXGAIN1: - bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK); - bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FIX_GAIN_STG_1_VAL); + case HIGHGAIN0: + bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_HIGH_GAIN_MSK); LOG(logINFO, - ("Set settings - Fix Gain 1, DAQ Reg: 0x%x\n", bus_r(DAQ_REG))); - break; - case FIXGAIN2: - bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK); - bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FIX_GAIN_STG_2_VAL); - LOG(logINFO, - ("Set settings - Fix Gain 2, DAQ Reg: 0x%x\n", bus_r(DAQ_REG))); - break; - case FORCESWITCHG1: - bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK); - bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FRCE_GAIN_STG_1_VAL); - LOG(logINFO, ("Set settings - Force Switch Gain 1, DAQ Reg: 0x%x\n", - bus_r(DAQ_REG))); - break; - case FORCESWITCHG2: - bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK); - bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FRCE_GAIN_STG_2_VAL); - LOG(logINFO, ("Set settings - Force Switch Gain 2, DAQ Reg: 0x%x\n", - bus_r(DAQ_REG))); + ("Set settings - High Gain 0 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); + dacVals = defaultDacValue_HG0; break; default: - LOG(logERROR, - ("This settings is not defined for this detector %d\n", (int)sett)); + LOG(logERROR, ("This settings %d is not defined\n", (int)sett)); return -1; } thisSettings = sett; + // set special dacs + const int specialDacs[] = SPECIALDACINDEX; + for (int i = 0; i < NSPECIALDACS; ++i) { + setDAC(specialDacs[i], dacVals[i], 0); + } + + // if chip 1.1, and power chip on, configure chip + if (getChipVersion() == 11 && powerChip(-1)) { + configureChip(); + } + return getSettings(); } enum detectorSettings getSettings() { + if (bus_r(DAQ_REG) & DAQ_HIGH_GAIN_MSK) + return HIGHGAIN0; + return GAIN0; +} +enum gainMode getGainMode() { uint32_t regval = bus_r(DAQ_REG); - uint32_t val = regval & DAQ_SETTINGS_MSK; - LOG(logDEBUG1, ("Getting Settings\n Reading DAQ Register :0x%x\n", val)); + uint32_t retval_force = regval & DAQ_FRCE_SWTCH_GAIN_MSK; + uint32_t retval_fix = regval & DAQ_FIX_GAIN_MSK; + uint32_t retval_cmp_rst = regval & DAQ_CMP_RST_MSK; - switch (val) { - case DAQ_FIX_GAIN_DYNMC_VAL: - thisSettings = DYNAMICGAIN; - LOG(logDEBUG1, - ("Settings read: Dynamic Gain. DAQ Reg: 0x%x\n", regval)); - break; - case DAQ_FIX_GAIN_HIGHGAIN_VAL: - thisSettings = DYNAMICHG0; - LOG(logDEBUG1, - ("Settings read: Dynamig High Gain. DAQ Reg: 0x%x\n", regval)); - break; - case DAQ_FIX_GAIN_STG_1_VAL: - thisSettings = FIXGAIN1; - LOG(logDEBUG1, ("Settings read: Fix Gain 1. DAQ Reg: 0x%x\n", regval)); - break; - case DAQ_FIX_GAIN_STG_2_VAL: - thisSettings = FIXGAIN2; - LOG(logDEBUG1, ("Settings read: Fix Gain 2. DAQ Reg: 0x%x\n", regval)); - break; - case DAQ_FRCE_GAIN_STG_1_VAL: - thisSettings = FORCESWITCHG1; - LOG(logDEBUG1, - ("Settings read: Force Switch Gain 1. DAQ Reg: 0x%x\n", regval)); - break; - case DAQ_FRCE_GAIN_STG_2_VAL: - thisSettings = FORCESWITCHG2; - LOG(logDEBUG1, - ("Settings read: Force Switch Gain 2. DAQ Reg: 0x%x\n", regval)); - break; - default: - thisSettings = UNDEFINED; - LOG(logERROR, ("Settings read: Undefined. DAQ Reg: 0x%x\n", regval)); + // only one set should be valid + if ((retval_force && retval_fix) || (retval_fix && retval_cmp_rst) || + (retval_force && retval_cmp_rst)) { + LOG(logERROR, ("undefined gain mode. DAQ reg: 0x%x\n", regval)); } - return thisSettings; + // dynamic gain, when nothing is set + if (retval_force == 0 && retval_fix == 0 && retval_cmp_rst == 0) { + return DYNAMIC; + } + + switch (retval_force) { + case DAQ_FRCE_GAIN_STG_1_VAL: + return FORCE_SWITCH_G1; + case DAQ_FRCE_GAIN_STG_2_VAL: + return FORCE_SWITCH_G2; + default: + break; + } + + switch (retval_fix) { + case DAQ_FIX_GAIN_STG_1_VAL: + return FIX_G1; + case DAQ_FIX_GAIN_STG_2_VAL: + return FIX_G2; + default: + break; + } + + if (retval_cmp_rst) { + return FIX_G0; + } + + LOG(logERROR, ("This gain mode is undefined [DAQ reg: %d]\n", regval)); + return -1; +} + +void setGainMode(enum gainMode mode) { + uint32_t addr = DAQ_REG; + uint32_t value = bus_r(addr); + + switch (mode) { + case DYNAMIC: + value &= ~(DAQ_GAIN_MODE_MASK); + bus_w(addr, value); + LOG(logINFO, + ("Set gain mode - Dynamic Gain [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); + break; + case FORCE_SWITCH_G1: + value &= ~(DAQ_GAIN_MODE_MASK); + value |= DAQ_FRCE_GAIN_STG_1_VAL; + bus_w(addr, value); + LOG(logINFO, ("Set gain mode - Force Switch G1 [DAQ Reg:0x%x]\n", + bus_r(DAQ_REG))); + break; + case FORCE_SWITCH_G2: + value &= ~(DAQ_GAIN_MODE_MASK); + value |= DAQ_FRCE_GAIN_STG_2_VAL; + bus_w(addr, value); + LOG(logINFO, ("Set gain mode - Force Switch G2 [DAQ Reg:0x%x]\n", + bus_r(DAQ_REG))); + break; + case FIX_G1: + value &= ~(DAQ_GAIN_MODE_MASK); + value |= DAQ_FIX_GAIN_STG_1_VAL; + bus_w(addr, value); + LOG(logINFO, + ("Set gain mode - Fix G1 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); + break; + case FIX_G2: + value &= ~(DAQ_GAIN_MODE_MASK); + value |= DAQ_FIX_GAIN_STG_2_VAL; + bus_w(addr, value); + LOG(logINFO, + ("Set gain mode - Fix G2 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); + break; + case FIX_G0: + value &= ~(DAQ_GAIN_MODE_MASK); + value |= DAQ_CMP_RST_MSK; + bus_w(addr, value); + LOG(logINFO, + ("Set gain mode - Fix G0 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); + break; + default: + LOG(logERROR, ("This gain mode %d is not defined\n", (int)mode)); + } } /* parameters - dac, adc, hv */ @@ -846,11 +1195,10 @@ void setDAC(enum DACINDEX ind, int val, int mV) { return; char *dac_names[] = {DAC_NAMES}; - LOG(logINFO, ("Setting DAC %s\n", dac_names[ind])); - LOG(logDEBUG1, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], - val, (mV ? "mV" : "dac units"))); int dacval = val; #ifdef VIRTUAL + LOG(logINFO, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind], + val, (mV ? "mV" : "dac units"))); if (!mV) { dacValues[ind] = val; } @@ -859,6 +1207,7 @@ void setDAC(enum DACINDEX ind, int val, int mV) { dacValues[ind] = dacval; } #else + LOG(logINFO, ("Setting DAC %s\n", dac_names[ind])); if (LTC2620_SetDACValue((int)ind, val, mV, &dacval) == OK) { dacValues[ind] = dacval; if (ind == J_VREF_COMP && @@ -1280,13 +1629,17 @@ void initReadoutConfiguration() { int powerChip(int on) { if (on != -1) { if (on) { - LOG(logINFO, ("Powering chip: on\n")); + LOG(logINFOBLUE, ("Powering chip: on\n")); bus_w(CHIP_POWER_REG, bus_r(CHIP_POWER_REG) | CHIP_POWER_ENABLE_MSK); + + configureChip(); } else { - LOG(logINFO, ("Powering chip: off\n")); + LOG(logINFOBLUE, ("Powering chip: off\n")); bus_w(CHIP_POWER_REG, bus_r(CHIP_POWER_REG) & ~CHIP_POWER_ENABLE_MSK); + + chipConfigured = 0; } } #ifdef VIRTUAL @@ -1297,6 +1650,22 @@ int powerChip(int on) { CHIP_POWER_STATUS_OFST); } +int isChipConfigured() { + return chipConfigured; +} + +void configureChip() { + // only for chipv1.1 + if (chipVersion == 11) { + LOG(logINFOBLUE, ("Configuring chip\n")); + // write same register values back to configure chip + uint32_t val = bus_r(CONFIG_V11_REG); + bus_w(CONFIG_V11_REG, val); + chipConfigured = 1; + } +} + + int autoCompDisable(int on) { if (on != -1) { if (on) { @@ -1314,6 +1683,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) | @@ -1613,6 +2008,167 @@ void alignDeserializer() { bus_r(ADC_DSRLZR_3_REG) & (~(ADC_DSRLZR_3_RFRSH_ALGNMNT_MSK))); } +int getFlipRows() { + return ((bus_r(CONFIG_REG) & CONFIG_BOTTOM_INVERT_STREAM_MSK) >> + CONFIG_BOTTOM_INVERT_STREAM_OFST); +} + +void setFlipRows(int arg) { + if (arg >= 0) { + if (arg == 0) { + LOG(logINFO, ("Switching off bottom row flipping\n")); + bus_w(CONFIG_REG, + bus_r(CONFIG_REG) & ~CONFIG_BOTTOM_INVERT_STREAM_MSK); + } else { + LOG(logINFO, ("Switching on bottom row flipping\n")); + bus_w(CONFIG_REG, + bus_r(CONFIG_REG) | CONFIG_BOTTOM_INVERT_STREAM_MSK); + } + } +} + +int getFilterResistor() { +#ifdef VIRTUAL + uint32_t addr = CONFIG_V11_REG; +#else + uint32_t addr = CONFIG_V11_STATUS_REG; +#endif + // 0 for lower value, 1 for higher value + if (bus_r(addr) & CONFIG_V11_STATUS_FLTR_RSSTR_SMLR_MSK) { + return 0; + } + return 1; +} + +int setFilterResistor(int value) { + // lower resistor + if (value == 0) { + LOG(logINFO, ("Setting Lower Filter Resistor\n")); + bus_w(CONFIG_V11_REG, + bus_r(CONFIG_V11_REG) | CONFIG_V11_FLTR_RSSTR_SMLR_MSK); + return OK; + } + // higher resistor + else if (value == 1) { + LOG(logINFO, ("Setting Higher Filter Resistor\n")); + bus_w(CONFIG_V11_REG, + bus_r(CONFIG_V11_REG) & ~CONFIG_V11_FLTR_RSSTR_SMLR_MSK); + return OK; + } + LOG(logERROR, ("Could not set Filter Resistor. Invalid value %d\n", value)); + return FAIL; +} + +int getFilterCell() { +#ifdef VIRTUAL + uint32_t addr = CONFIG_V11_REG; +#else + uint32_t addr = CONFIG_V11_STATUS_REG; +#endif + uint32_t value = (bus_r(addr) & CONFIG_V11_FLTR_CLL_MSK) >> CONFIG_V11_FLTR_CLL_OFST; + // count number of bits = which icell + return (__builtin_popcount(value)); +} + +void setFilterCell(int iCell) { + uint32_t value = 0; + // sets the corresponding cell and the cells before it + if (iCell != 0) { + value = iCell; + if (value > 1) { + value += (value - 1); + } + } + uint32_t addr = CONFIG_V11_REG; + bus_w(addr, bus_r(addr) &~ CONFIG_V11_FLTR_CLL_MSK); + bus_w(addr, bus_r(addr) | ((value << CONFIG_V11_FLTR_CLL_OFST) & CONFIG_V11_FLTR_CLL_MSK)); + LOG(logINFO, ("Setting Filter Cell to %d [Reg:0x%x]\n", iCell, bus_r(addr))); +} + +void disableCurrentSource() { + LOG(logINFO, ("Disabling Current Source\n")); + bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_CRRNT_SRC_ENBL_MSK); +} + +void enableCurrentSource(int fix, uint64_t select, int normal) { + if (chipVersion == 11) { + LOG(logINFO, ("Enabling current source [fix:%d, select:%lld]\n", fix, + (long long int)select)); + } else { + LOG(logINFO, + ("Enabling current source [fix:%d, select:0x%llx, normal:%d]\n", + fix, (long long int)select, normal)); + } + disableCurrentSource(); + LOG(logINFO, ("\tSetting current source parameters\n")); + // fix + if (fix) { + bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_CRRNT_SRC_CLMN_FIX_MSK); + } else { + bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_CRRNT_SRC_CLMN_FIX_MSK); + } + if (chipVersion == 10) { + // select + bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_CRRNT_SRC_CLMN_SLCT_MSK); + bus_w(DAQ_REG, + bus_r(DAQ_REG) | ((select << DAQ_CRRNT_SRC_CLMN_SLCT_OFST) & + DAQ_CRRNT_SRC_CLMN_SLCT_MSK)); + + } else { + // select + set64BitReg(select, CRRNT_SRC_COL_LSB_REG, CRRNT_SRC_COL_MSB_REG); + // normal + if (normal) { + bus_w(CONFIG_V11_REG, + bus_r(CONFIG_V11_REG) & ~CONFIG_V11_CRRNT_SRC_LOW_MSK); + } else { + bus_w(CONFIG_V11_REG, + bus_r(CONFIG_V11_REG) | CONFIG_V11_CRRNT_SRC_LOW_MSK); + } + } + // validating before enabling current source + if (getFixCurrentSource() != fix || getSelectCurrentSource() != select) { + LOG(logERROR, + ("Could not set fix or select parameters for current source.\n")) + return; + } + // not validating normal because the status register might not update during + // acquisition + + // enabling current source + LOG(logINFO, ("Enabling Current Source\n")); + bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_CRRNT_SRC_ENBL_MSK); +} + +int getCurrentSource() { + return ((bus_r(DAQ_REG) & DAQ_CRRNT_SRC_ENBL_MSK) >> + DAQ_CRRNT_SRC_ENBL_OFST); +} + +int getFixCurrentSource() { + return ((bus_r(DAQ_REG) & DAQ_CRRNT_SRC_CLMN_FIX_MSK) >> + DAQ_CRRNT_SRC_CLMN_FIX_OFST); +} + +int getNormalCurrentSource() { + if (getChipVersion() == 11) { + int low = ((bus_r(CONFIG_V11_STATUS_REG) & + CONFIG_V11_STATUS_CRRNT_SRC_LOW_MSK) >> + CONFIG_V11_STATUS_CRRNT_SRC_LOW_OFST); + return (low == 0 ? 1 : 0); + } + return -1; +} + +uint64_t getSelectCurrentSource() { + if (chipVersion == 10) { + return ((bus_r(DAQ_REG) & DAQ_CRRNT_SRC_CLMN_SLCT_MSK) >> + DAQ_CRRNT_SRC_CLMN_SLCT_OFST); + } else { + return get64BitReg(CRRNT_SRC_COL_LSB_REG, CRRNT_SRC_COL_MSB_REG); + } +} + int getTenGigaFlowControl() { return ((bus_r(CONFIG_REG) & CONFIG_ETHRNT_FLW_CNTRL_MSK) >> CONFIG_ETHRNT_FLW_CNTRL_OFST); diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h index 9877917c6..8d29fe307 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h @@ -3,8 +3,8 @@ #include "sls/sls_detector_defs.h" #define MIN_REQRD_VRSN_T_RD_API 0x171220 -#define REQRD_FRMWRE_VRSN_BOARD2 0x210218 // 1.0 pcb -#define REQRD_FRMWRE_VRSN 0x200721 // 2.0 pcb +#define REQRD_FRMWRE_VRSN_BOARD2 0x210621 // 1.0 pcb (version = 010) +#define REQRD_FRMWRE_VRSN 0x210622 // 2.0 pcb (version = 011) #define CTRL_SRVR_INIT_TIME_US (300 * 1000) @@ -62,6 +62,15 @@ enum DACINDEX { 480, /* J_VREF_DS */ \ 420 /* J_VREF_COMP */ \ }; + +#define NUMSETTINGS (2) +#define NSPECIALDACS (3) +#define SPECIALDACINDEX {J_VREF_PRECH, J_VREF_DS, J_VREF_COMP}; +#define SPECIAL_DEFAULT_DYNAMIC_GAIN_VALS \ + { 1000, 500, 400 } +#define SPECIAL_DEFAULT_DYNAMICHG0_GAIN_VALS \ + { 1500, 550, 450 } + enum NETWORKINDEX { TXN_FRAME, FLOWCTRL_10G }; enum CLKINDEX { RUN_CLK, ADC_CLK, DBIT_CLK, NUM_CLOCKS }; #define CLK_NAMES "run", "adc", "dbit" @@ -77,6 +86,7 @@ enum CLKINDEX { RUN_CLK, ADC_CLK, DBIT_CLK, NUM_CLOCKS }; #define CLK_SYNC (20) // MHz #define ADC_CLK_INDEX (1) #define DBIT_CLK_INDEX (0) +#define CONFIG_FILE ("config_jungfrau.txt") /** Default Parameters */ #define DEFAULT_NUM_FRAMES (100 * 1000 * 1000) @@ -87,24 +97,33 @@ enum CLKINDEX { RUN_CLK, ADC_CLK, DBIT_CLK, NUM_CLOCKS }; #define DEFAULT_DELAY (0) #define DEFAULT_HIGH_VOLTAGE (0) #define DEFAULT_TIMING_MODE (AUTO_TIMING) -#define DEFAULT_SETTINGS (DYNAMICGAIN) +#define DEFAULT_SETTINGS (GAIN0) +#define DEFAULT_GAINMODE (DYNAMIC) #define DEFAULT_TX_UDP_PORT (0x7e9a) #define DEFAULT_TMP_THRSHLD (65 * 1000) // milli degree Celsius #define DEFAULT_NUM_STRG_CLLS (0) #define DEFAULT_STRG_CLL_STRT (0xf) +#define DEFAULT_STRG_CLL_STRT_CHIP11 (0x3) #define DEFAULT_STRG_CLL_DLY (0) +#define DEFAULT_FLIP_ROWS (0) +#define DEFAULT_FILTER_RESISTOR (1) // higher resistor +#define DEFAULT_FILTER_CELL (0) #define HIGHVOLTAGE_MIN (60) #define HIGHVOLTAGE_MAX (200) #define DAC_MIN_MV (0) #define DAC_MAX_MV (2500) - +#define MAX_FILTER_CELL_VAL (12) + /* Defines in the Firmware */ #define MAX_TIMESLOT_VAL (0x1F) #define MAX_THRESHOLD_TEMP_VAL (127999) // millidegrees #define MAX_STORAGE_CELL_VAL (15) // 0xF +#define MAX_STORAGE_CELL_CHIP11_VAL (3) #define MAX_STORAGE_CELL_DLY_NS_VAL (ASIC_CTRL_EXPSRE_TMR_MAX_VAL) #define ACQ_TIME_MIN_CLOCK (2) +#define ASIC_FILTER_MAX_RES_VALUE (1) +#define MAX_SELECT_CHIP10_VAL (63) #define MAX_PHASE_SHIFTS (240) #define BIT16_MASK (0xFFFF) diff --git a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer index 2e9455217..c20b7c328 100755 Binary files a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer and b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer differ diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index 849e6b62c..6a24aaa2a 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -61,6 +61,7 @@ uint8_t adcEnableMask_10g = 0; int32_t clkPhase[NUM_CLOCKS] = {}; uint32_t clkFrequency[NUM_CLOCKS] = {40, 20, 20, 200}; int dacValues[NDAC] = {}; +int defaultDacValues[NDAC] = DEFAULT_DAC_VALS; // software limit that depends on the current chip on the ctb int vLimit = 0; enum detectorSettings thisSettings = UNINITIALIZED; @@ -516,7 +517,7 @@ void setupDetector() { DAC_MAX_MV); // has to be before setvchip LTC2620_Disable(); LTC2620_Configure(); - setDefaultDacs(); + resetToDefaultDacs(0); // altera pll ALTERA_PLL_SetDefines(PLL_CNTRL_REG, PLL_PARAM_REG, @@ -613,20 +614,51 @@ void updateDataBytes() { dataBytes = analogDataBytes; } -int setDefaultDacs() { +int resetToDefaultDacs(int hardReset) { + // reset defaults to hardcoded defaults + if (hardReset) { + const int vals[] = DEFAULT_DAC_VALS; + for (int i = 0; i < NDAC; ++i) { + defaultDacValues[i] = vals[i]; + } + } + // reset dacs to defaults int ret = OK; LOG(logINFOBLUE, ("Setting Default Dac values\n")); - const int defaultvals[NDAC] = DEFAULT_DAC_VALS; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultvals[i], 0); - if (dacValues[i] != defaultvals[i]) { + setDAC((enum DACINDEX)i, defaultDacValues[i], 0); + if (dacValues[i] != defaultDacValues[i]) { ret = FAIL; LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultvals[i], dacValues[i])); + defaultDacValues[i], dacValues[i])); } } return ret; } +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + if (sett != UNDEFINED) { + return FAIL; + } + if (index < 0 || index >= NDAC) + return FAIL; + + char *dac_names[] = {DAC_NAMES}; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; +} /* firmware functions (resets) */ diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index 3b3057a24..c1b23dcc9 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 3da8bda2f..f0ae19d82 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -42,11 +42,15 @@ pthread_t pthread_virtual_tid; int64_t virtual_currentFrameNumber = 2; #endif -enum detectorSettings thisSettings; +enum detectorSettings thisSettings = UNINITIALIZED; sls_detector_module *detectorModules = NULL; int *detectorChans = NULL; int *detectorDacs = NULL; int *channelMask = NULL; +int defaultDacValues[NDAC] = DEFAULT_DAC_VALS; +int defaultDacValue_standard[] = SPECIAL_DEFAULT_STANDARD_DAC_VALS; +int defaultDacValue_fast[] = SPECIAL_DEFAULT_FAST_DAC_VALS; +int defaultDacValue_highgain[] = SPECIAL_DEFAULT_HIGHGAIN_DAC_VALS; int32_t clkPhase[NUM_CLOCKS] = {}; uint32_t clkDivider[NUM_CLOCKS] = {}; @@ -446,7 +450,7 @@ void setupDetector() { // defaults setHighVoltage(DEFAULT_HIGH_VOLTAGE); - setDefaultDacs(); + resetToDefaultDacs(0); setASICDefaults(); setADIFDefaults(); @@ -523,21 +527,147 @@ void setupDetector() { setAllTrimbits(DEFAULT_TRIMBIT_VALUE); } -int setDefaultDacs() { - int ret = OK; - LOG(logINFOBLUE, ("Setting Default Dac values\n")); - { - const int defaultvals[NDAC] = DEFAULT_DAC_VALS; +int resetToDefaultDacs(int hardReset) { + LOG(logINFOBLUE, ("Resetting %s to Default Dac values\n", + (hardReset == 1 ? "hard" : ""))); + + // reset defaults to hardcoded defaults + if (hardReset) { + const int vals[] = DEFAULT_DAC_VALS; for (int i = 0; i < NDAC; ++i) { - setDAC((enum DACINDEX)i, defaultvals[i], 0); - if (detectorDacs[i] != defaultvals[i]) { - ret = FAIL; - LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, - defaultvals[i], detectorDacs[i])); + defaultDacValues[i] = vals[i]; + } + const int vals_standard[] = SPECIAL_DEFAULT_STANDARD_DAC_VALS; + for (int i = 0; i < NSPECIALDACS; ++i) { + defaultDacValue_standard[i] = vals_standard[i]; + } + const int vals_fast[] = SPECIAL_DEFAULT_FAST_DAC_VALS; + for (int i = 0; i < NSPECIALDACS; ++i) { + defaultDacValue_fast[i] = vals_fast[i]; + } + const int vals_highgain[] = SPECIAL_DEFAULT_HIGHGAIN_DAC_VALS; + for (int i = 0; i < NSPECIALDACS; ++i) { + defaultDacValue_highgain[i] = vals_highgain[i]; + } + } + + // remember settings + enum detectorSettings oldSettings = thisSettings; + + // reset dacs to defaults + const int specialDacs[] = SPECIALDACINDEX; + for (int i = 0; i < NDAC; ++i) { + int value = defaultDacValues[i]; + + for (int j = 0; j < NSPECIALDACS; ++j) { + // special dac: replace default value + if (specialDacs[j] == i) { + switch (oldSettings) { + case STANDARD: + value = defaultDacValue_standard[j]; + break; + case FAST: + value = defaultDacValue_fast[j]; + break; + case HIGHGAIN: + value = defaultDacValue_highgain[j]; + break; + default: + break; + } + break; } } + + // set to defualt + setDAC((enum DACINDEX)i, value, 0); + if (detectorDacs[i] != value) { + LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, + value, detectorDacs[i])); + return FAIL; + } } - return ret; + return OK; +} + +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, + int *retval) { + + // settings only for special dacs + if (sett != UNDEFINED) { + const int specialDacs[] = SPECIALDACINDEX; + // find special dac index + for (int i = 0; i < NSPECIALDACS; ++i) { + if ((int)index == specialDacs[i]) { + switch (sett) { + case STANDARD: + *retval = defaultDacValue_standard[i]; + return OK; + case FAST: + *retval = defaultDacValue_fast[i]; + return OK; + case HIGHGAIN: + *retval = defaultDacValue_highgain[i]; + return OK; + // unknown settings + default: + return FAIL; + } + } + } + // not a special dac + return FAIL; + } + + if (index < 0 || index >= NDAC) + return FAIL; + *retval = defaultDacValues[index]; + return OK; +} + +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { + char *dac_names[] = {DAC_NAMES}; + + // settings only for special dacs + if (sett != UNDEFINED) { + const int specialDacs[] = SPECIALDACINDEX; + // find special dac index + for (int i = 0; i < NSPECIALDACS; ++i) { + if ((int)index == specialDacs[i]) { + switch (sett) { + case STANDARD: + LOG(logINFO, + ("Setting Default Dac [%d - %s, standard]: %d\n", + (int)index, dac_names[index], value)); + defaultDacValue_standard[i] = value; + return OK; + case FAST: + LOG(logINFO, ("Setting Default Dac [%d - %s, fast]: %d\n", + (int)index, dac_names[index], value)); + defaultDacValue_fast[i] = value; + return OK; + case HIGHGAIN: + LOG(logINFO, + ("Setting Default Dac [%d - %s, highgain]: %d\n", + (int)index, dac_names[index], value)); + defaultDacValue_highgain[i] = value; + return OK; + // unknown settings + default: + return FAIL; + } + } + } + // not a special dac + return FAIL; + } + + if (index < 0 || index >= NDAC) + return FAIL; + LOG(logINFO, ("Setting Default Dac [%d - %s]: %d\n", (int)index, + dac_names[index], value)); + defaultDacValues[index] = value; + return OK; } void setASICDefaults() { @@ -1201,24 +1331,19 @@ int getAllTrimbits() { } enum detectorSettings setSettings(enum detectorSettings sett) { + int *dacVals = NULL; switch (sett) { case STANDARD: LOG(logINFOBLUE, ("Setting to standard settings\n")); - thisSettings = sett; - setDAC(M_VRPREAMP, DEFAULT_STANDARD_VRPREAMP, 0); - setDAC(M_VRSHAPER, DEFAULT_STANDARD_VRSHAPER, 0); + dacVals = defaultDacValue_standard; break; case FAST: LOG(logINFOBLUE, ("Setting to fast settings\n")); - thisSettings = sett; - setDAC(M_VRPREAMP, DEFAULT_FAST_VRPREAMP, 0); - setDAC(M_VRSHAPER, DEFAULT_FAST_VRSHAPER, 0); + dacVals = defaultDacValue_fast; break; case HIGHGAIN: LOG(logINFOBLUE, ("Setting to high gain settings\n")); - thisSettings = sett; - setDAC(M_VRPREAMP, DEFAULT_HIGHGAIN_VRPREAMP, 0); - setDAC(M_VRSHAPER, DEFAULT_HIGHGAIN_VRSHAPER, 0); + dacVals = defaultDacValue_highgain; break; default: LOG(logERROR, @@ -1226,34 +1351,54 @@ enum detectorSettings setSettings(enum detectorSettings sett) { return thisSettings; } + thisSettings = sett; + + // set special dacs + const int specialDacs[] = SPECIALDACINDEX; + for (int i = 0; i < NSPECIALDACS; ++i) { + setDAC(specialDacs[i], dacVals[i], 0); + } + LOG(logINFO, ("Settings: %d\n", thisSettings)); return thisSettings; } void validateSettings() { - if (detectorDacs[M_VRPREAMP] == DEFAULT_STANDARD_VRPREAMP && - detectorDacs[M_VRSHAPER] == DEFAULT_STANDARD_VRSHAPER) { - if (thisSettings != STANDARD) { - thisSettings = STANDARD; - LOG(logINFOBLUE, ("Validated Settings changed to standard!\n")); + // if any special dac value is changed individually => undefined + const int specialDacs[NSPECIALDACS] = SPECIALDACINDEX; + int *specialDacValues[] = {defaultDacValue_standard, defaultDacValue_fast, + defaultDacValue_highgain}; + int settList[] = {STANDARD, FAST, HIGHGAIN}; + + enum detectorSettings sett = UNDEFINED; + for (int isett = 0; isett != NUMSETTINGS; ++isett) { + + // assume it matches current setting in list + sett = settList[isett]; + // if one value does not match, = undefined + for (int i = 0; i < NSPECIALDACS; ++i) { + if (getDAC(specialDacs[i], 0) != specialDacValues[isett][i]) { + sett = UNDEFINED; + break; + } } - } else if (detectorDacs[M_VRPREAMP] == DEFAULT_FAST_VRPREAMP && - detectorDacs[M_VRSHAPER] == DEFAULT_FAST_VRSHAPER) { - if (thisSettings != FAST) { - thisSettings = FAST; - LOG(logINFOBLUE, ("Validated Settings changed to fast!\n")); + + // all values matchd a setting + if (sett != UNDEFINED) { + break; } - } else if (detectorDacs[M_VRPREAMP] == DEFAULT_HIGHGAIN_VRPREAMP && - detectorDacs[M_VRSHAPER] == DEFAULT_HIGHGAIN_VRSHAPER) { - if (thisSettings != HIGHGAIN) { - thisSettings = HIGHGAIN; - LOG(logINFOBLUE, ("Validated Settings changed to highgain!\n")); - } - } else { - thisSettings = UNDEFINED; - LOG(logWARNING, - ("Settings set to undefined [vrpreamp: %d, vrshaper: %d]\n", - detectorDacs[M_VRPREAMP], detectorDacs[M_VRSHAPER])); + } + // update settings + if (thisSettings != sett) { + LOG(logINFOBLUE, + ("Validated settings to %s (%d)\n", + (sett == STANDARD + ? "standard" + : (sett == FAST + ? "fast" + : (sett == HIGHGAIN ? "highgain" : "undefined"))), + sett)); + thisSettings = sett; } } @@ -1335,8 +1480,11 @@ void setGeneralDAC(enum DACINDEX ind, int val, int mV) { detectorDacs[ind] = dacval; } #endif - if (ind == M_VRPREAMP || ind == M_VRSHAPER) { - validateSettings(); + const int specialDacs[NSPECIALDACS] = SPECIALDACINDEX; + for (int i = 0; i < NSPECIALDACS; ++i) { + if ((int)ind == specialDacs[i]) { + validateSettings(); + } } } @@ -2425,6 +2573,7 @@ int setChipStatusRegister(int csr) { } int setGainCaps(int caps) { + LOG(logINFO, ("Setting gain caps to: %u\n", caps)); // Update only gain caps, leave the rest of the CSR unchanged int csr = getChipStatusRegister(); csr &= ~GAIN_MASK; diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h index 35f53caef..8efa6ead6 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h @@ -42,13 +42,6 @@ #define DEFAULT_TRIMBIT_VALUE (0) #define DEFAULT_COUNTER_DISABLED_VTH_VAL (2800) -#define DEFAULT_STANDARD_VRPREAMP (1100) -#define DEFAULT_FAST_VRPREAMP (300) -#define DEFAULT_HIGHGAIN_VRPREAMP (1300) -#define DEFAULT_STANDARD_VRSHAPER (1280) -#define DEFAULT_FAST_VRSHAPER (1500) -#define DEFAULT_HIGHGAIN_VRSHAPER (1100) - #define DEFAULT_READOUT_C0 (10) //(100000000) // rdo_clk, 100 MHz #define DEFAULT_READOUT_C1 (10) //(100000000) // smp sample clk (x2), 100 MHz #define DEFAULT_SYSTEM_C0 (10) //(100000000) // run_clk, 100 MHz @@ -118,6 +111,17 @@ enum DACINDEX { 2800, /* vTrim */ \ 800 /* VdcSh */ \ }; + +#define NUMSETTINGS (3) +#define NSPECIALDACS (2) +#define SPECIALDACINDEX {M_VRPREAMP, M_VRSHAPER}; +#define SPECIAL_DEFAULT_STANDARD_DAC_VALS \ + { 1100, 1280 } +#define SPECIAL_DEFAULT_FAST_DAC_VALS \ + { 300, 1500 } +#define SPECIAL_DEFAULT_HIGHGAIN_DAC_VALS \ + { 1300, 1100 } + enum CLKINDEX { READOUT_C0, READOUT_C1, diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 6287ce675..01f217b48 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -87,6 +87,7 @@ u_int16_t getHardwareSerialNumber(); #endif #ifdef JUNGFRAUD int isHardwareVersion2(); +int getChipVersion(); #endif #if defined(EIGERD) || defined(MYTHEN3D) void readDetectorNumber(); @@ -116,13 +117,15 @@ void updateDataBytes(); #endif #ifndef CHIPTESTBOARDD -int setDefaultDacs(); +int resetToDefaultDacs(int hardReset); +int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, int *retval); +int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value); #endif #ifdef MYTHEN3D void setASICDefaults(); void setADIFDefaults(); #endif -#if defined(GOTTHARD2D) || defined(EIGERD) +#if defined(GOTTHARD2D) || defined(EIGERD) || defined(JUNGFRAUD) int readConfigFile(); #endif #ifdef EIGERD @@ -199,6 +202,7 @@ int getReadoutMode(); // parameters - timer #ifdef JUNGFRAUD int selectStoragecellStart(int pos); +int getMaxStoragecellStart(); #endif #if defined(JUNGFRAUD) || defined(EIGERD) int setNextFrameNumber(uint64_t value); @@ -293,10 +297,11 @@ int getAllTrimbits(); #ifndef CHIPTESTBOARDD enum detectorSettings setSettings(enum detectorSettings sett); #endif -#ifdef MYTHEN3D -void validateSettings(); -#endif enum detectorSettings getSettings(); +#ifdef JUNGFRAUD +enum gainMode getGainMode(); +void setGainMode(enum gainMode mode); +#endif // parameters - threshold #ifdef EIGERD @@ -439,7 +444,11 @@ void setDigitalIODelay(uint64_t pinMask, int delay); #ifdef JUNGFRAUD void initReadoutConfiguration(); 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); @@ -451,6 +460,18 @@ int setThresholdTemperature(int val); int setTemperatureControl(int val); int setTemperatureEvent(int val); void alignDeserializer(); +int getFlipRows(); +void setFlipRows(int arg); +int setFilterResistor(int value); +int getFilterResistor(); +int getFilterCell(); +void setFilterCell(int iCell); +void disableCurrentSource(); +void enableCurrentSource(int fix, uint64_t select, int normal); +int getCurrentSource(); +int getFixCurrentSource(); +int getNormalCurrentSource(); +uint64_t getSelectCurrentSource(); // eiger specific - iodelay, pulse, rate, temp, activate, delay nw parameter #elif EIGERD @@ -522,8 +543,8 @@ int configureASICGlobalSettings(); enum burstMode getBurstMode(); int setCDSGain(int enable); int getCDSGain(); -int setFilter(int value); -int getFilter(); +int setFilterResistor(int value); +int getFilterResistor(); void setCurrentSource(int value); int getCurrentSource(); void setTimingSource(enum timingSourceType value); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index f9c86e9c1..040b64f18 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -40,6 +40,7 @@ int get_adc(int); int write_register(int); int read_register(int); int set_module(int); +void validate_settings(enum detectorSettings sett); int set_settings(int); int get_threshold_energy(int); int acquire(int blocking, int file_des); @@ -228,8 +229,8 @@ int set_scan(int); int get_scan_error_message(int); int get_cds_gain(int); int set_cds_gain(int); -int get_filter(int); -int set_filter(int); +int get_filter_resistor(int); +int set_filter_resistor(int); int get_adc_config(int); int set_adc_config(int); int get_bad_channels(int); @@ -238,7 +239,7 @@ int reconfigure_udp(int); int validate_udp_configuration(int); int get_bursts_left(int); int start_readout(int); -int set_default_dacs(int); +int reset_to_default_dacs(int); int is_virtual(int); int get_pattern(int); int load_default_pattern(int); @@ -253,3 +254,14 @@ int get_veto_stream(int); int set_veto_stream(int); int get_veto_algorithm(int); int set_veto_algorithm(int); +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); +int get_comp_disable_time(int); +int set_comp_disable_time(int); +int get_flip_rows(int); +int set_flip_rows(int); +int get_filter_cell(int); +int set_filter_cell(int); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 37716ca85..b104607cb 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -354,8 +354,8 @@ void function_table() { flist[F_GET_SCAN_ERROR_MESSAGE] = &get_scan_error_message; flist[F_GET_CDS_GAIN] = &get_cds_gain; flist[F_SET_CDS_GAIN] = &set_cds_gain; - flist[F_GET_FILTER] = &get_filter; - flist[F_SET_FILTER] = &set_filter; + flist[F_GET_FILTER_RESISTOR] = &get_filter_resistor; + flist[F_SET_FILTER_RESISTOR] = &set_filter_resistor; flist[F_GET_ADC_CONFIGURATION] = &get_adc_config; flist[F_SET_ADC_CONFIGURATION] = &set_adc_config; flist[F_GET_BAD_CHANNELS] = &get_bad_channels; @@ -364,7 +364,7 @@ void function_table() { flist[F_VALIDATE_UDP_CONFIG] = &validate_udp_configuration; flist[F_GET_BURSTS_LEFT] = &get_bursts_left; flist[F_START_READOUT] = &start_readout; - flist[F_SET_DEFAULT_DACS] = &set_default_dacs; + flist[F_RESET_TO_DEFAULT_DACS] = &reset_to_default_dacs; flist[F_IS_VIRTUAL] = &is_virtual; flist[F_GET_PATTERN] = &get_pattern; flist[F_LOAD_DEFAULT_PATTERN] = &load_default_pattern; @@ -379,6 +379,17 @@ void function_table() { flist[F_SET_VETO_STREAM] = &set_veto_stream; flist[F_GET_VETO_ALGORITHM] = &get_veto_algorithm; flist[F_SET_VETO_ALGORITHM] = &set_veto_algorithm; + flist[F_GET_CHIP_VERSION] = &get_chip_version; + flist[F_GET_DEFAULT_DAC] = &get_default_dac; + 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; + flist[F_GET_FLIP_ROWS] = &get_flip_rows; + flist[F_SET_FLIP_ROWS] = &set_flip_rows; + flist[F_GET_FILTER_CELL] = &get_filter_cell; + flist[F_SET_FILTER_CELL] = &set_filter_cell; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -748,8 +759,6 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { case IB_TESTC: serverDacIndex = G_IB_TESTC; break; - case HIGH_VOLTAGE: - break; #elif EIGERD case VTHRESHOLD: serverDacIndex = E_VTHRESHOLD; @@ -802,13 +811,7 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { case VISHAPER: serverDacIndex = E_VISHAPER; break; - case HIGH_VOLTAGE: - case IO_DELAY: - break; #elif CHIPTESTBOARDD - case ADC_VPP: - case HIGH_VOLTAGE: - break; case V_POWER_A: serverDacIndex = D_PWR_A; break; @@ -827,8 +830,6 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { case V_POWER_CHIP: serverDacIndex = D_PWR_CHIP; break; - case V_LIMIT: - break; #elif MOENCHD case VBP_COLBUF: serverDacIndex = MO_VBP_COLBUF; @@ -854,14 +855,7 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { case IBIAS_SFP: serverDacIndex = MO_IBIAS_SFP; break; - case ADC_VPP: - case HIGH_VOLTAGE: - case V_LIMIT: - break; - #elif MYTHEN3D - case HIGH_VOLTAGE: - break; case VCASSH: serverDacIndex = M_VCASSH; break; @@ -1003,239 +997,256 @@ enum DACINDEX getDACIndex(enum dacIndex ind) { int validateAndSetDac(enum dacIndex ind, int val, int mV) { int retval = -1; - enum DACINDEX serverDacIndex = getDACIndex(ind); + enum DACINDEX serverDacIndex = 0; - if (ret == OK) { - switch (ind) { - - // adc vpp -#if defined(CHIPTESTBOARDD) || defined(MOENCHD) - case ADC_VPP: - // set - if (val >= 0) { - ret = AD9257_SetVrefVoltage(val, mV); - if (ret == FAIL) { - sprintf(mess, "Could not set Adc Vpp. Please set a " - "proper value\n"); - LOG(logERROR, (mess)); - } - } - retval = AD9257_GetVrefVoltage(mV); - LOG(logDEBUG1, - ("Adc Vpp retval: %d %s\n", retval, (mV ? "mV" : "mode"))); - // cannot validate (its just a variable and mv gives different - // value) - break; -#endif - - // io delay + // valid enums + switch (ind) { + case HIGH_VOLTAGE: #ifdef EIGERD - case IO_DELAY: - retval = setIODelay(val); - LOG(logDEBUG1, ("IODelay: %d\n", retval)); - validate(&ret, mess, val, retval, "set iodelay", DEC); - break; + case IO_DELAY: +#elif CHIPTESTBOARDD + case ADC_VPP: + case V_LIMIT: +#elif MOENCHD + case ADC_VPP: + case V_LIMIT: +#endif + break; + default: + serverDacIndex = getDACIndex(ind); + break; + } + if (ret == FAIL) { + return retval; + } + switch (ind) { + // adc vpp +#if defined(CHIPTESTBOARDD) || defined(MOENCHD) + case ADC_VPP: + // set + if (val >= 0) { + ret = AD9257_SetVrefVoltage(val, mV); + if (ret == FAIL) { + sprintf(mess, "Could not set Adc Vpp. Please set a " + "proper value\n"); + LOG(logERROR, (mess)); + } + } + retval = AD9257_GetVrefVoltage(mV); + LOG(logDEBUG1, + ("Adc Vpp retval: %d %s\n", retval, (mV ? "mV" : "mode"))); + // cannot validate (its just a variable and mv gives different + // value) + break; #endif - // high voltage - case HIGH_VOLTAGE: - retval = setHighVoltage(val); - LOG(logDEBUG1, ("High Voltage: %d\n", retval)); + // io delay +#ifdef EIGERD + case IO_DELAY: + retval = setIODelay(val); + LOG(logDEBUG1, ("IODelay: %d\n", retval)); + validate(&ret, mess, val, retval, "set iodelay", DEC); + break; +#endif + + // high voltage + case HIGH_VOLTAGE: + retval = setHighVoltage(val); + LOG(logDEBUG1, ("High Voltage: %d\n", retval)); #if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) || \ - defined(GOTTHARD2D) || defined(MYTHEN3D) - validate(&ret, mess, val, retval, "set high voltage", DEC); +defined(GOTTHARD2D) || defined(MYTHEN3D) + validate(&ret, mess, val, retval, "set high voltage", DEC); #endif #ifdef GOTTHARDD - if (retval == -1) { - ret = FAIL; - strcpy(mess, "Invalid Voltage. Valid values are 0, 90, " - "110, 120, 150, 180, 200\n"); - LOG(logERROR, (mess)); - } else - validate(&ret, mess, val, retval, "set high voltage", DEC); + if (retval == -1) { + ret = FAIL; + strcpy(mess, "Invalid Voltage. Valid values are 0, 90, " + "110, 120, 150, 180, 200\n"); + LOG(logERROR, (mess)); + } else + validate(&ret, mess, val, retval, "set high voltage", DEC); #elif EIGERD - if ((retval != SLAVE_HIGH_VOLTAGE_READ_VAL) && (retval < 0)) { - ret = FAIL; - if (retval == -1) - sprintf(mess, - "Setting high voltage failed. Bad value %d. " - "The range is from 0 to 200 V.\n", - val); - else if (retval == -2) - strcpy(mess, "Setting high voltage failed. " - "Serial/i2c communication failed.\n"); - else if (retval == -3) - strcpy(mess, "Getting high voltage failed. " - "Serial/i2c communication failed.\n"); - LOG(logERROR, (mess)); - } + if ((retval != SLAVE_HIGH_VOLTAGE_READ_VAL) && (retval < 0)) { + ret = FAIL; + if (retval == -1) + sprintf(mess, + "Setting high voltage failed. Bad value %d. " + "The range is from 0 to 200 V.\n", + val); + else if (retval == -2) + strcpy(mess, "Setting high voltage failed. " + "Serial/i2c communication failed.\n"); + else if (retval == -3) + strcpy(mess, "Getting high voltage failed. " + "Serial/i2c communication failed.\n"); + LOG(logERROR, (mess)); + } #endif - break; + break; - // power, vlimit + // power, vlimit #ifdef CHIPTESTBOARDD - case V_POWER_A: - case V_POWER_B: - case V_POWER_C: - case V_POWER_D: - case V_POWER_IO: - if (val != GET_FLAG) { - if (!mV) { - ret = FAIL; - sprintf(mess, - "Could not set power. Power regulator %d " - "should be in mV and not dac units.\n", - ind); - LOG(logERROR, (mess)); - } else if (checkVLimitCompliant(val) == FAIL) { - ret = FAIL; - sprintf(mess, - "Could not set power. Power regulator %d " - "exceeds voltage limit %d.\n", - ind, getVLimit()); - LOG(logERROR, (mess)); - } else if (!isPowerValid(serverDacIndex, val)) { - ret = FAIL; - sprintf(mess, - "Could not set power. Power regulator %d " - "should be between %d and %d mV\n", - ind, - (serverDacIndex == D_PWR_IO ? VIO_MIN_MV - : POWER_RGLTR_MIN), - (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT)); - LOG(logERROR, (mess)); - } else { - setPower(serverDacIndex, val); - } - } - retval = getPower(serverDacIndex); - LOG(logDEBUG1, ("Power regulator(%d): %d\n", ind, retval)); - validate(&ret, mess, val, retval, "set power regulator", DEC); - break; - - case V_POWER_CHIP: - if (val >= 0) { - ret = FAIL; - sprintf(mess, "Can not set Vchip. Can only be set " - "automatically in the background (+200mV " - "from highest power regulator voltage).\n"); - LOG(logERROR, (mess)); - /* restrict users from setting vchip - if (!mV) { - ret = FAIL; - sprintf(mess,"Could not set Vchip. Should be in mV and - not dac units.\n"); LOG(logERROR,(mess)); } else if - (!isVchipValid(val)) { ret = FAIL; sprintf(mess,"Could not - set Vchip. Should be between %d and %d mV\n", VCHIP_MIN_MV, - VCHIP_MAX_MV); LOG(logERROR,(mess)); } else { setVchip(val); - } - */ - } - retval = getVchip(); - LOG(logDEBUG1, ("Vchip: %d\n", retval)); - if (ret == OK && val != GET_FLAG && val != -100 && retval != val) { - ret = FAIL; - sprintf(mess, "Could not set vchip. Set %d, but read %d\n", val, - retval); - LOG(logERROR, (mess)); - } - break; -#endif - -#if defined(CHIPTESTBOARDD) || defined(MOENCHD) - case V_LIMIT: - if (val >= 0) { - if (!mV) { - ret = FAIL; - strcpy(mess, "Could not set power. VLimit should be in " - "mV and not dac units.\n"); - LOG(logERROR, (mess)); - } else { - setVLimit(val); - } - } - retval = getVLimit(); - LOG(logDEBUG1, ("VLimit: %d\n", retval)); - validate(&ret, mess, val, retval, "set vlimit", DEC); - break; -#endif - // dacs - default: - if (mV && val > DAC_MAX_MV) { + case V_POWER_A: + case V_POWER_B: + case V_POWER_C: + case V_POWER_D: + case V_POWER_IO: + if (val != GET_FLAG) { + if (!mV) { ret = FAIL; sprintf(mess, - "Could not set dac %d to value %d. Allowed limits " - "(0 - %d mV).\n", - ind, val, DAC_MAX_MV); + "Could not set power. Power regulator %d " + "should be in mV and not dac units.\n", + ind); LOG(logERROR, (mess)); - } else if (!mV && val > getMaxDacSteps()) { + } else if (checkVLimitCompliant(val) == FAIL) { ret = FAIL; sprintf(mess, - "Could not set dac %d to value %d. Allowed limits " - "(0 - %d dac units).\n", - ind, val, getMaxDacSteps()); + "Could not set power. Power regulator %d " + "exceeds voltage limit %d.\n", + ind, getVLimit()); + LOG(logERROR, (mess)); + } else if (!isPowerValid(serverDacIndex, val)) { + ret = FAIL; + sprintf(mess, + "Could not set power. Power regulator %d " + "should be between %d and %d mV\n", + ind, + (serverDacIndex == D_PWR_IO ? VIO_MIN_MV + : POWER_RGLTR_MIN), + (VCHIP_MAX_MV - VCHIP_POWER_INCRMNT)); LOG(logERROR, (mess)); } else { -#if defined(CHIPTESTBOARDD) || defined(MOENCHD) - if ((val != GET_FLAG && mV && - checkVLimitCompliant(val) == FAIL) || - (val != GET_FLAG && !mV && - checkVLimitDacCompliant(val) == FAIL)) { - ret = FAIL; - sprintf(mess, - "Could not set dac %d to value %d. " - "Exceeds voltage limit %d.\n", - ind, (mV ? val : dacToVoltage(val)), getVLimit()); - LOG(logERROR, (mess)); - } else -#endif - setDAC(serverDacIndex, val, mV); - retval = getDAC(serverDacIndex, mV); + setPower(serverDacIndex, val); } -#ifdef EIGERD - if (val != GET_FLAG && getSettings() != UNDEFINED) { - // changing dac changes settings to undefined - switch (serverDacIndex) { - case E_VCMP_LL: - case E_VCMP_LR: - case E_VCMP_RL: - case E_VCMP_RR: - case E_VRPREAMP: - case E_VCP: - setSettings(UNDEFINED); - LOG(logERROR, ("Settings has been changed " - "to undefined (changed specific dacs)\n")); - break; - default: - break; - } - } -#endif - // check - if (ret == OK) { - if ((abs(retval - val) <= 5) || val == GET_FLAG) { - ret = OK; - } else { - ret = FAIL; - sprintf(mess, "Setting dac %d : wrote %d but read %d\n", - serverDacIndex, val, retval); - LOG(logERROR, (mess)); - } - } - LOG(logDEBUG1, ("Dac (%d): %d %s\n\n", serverDacIndex, retval, - (mV ? "mV" : "dac units"))); -#ifdef MYTHEN3D - // changed for setsettings (direct), - // custom trimbit file (setmodule with myMod.reg as -1), - // change of dac (direct) - if (val != GET_FLAG && ret == OK) { - for (int i = 0; i < NCOUNTERS; ++i) { - setThresholdEnergy(i, -1); - } - } -#endif - break; } + retval = getPower(serverDacIndex); + LOG(logDEBUG1, ("Power regulator(%d): %d\n", ind, retval)); + validate(&ret, mess, val, retval, "set power regulator", DEC); + break; + + case V_POWER_CHIP: + if (val >= 0) { + ret = FAIL; + sprintf(mess, "Can not set Vchip. Can only be set " + "automatically in the background (+200mV " + "from highest power regulator voltage).\n"); + LOG(logERROR, (mess)); + /* restrict users from setting vchip + if (!mV) { + ret = FAIL; + sprintf(mess,"Could not set Vchip. Should be in mV and + not dac units.\n"); LOG(logERROR,(mess)); } else if + (!isVchipValid(val)) { ret = FAIL; sprintf(mess,"Could not + set Vchip. Should be between %d and %d mV\n", VCHIP_MIN_MV, + VCHIP_MAX_MV); LOG(logERROR,(mess)); } else { setVchip(val); + } + */ + } + retval = getVchip(); + LOG(logDEBUG1, ("Vchip: %d\n", retval)); + if (ret == OK && val != GET_FLAG && val != -100 && retval != val) { + ret = FAIL; + sprintf(mess, "Could not set vchip. Set %d, but read %d\n", val, + retval); + LOG(logERROR, (mess)); + } + break; +#endif + +#if defined(CHIPTESTBOARDD) || defined(MOENCHD) + case V_LIMIT: + if (val >= 0) { + if (!mV) { + ret = FAIL; + strcpy(mess, "Could not set power. VLimit should be in " + "mV and not dac units.\n"); + LOG(logERROR, (mess)); + } else { + setVLimit(val); + } + } + retval = getVLimit(); + LOG(logDEBUG1, ("VLimit: %d\n", retval)); + validate(&ret, mess, val, retval, "set vlimit", DEC); + break; +#endif + // dacs + default: + if (mV && val > DAC_MAX_MV) { + ret = FAIL; + sprintf(mess, + "Could not set dac %d to value %d. Allowed limits " + "(0 - %d mV).\n", + ind, val, DAC_MAX_MV); + LOG(logERROR, (mess)); + } else if (!mV && val > getMaxDacSteps()) { + ret = FAIL; + sprintf(mess, + "Could not set dac %d to value %d. Allowed limits " + "(0 - %d dac units).\n", + ind, val, getMaxDacSteps()); + LOG(logERROR, (mess)); + } else { +#if defined(CHIPTESTBOARDD) || defined(MOENCHD) + if ((val != GET_FLAG && mV && + checkVLimitCompliant(val) == FAIL) || + (val != GET_FLAG && !mV && + checkVLimitDacCompliant(val) == FAIL)) { + ret = FAIL; + sprintf(mess, + "Could not set dac %d to value %d. " + "Exceeds voltage limit %d.\n", + ind, (mV ? val : dacToVoltage(val)), getVLimit()); + LOG(logERROR, (mess)); + } else +#endif + setDAC(serverDacIndex, val, mV); + retval = getDAC(serverDacIndex, mV); + } +#ifdef EIGERD + if (val != GET_FLAG && getSettings() != UNDEFINED) { + // changing dac changes settings to undefined + switch (serverDacIndex) { + case E_VCMP_LL: + case E_VCMP_LR: + case E_VCMP_RL: + case E_VCMP_RR: + case E_VRPREAMP: + case E_VCP: + setSettings(UNDEFINED); + LOG(logERROR, ("Settings has been changed " + "to undefined (changed specific dacs)\n")); + break; + default: + break; + } + } +#endif + // check + if (ret == OK) { + if ((abs(retval - val) <= 5) || val == GET_FLAG) { + ret = OK; + } else { + ret = FAIL; + sprintf(mess, "Setting dac %d : wrote %d but read %d\n", + serverDacIndex, val, retval); + LOG(logERROR, (mess)); + } + } + LOG(logDEBUG1, ("Dac (%d): %d %s\n\n", serverDacIndex, retval, + (mV ? "mV" : "dac units"))); +#ifdef MYTHEN3D + // changed for setsettings (direct), + // custom trimbit file (setmodule with myMod.reg as -1), + // change of dac (direct) + if (val != GET_FLAG && ret == OK) { + for (int i = 0; i < NCOUNTERS; ++i) { + setThresholdEnergy(i, -1); + } + } +#endif + break; } return retval; } @@ -1530,32 +1541,12 @@ int set_module(int file_des) { else if (Server_VerifyLock() == OK) { // check index -#if !(defined(EIGERD) || defined(MYTHEN3D)) - // TODO! Check if this is used for any detector - switch (module.reg) { -#ifdef JUNGFRAUD - case DYNAMICGAIN: - case DYNAMICHG0: - case FIXGAIN1: - case FIXGAIN2: - case FORCESWITCHG1: - case FORCESWITCHG2: -#elif GOTTHARDD - case DYNAMICGAIN: - case HIGHGAIN: - case LOWGAIN: - case MEDIUMGAIN: - case VERYHIGHGAIN: -#endif - break; - default: - modeNotImplemented("Settings", (int)module.reg); - break; - } +#ifndef EIGERD + validate_settings((enum detectorSettings)(module.reg)); #endif ret = setModule(module, mess); enum detectorSettings retval = getSettings(); -#if !(defined(EIGERD) || defined(MYTHEN3D)) +#ifndef EIGERD validate(&ret, mess, module.reg, (int)retval, "set module (settings)", DEC); #endif @@ -1568,6 +1559,45 @@ int set_module(int file_des) { return Server_SendResult(file_des, INT32, NULL, 0); } +void validate_settings(enum detectorSettings sett) { + // check index + switch (sett) { +#ifdef EIGERD + case STANDARD: +#elif JUNGFRAUD + case GAIN0: + case HIGHGAIN0: +#elif GOTTHARDD + case DYNAMICGAIN: + case HIGHGAIN: + case LOWGAIN: + case MEDIUMGAIN: + case VERYHIGHGAIN: +#elif GOTTHARD2D + case DYNAMICGAIN: + case FIXGAIN1: + case FIXGAIN2: +#elif MOENCHD + case G1_HIGHGAIN: + case G1_LOWGAIN: + case G2_HIGHCAP_HIGHGAIN: + case G2_HIGHCAP_LOWGAIN: + case G2_LOWCAP_HIGHGAIN: + case G2_LOWCAP_LOWGAIN: + case G4_HIGHGAIN: + case G4_LOWGAIN: +#elif MYTHEN3D + case STANDARD: + case FAST: + case HIGHGAIN: +#endif + break; + default: + modeNotImplemented("Settings Index", (int)sett); + break; + } +} + int set_settings(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); @@ -1586,51 +1616,14 @@ int set_settings(int file_des) { if (((int)isett == GET_FLAG) || (Server_VerifyLock() == OK)) { if ((int)isett != GET_FLAG) { - // check index - switch (isett) { -#ifdef JUNGFRAUD - case DYNAMICGAIN: - case DYNAMICHG0: - case FIXGAIN1: - case FIXGAIN2: - case FORCESWITCHG1: - case FORCESWITCHG2: -#elif GOTTHARDD - case DYNAMICGAIN: - case HIGHGAIN: - case LOWGAIN: - case MEDIUMGAIN: - case VERYHIGHGAIN: -#elif GOTTHARD2D - case DYNAMICGAIN: - case FIXGAIN1: - case FIXGAIN2: -#elif MOENCHD - case G1_HIGHGAIN: - case G1_LOWGAIN: - case G2_HIGHCAP_HIGHGAIN: - case G2_HIGHCAP_LOWGAIN: - case G2_LOWCAP_HIGHGAIN: - case G2_LOWCAP_LOWGAIN: - case G4_HIGHGAIN: - case G4_LOWGAIN: -#elif MYTHEN3D - case STANDARD: - case FAST: - case HIGHGAIN: +#ifdef EIGERD + ret = FAIL; + sprintf(mess, "Cannot set settings via SET_SETTINGS, use " + "SET_MODULE\n"); + LOG(logERROR, (mess)); +#else + validate_settings(isett); #endif - break; - default: - if (myDetectorType == EIGER) { - ret = FAIL; - sprintf(mess, "Cannot set settings via SET_SETTINGS, use " - "SET_MODULE\n"); - LOG(logERROR, (mess)); - } else - modeNotImplemented("Settings Index", (int)isett); - break; - } - if (ret == OK) { setSettings(isett); } @@ -1642,7 +1635,7 @@ int set_settings(int file_des) { validate(&ret, mess, (int)isett, (int)retval, "set settings", DEC); #ifdef GOTTHARDD if (ret == OK) { - ret = setDefaultDacs(); + ret = resetToDefaultDacs(0); if (ret == FAIL) { strcpy(mess, "Could change settings, but could not set to " "default dacs\n"); @@ -1693,7 +1686,16 @@ int acquire(int blocking, int file_des) { } // only set if (Server_VerifyLock() == OK) { -#if defined(MOENCHD) +#ifdef JUNGFRAUD + // chipv1.1 has to be configured before acquisition + if (getChipVersion() == 11 && !isChipConfigured()) { + ret = FAIL; + strcpy(mess, + "Could not start acquisition. Chip is not configured.\n"); + LOG(logERROR, (mess)); + } else +#endif +#ifdef MOENCHD if (getNumAnalogSamples() <= 0) { ret = FAIL; sprintf(mess, @@ -1703,7 +1705,7 @@ int acquire(int blocking, int file_des) { LOG(logERROR, (mess)); } else #endif -#if defined(CHIPTESTBOARDD) +#ifdef CHIPTESTBOARDD if ((getReadoutMode() == ANALOG_AND_DIGITAL || getReadoutMode() == ANALOG_ONLY) && (getNumAnalogSamples() <= 0)) { @@ -2042,10 +2044,14 @@ int set_num_additional_storage_cells(int file_des) { #else // only set if (Server_VerifyLock() == OK) { - if (arg > MAX_STORAGE_CELL_VAL) { + if (getChipVersion() == 11) { + ret = FAIL; + sprintf(mess, "Cannot set addl. number of storage cells for chip v1.1\n"); + LOG(logERROR, (mess)); + } else if (arg > getMaxStoragecellStart()) { ret = FAIL; sprintf(mess, "Max Storage cell number should not exceed %d\n", - MAX_STORAGE_CELL_VAL); + getMaxStoragecellStart()); LOG(logERROR, (mess)); } else { setNumAdditionalStorageCells(arg); @@ -2489,9 +2495,15 @@ int get_storage_cell_delay(int file_des) { functionNotImplemented(); #else // get only - retval = getStorageCellDelay(); - LOG(logDEBUG1, + if (getChipVersion() == 11) { + ret = FAIL; + strcpy(mess, "Storage cell delay is not applicable for chipv 1.1\n"); + LOG(logERROR, (mess)); + } else { + retval = getStorageCellDelay(); + LOG(logDEBUG1, ("retval storage cell delay %lld ns\n", (long long int)retval)); + } #endif return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); } @@ -2511,7 +2523,11 @@ int set_storage_cell_delay(int file_des) { #else // only set if (Server_VerifyLock() == OK) { - if (arg > MAX_STORAGE_CELL_DLY_NS_VAL) { + if (getChipVersion() == 11) { + ret = FAIL; + strcpy(mess, "Storage cell delay is not applicable for chipv 1.1\n"); + LOG(logERROR, (mess)); + } else if (arg > MAX_STORAGE_CELL_DLY_NS_VAL) { ret = FAIL; sprintf(mess, "Max Storage cell delay value should not exceed %lld ns\n", @@ -4013,9 +4029,9 @@ int storage_cell_start(int file_des) { #else // set & get if ((arg == GET_FLAG) || (Server_VerifyLock() == OK)) { - if (arg > MAX_STORAGE_CELL_VAL) { + if (arg > getMaxStoragecellStart()) { ret = FAIL; - strcpy(mess, "Max Storage cell number should not exceed 15\n"); + sprintf(mess, "Max Storage cell number should not exceed %d\n", getMaxStoragecellStart()); LOG(logERROR, (mess)); } else { retval = selectStoragecellStart(arg); @@ -6737,21 +6753,104 @@ int set_burst_period(int file_des) { int set_current_source(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - int arg = 0; - - if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + uint64_t select = 0; + int args[3] = {-1, -1, -1}; + if (receiveData(file_des, args, sizeof(args), INT32) < 0) return printSocketReadError(); - LOG(logINFO, ("Setting current source enable: %u\n", arg)); + if (receiveData(file_des, &select, sizeof(select), INT64) < 0) + return printSocketReadError(); + int enable = args[0]; + int fix = args[1]; + int normal = args[2]; -#ifndef GOTTHARD2D + LOG(logINFOBLUE, ("Setting current source [enable:%d, fix:%d, select:%lld, " + "normal:%d]\n", + enable, fix, (long long int)select, normal)); + +#if !defined(GOTTHARD2D) && !defined(JUNGFRAUD) functionNotImplemented(); #else // only set if (Server_VerifyLock() == OK) { - setCurrentSource(arg); - int retval = getCurrentSource(); - LOG(logDEBUG1, ("current source enable retval: %u\n", retval)); - validate(&ret, mess, arg, retval, "set current source enable", DEC); + if (enable != 0 && enable != 1) { + ret = FAIL; + strcpy(mess, + "Could not enable/disable current source. Enable can be 0 or 1 only.\n"); + LOG(logERROR, (mess)); + } + // disable + else if (enable == 0 && (fix != -1 || normal != -1)) { + ret = FAIL; + strcpy(mess, + "Could not disable current source. Requires no parameters.\n"); + LOG(logERROR, (mess)); + } + // enable + else if (enable == 1) { +#ifdef GOTTHARD2D + // no parameters allowed + if (fix != -1 || normal != -1) { + ret = FAIL; + strcpy(mess, + "Could not enable current source. Fix and normal are invalid parameters for this detector.\n"); + LOG(logERROR, (mess)); + } +#else + int chipVersion = getChipVersion(); + if (ret == OK) { + if (chipVersion == 11) { + // require both + if ((fix != 0 && fix != 1) || + (normal != 0 && normal != 1)) { + ret = FAIL; + strcpy(mess, "Could not enable current source. Invalid " + "or insufficient parameters (fix or " + "normal). or Options: 0 or 1.\n"); + LOG(logERROR, (mess)); + } + } + // chipv1.0 + else { + // require only fix + if (fix != 0 && fix != 1) { + ret = FAIL; + strcpy(mess, + "Could not enable current source. Invalid value for parameter (fix). Options: 0 or 1.\n"); + LOG(logERROR, (mess)); + } else if (normal != -1) { + ret = FAIL; + strcpy(mess, "Could not enable current source. Invalid " + "parmaeter (normal). Require only fix and " + "select for chipv1.0.\n"); + LOG(logERROR, (mess)); + } + // select can only be 0-63 + else if (select > MAX_SELECT_CHIP10_VAL) { + ret = FAIL; + strcpy(mess, + "Could not enable current source. Invalid value " + "for parameter (select). Options: 0-63.\n"); + LOG(logERROR, (mess)); + } + } + } +#endif + } + + if (ret == OK) { +#ifdef JUNGFRAUD + if (enable == 0) { + disableCurrentSource(); + } else { + enableCurrentSource(fix, select, normal); + } +#else + setCurrentSource(enable); +#endif + int retval = getCurrentSource(); + LOG(logDEBUG1, ("current source enable retval: %u\n", retval)); + validate(&ret, mess, enable, retval, "set current source enable", DEC); + } } #endif return Server_SendResult(file_des, INT32, NULL, 0); @@ -6760,18 +6859,34 @@ int set_current_source(int file_des) { int get_current_source(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - int retval = -1; + int retvals[3] = {-1, -1, -1}; + uint64_t retval_select = 0; - LOG(logDEBUG1, ("Getting current source enable\n")); + LOG(logDEBUG1, ("Getting current source\n")); -#ifndef GOTTHARD2D +#if !defined(GOTTHARD2D) && !defined(JUNGFRAUD) functionNotImplemented(); #else // get only - retval = getCurrentSource(); - LOG(logDEBUG1, ("current source enable retval: %u\n", retval)); + retvals[0] = getCurrentSource(); + LOG(logDEBUG1, ("current source enable retval: %u\n", retvals[0])); +#ifdef JUNGFRAUD + if (retvals[0]) { + retvals[1] = getFixCurrentSource(); + retvals[2] = getNormalCurrentSource(); + retval_select = getSelectCurrentSource(); + } + LOG(logDEBUG1, ("current source parameters retval: [enable:%d fix:%d, " + "normal:%d, select:%lld]\n", + retvals[0], retvals[1], retvals[2], retval_select)); #endif - return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +#endif + Server_SendResult(file_des, INT32, NULL, 0); + if (ret != FAIL) { + sendData(file_des, retvals, sizeof(retvals), INT32); + sendData(file_des, &retval_select, sizeof(retval_select), INT64); + } + return ret; } int set_timing_source(int file_des) { @@ -7651,6 +7766,7 @@ int set_scan(int file_des) { } // dac scan else { + // validate index getDACIndex(index); if (ret == OK) { LOG(logINFOBLUE, ("Dac [%d] scan enabled\n", index)); @@ -7756,49 +7872,76 @@ int set_cds_gain(int file_des) { return Server_SendResult(file_des, INT32, NULL, 0); } -int get_filter(int file_des) { +int get_filter_resistor(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); int retval = -1; - LOG(logDEBUG1, ("Getting filter\n")); + LOG(logDEBUG1, ("Getting filter resistor\n")); -#ifndef GOTTHARD2D +#if !defined(GOTTHAR2D) && !defined(JUNGFRAUD) functionNotImplemented(); #else // get only - retval = getFilter(); - LOG(logDEBUG1, ("filter retval: %u\n", retval)); +#ifdef JUNGFRAUD + if (getChipVersion() == 10) { + ret = FAIL; + strcpy(mess, "Could not get filter cell. Not available for this chip " + "version 1.0.\n"); + LOG(logERROR, (mess)); + } +#endif + if (ret == OK) { + retval = getFilterResistor(); + LOG(logDEBUG1, ("filter resistor retval: %u\n", retval)); + } #endif return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); } -int set_filter(int file_des) { +int set_filter_resistor(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); int arg = 0; if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) return printSocketReadError(); - LOG(logINFO, ("Setting filter: %u\n", arg)); + LOG(logINFO, ("Setting filter resistor: %u\n", arg)); -#ifndef GOTTHARD2D +#if !defined(GOTTHAR2D) && !defined(JUNGFRAUD) functionNotImplemented(); #else // only set if (Server_VerifyLock() == OK) { - if (arg < 0 || arg > ASIC_FILTER_MAX_VALUE) { + if (arg < 0 || arg > ASIC_FILTER_MAX_RES_VALUE) { ret = FAIL; sprintf(mess, - "Could not set filter. Invalid filter %d. " + "Could not set filter resistor. Invalid filter argument %d. " "Options [0-%d]\n", - arg, ASIC_FILTER_MAX_VALUE); + arg, ASIC_FILTER_MAX_RES_VALUE); LOG(logERROR, (mess)); - } else { - setFilter(arg); - int retval = getFilter(); - LOG(logDEBUG1, ("filter retval: %u\n", retval)); - validate(&ret, mess, arg, retval, "set filter", DEC); + } +#ifdef JUNGFRAUD + else if (getChipVersion() == 10) { + ret = FAIL; + strcpy(mess, "Could not set filter cell. Not available for this " + "chip version 1.0.\n"); + LOG(logERROR, (mess)); + } +#endif + else { + ret = setFilterResistor(arg); + if (ret == FAIL) { + ret = FAIL; + strcpy(mess, "Could not set filter resistor.\n"); + LOG(logERROR, (mess)); + } +#ifndef JUNGFRAUD + // jungfrau might take time to update status register if acquiring + int retval = getFilterResistor(); + LOG(logDEBUG1, ("filter resistor retval: %u\n", retval)); + validate(&ret, mess, arg, retval, "set filter resistor", DEC); +#endif } } #endif @@ -8095,17 +8238,22 @@ int start_readout(int file_des) { return Server_SendResult(file_des, INT32, NULL, 0); } -int set_default_dacs(int file_des) { +int reset_to_default_dacs(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); + int arg = -1; + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + LOG(logDEBUG1, ("Resetting dacs to defaults (hard reset: %d)\n", arg)); #ifdef CHIPTESTBOARDD functionNotImplemented(); #else if (Server_VerifyLock() == OK) { - if (setDefaultDacs() == FAIL) { + if (resetToDefaultDacs(arg) == FAIL) { ret = FAIL; - strcpy(mess, "Could not set default dacs"); + sprintf(mess, "Could not %s reset default dacs", + (arg == 1 ? "hard" : "")); LOG(logERROR, (mess)); } } @@ -8196,7 +8344,7 @@ int set_gain_caps(int file_des) { if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) return printSocketReadError(); - LOG(logINFO, ("Setting gain caps to: %u\n", arg)); + LOG(logDEBUG1, ("Setting gain caps to: %u\n", arg)); int retval = -1; @@ -8342,7 +8490,7 @@ int set_veto_stream(int file_des) { if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) return printSocketReadError(); - LOG(logINFO, ("Setting vetostream: %u\n", (int)arg)); + LOG(logDEBUG1, ("Setting vetostream: %u\n", (int)arg)); #ifndef GOTTHARD2D functionNotImplemented(); @@ -8403,7 +8551,7 @@ int set_veto_algorithm(int file_des) { enum vetoAlgorithm alg = args[0]; enum streamingInterface interface = args[1]; - LOG(logINFO, ("Setting vetoalgorithm (interface: %d): %u\n", (int)interface, + LOG(logDEBUG1, ("Setting vetoalgorithm (interface: %d): %u\n", (int)interface, (int)alg)); #ifndef GOTTHARD2D @@ -8432,4 +8580,345 @@ int set_veto_algorithm(int file_des) { } #endif return Server_SendResult(file_des, INT32, NULL, 0); -} \ No newline at end of file +} + +int get_chip_version(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int retval = -1; +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + retval = getChipVersion(); +#endif + LOG(logDEBUG1, ("chip version retval: %d\n", retval)); + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +} + +int get_default_dac(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int args[2] = {-1, -1}; + int retval = -1; + if (receiveData(file_des, args, sizeof(args), INT32) < 0) + return printSocketReadError(); + + enum dacIndex dacindex = args[0]; + enum detectorSettings sett = args[1]; + LOG(logDEBUG1, + ("Getting default dac [dacindex:%d, settings: %d]\n", dacindex, sett)); + +#ifdef CHIPTESTBOARDD + functionNotImplemented(); +#else + // get only + enum DACINDEX idac = getDACIndex(dacindex); + if (ret == OK) { + // to allow for default dacs (without settings) + if (sett != UNDEFINED) { + validate_settings(sett); + } + if (ret == OK) { + ret = getDefaultDac(idac, sett, &retval); + if (ret == FAIL) { + sprintf(mess, "Could not get default dac %d %s\n", (int)idac, + (sett != UNDEFINED ? "for this setting" : "")); + LOG(logERROR, (mess)); + } else { + LOG(logDEBUG1, + ("default dac retval [dacindex:%d, setting:%d]: %u\n", + (int)dacindex, (int)sett, retval)); + } + } + } +#endif + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +} + +int set_default_dac(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int args[3] = {-1, -1, -1}; + if (receiveData(file_des, args, sizeof(args), INT32) < 0) + return printSocketReadError(); + + enum dacIndex dacindex = args[0]; + enum detectorSettings sett = args[1]; + int value = args[2]; + LOG(logDEBUG1, ("Setting default dac [dacindex: %d, settings: %d] to %d\n", + (int)dacindex, (int)sett, value)); + +#ifdef CHIPTESTBOARDD + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + enum DACINDEX idac = getDACIndex(dacindex); + if (ret == OK) { + // to allow for default dacs (without settings) + if (sett != UNDEFINED) { + validate_settings(sett); + } + if (ret == OK) { + ret = setDefaultDac(idac, sett, value); + if (ret == FAIL) { + sprintf(mess, "Could not set default dac %d %s\n", + (int)idac, + (sett != UNDEFINED ? "for this setting" : "")); + LOG(logERROR, (mess)); + } else { + int retval = -1; + ret = getDefaultDac(idac, sett, &retval); + if (ret == FAIL) { + sprintf(mess, "Could not get default dac %d %s\n", + (int)idac, + (sett != UNDEFINED ? "for this setting" : "")); + LOG(logERROR, (mess)); + } else { + LOG(logDEBUG1, ("default dac retval [dacindex:%d, " + "setting:%d]: %u\n", + (int)dacindex, (int)sett, retval)); + } + } + } + } + } +#endif + return Server_SendResult(file_des, INT32, NULL, 0); +} + +int get_gain_mode(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + enum gainMode retval = DYNAMIC; + LOG(logDEBUG1, ("Getting gain mode\n")); + +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // get only + retval = getGainMode(); + LOG(logDEBUG1, ("gainmode retval: %u\n", retval)); + if ((int)retval == -1) { + ret = FAIL; + strcpy(mess, "Could not get gain mode.\n"); + LOG(logERROR, (mess)); + } +#endif + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +} + +int set_gain_mode(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int arg = -1; + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + enum gainMode gainmode = arg; + LOG(logDEBUG1, ("Setting gain mode %d\n", (int)gainmode)); + +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + switch (gainmode) { + case DYNAMIC: + case FORCE_SWITCH_G1: + case FORCE_SWITCH_G2: + case FIX_G1: + case FIX_G2: + case FIX_G0: + break; + default: + modeNotImplemented("Gain Mode Index", (int)gainmode); + break; + } + + setGainMode(gainmode); + int retval = getGainMode(); + LOG(logDEBUG1, ("gainmode retval: %u\n", retval)); + if (retval == -1) { + ret = FAIL; + strcpy(mess, "Could not get gain mode.\n"); + LOG(logERROR, (mess)); + } + validate(&ret, mess, arg, retval, "set gain mode", DEC); + } +#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); +} + +int get_flip_rows(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int retval = -1; + + LOG(logDEBUG1, ("Getting flip rows\n")); + +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // get only + retval = getFlipRows(); + LOG(logDEBUG1, ("flip rows retval: %u\n", retval)); +#endif + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +} + +int set_flip_rows(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int arg = -1; + + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + LOG(logDEBUG1, ("Setting flip rows: %u\n", (int)arg)); + +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + + if (arg != 0 && arg != 1) { + ret = FAIL; + sprintf(mess, + "Could not set flip rows. Invalid argument %d.\n", + arg); + LOG(logERROR, (mess)); + } + // only for HW 2.0 (version = 3) + else if (isHardwareVersion2()) { + ret = FAIL; + strcpy(mess, "Could not set flip rows. Only available for " + "Hardware Board version 2.0.\n"); + LOG(logERROR, (mess)); + } else if (getNumberofUDPInterfaces() == 1) { + ret = FAIL; + strcpy(mess, "Could not set flip rows. Number of udp " + "interfaces is still 1.\n"); + LOG(logERROR, (mess)); + } else { + setFlipRows(arg); + int retval = getFlipRows(); + LOG(logDEBUG1, ("flip rows retval: %u\n", retval)); + validate(&ret, mess, arg, retval, "set flip rows", DEC); + } + } +#endif + return Server_SendResult(file_des, INT32, NULL, 0); +} + + +int get_filter_cell(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int retval = -1; + + LOG(logDEBUG1, ("Getting filter cell\n")); + +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // get only + retval = getFilterCell(); + LOG(logDEBUG1, ("filter cell retval: %u\n", retval)); +#endif + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +} + +int set_filter_cell(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int arg = -1; + + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + LOG(logDEBUG1, ("Setting filter cell: %u\n", (int)arg)); + +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + + if (arg < 0 || arg > MAX_FILTER_CELL_VAL) { + ret = FAIL; + sprintf(mess, + "Could not set filter cell. Invalid argument %d. Options: 0 - %d\n", + arg, MAX_FILTER_CELL_VAL); + LOG(logERROR, (mess)); + } + // only for chipv1.1 + else if (getChipVersion() == 10) { + ret = FAIL; + strcpy(mess, "Could not set filter cell. Only available for " + "chip version 1.1\n"); + LOG(logERROR, (mess)); + } else { + setFilterCell(arg); + // no validation as it might take time to update status register if acquiring + } + } +#endif + return Server_SendResult(file_des, INT32, NULL, 0); +} diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 625afa26a..19bf54a11 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -113,8 +113,7 @@ class Detector { /** [Jungfrau][Gotthard][Gotthard2][Mythen3] */ Result getSettings(Positions pos = {}) const; - /** [Jungfrau] DYNAMICGAIN, DYNAMICHG0, FIXGAIN1, FIXGAIN2, - * FORCESWITCHG1, FORCESWITCHG2 \n [Gotthard] DYNAMICGAIN, HIGHGAIN, + /** [Jungfrau] GAIN0, HIGHGAIN0 \n [Gotthard] DYNAMICGAIN, HIGHGAIN, * LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN \n [Gotthard2] DYNAMICGAIN, * FIXGAIN1, FIXGAIN2 \n [Moench] G1_HIGHGAIN, G1_LOWGAIN, * G2_HIGHCAP_HIGHGAIN, G2_HIGHCAP_LOWGAIN, G2_LOWCAP_HIGHGAIN, @@ -173,6 +172,17 @@ class Detector { */ void setGapPixelsinCallback(const bool enable); + /** [Eiger][Jungfrau] */ + Result getFlipRows(Positions pos = {}) const; + + /** [Eiger] flips rows paramater sent to slsreceiver to stream as json + * parameter to flip rows in gui \n[Jungfrau] flips rows in the detector + * itself. For bottom module and number of interfaces must be set to 2. + * slsReceiver and slsDetectorGui does not handle.slsReceiver and + * slsDetectorGui does not handle + */ + void setFlipRows(bool value, Positions pos = {}); + Result isVirtualDetectorServer(Positions pos = {}) const; ///@{ @@ -383,7 +393,7 @@ class Detector { * [Moench] Default is disabled. \n * [Jungfrau] Default is disabled. Get will return power status. Can be off * if temperature event occured (temperature over temp_threshold with - * temp_control enabled. \n [Mythen3][Gotthard2] Default is 1. If module not + * temp_control enabled. Will configure chip (only chip v1.1)\n [Mythen3][Gotthard2] Default is 1. If module not * connected or wrong module, powerchip will fail. */ void setPowerChip(bool on, Positions pos = {}); @@ -414,7 +424,24 @@ class Detector { std::vector getDacList() const; /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ - void setDefaultDacs(Positions pos = {}); + Result getDefaultDac(defs::dacIndex index, Positions pos = {}); + + /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ + void setDefaultDac(defs::dacIndex index, int defaultValue, + Positions pos = {}); + + /** [Jungfrau][Mythen3] */ + Result getDefaultDac(defs::dacIndex index, defs::detectorSettings sett, + Positions pos = {}); + + /** [Jungfrau][Mythen3] */ + void setDefaultDac(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos = {}); + + /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] + reset to defaults, hardReset will reset to hardcoded defaults on on-board + server */ + void resetToDefaultDacs(const bool hardReset, Positions pos = {}); Result getDAC(defs::dacIndex index, bool mV = false, Positions pos = {}) const; @@ -452,6 +479,23 @@ class Detector { * [Mythen3] If exposure time is too short, acquisition will return with an * ERROR and take fewer frames than expected */ void setParallelMode(bool value, Positions pos = {}); + + /** [Gotthard2][Jungfrau] */ + Result getFilterResistor(Positions pos = {}) const; + + /** [Gotthard2][Jungfrau] Set filter resistor. Increasing values for + * increasing resistance.\n[Gotthard2] Options: [0|1|2|3]. Default is + * 0.\n[Jungfrau] Options: [0|1]. Default is 1.*/ + void setFilterResistor(int value, Positions pos = {}); + + /** [Gotthard2][Jungfrau] */ + Result + getCurrentSource(Positions pos = {}) const; + + /** [Gotthard2][Jungfrau] Please refer documentation on currentSrcParameters + * (sls_detector_defs.h) on the structure and its members */ + void setCurrentSource(defs::currentSrcParameters par, Positions pos = {}); + ///@{ /** @name Acquisition */ @@ -979,12 +1023,6 @@ class Detector { /** [Eiger] Overflow in 32 bit mode. Default is disabled.*/ void setOverFlowMode(bool value, Positions pos = {}); - /** [Eiger] */ - Result getBottom(Positions pos = {}) const; - - /** [Eiger] for client call back (gui) purposes to flip bottom image */ - void setBottom(bool value, Positions pos = {}); - /** [Eiger] deadtime in ns, 0 = disabled */ Result getRateCorrection(Positions pos = {}) const; @@ -1081,6 +1119,9 @@ class Detector { * * * ************************************************/ + /** [Jungfrau] */ + Result getChipVersion(Positions pos = {}) const; + /** [Jungfrau] */ Result getThresholdTemperature(Positions pos = {}) const; @@ -1108,24 +1149,32 @@ 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; /** [Jungfrau] Advanced \n - * Options: 0 - 15. Default: 0. \n + * Only for chipv1.0. Options: 0 - 15. Default: 0. \n * The #images = #frames x #triggers x (#storagecells + 1) */ void setNumberOfAdditionalStorageCells(int value); @@ -1133,7 +1182,7 @@ class Detector { Result getStorageCellStart(Positions pos = {}) const; /** [Jungfrau] Advanced. Sets the storage cell storing the first acquisition - * of the series. Options: 0-15. Default: 15. + * of the series. Options: 0-max. max is 15 (default) for chipv1.0 and 3 (default) for chipv1.1. */ void setStorageCellStart(int cell, Positions pos = {}); @@ -1141,9 +1190,30 @@ class Detector { Result getStorageCellDelay(Positions pos = {}) const; /** [Jungfrau] Advanced \n Additional time delay between 2 consecutive - * exposures in burst mode. \n Options: (0-1638375 ns (resolution of 25ns) + * exposures in burst mode. \n Options: (0-1638375 ns (resolution of 25ns)\n + * Only applicable for chipv1.0. */ void setStorageCellDelay(ns value, Positions pos = {}); + + /** list of possible gainmode */ + std::vector getGainModeList() const; + + /** [Jungfrau]*/ + Result getGainMode(Positions pos = {}) const; + + /** [Jungfrau] Options: DYNAMIC, FORCE_SWITCH_G1, FORCE_SWITCH_G2, + * FIX_G1, FIX_G2, FIX_G0 \n\CAUTION: Do not use FIX_G0 without caution, you + * can damage the detector!!!\n + */ + void setGainMode(const defs::gainMode mode, Positions pos = {}); + + /** [Jungfrau] Advanced */ + Result getFilterCell(Positions pos = {}) const; + + /** [Jungfrau] Advanced Options[0-12] + */ + void setFilterCell(int cell, Positions pos = {}); + ///@{ /** @name Gotthard Specific */ @@ -1238,18 +1308,6 @@ class Detector { /** default disabled */ void setCDSGain(bool value, Positions pos = {}); - /** [Gotthard2] */ - Result getFilter(Positions pos = {}) const; - - /** [Gotthard2] Set filter resister. Options: 0-3. Default: 0 */ - void setFilter(int value, Positions pos = {}); - - /** [Gotthard2] */ - Result getCurrentSource(Positions pos = {}) const; - - /** default disabled */ - void setCurrentSource(bool value, Positions pos = {}); - /** [Gotthard2] */ Result getTimingSource(Positions pos = {}) const; @@ -1776,7 +1834,6 @@ class Detector { std::vector getPortNumbers(int start_port); void updateRxRateCorrections(); void setNumberofUDPInterfaces_(int n, Positions pos); - Result getNumberofUDPInterfaces_(Positions pos) const; }; } // namespace sls diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 9ef9d20f1..975c59420 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -959,6 +959,68 @@ std::string CmdProxy::ExternalSignal(int action) { return os.str(); } +std::string CmdProxy::CurrentSource(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[0|1]\n\t[Gotthard2] Enable or disable current source. Default " + "is disabled.\n[0|1] [fix|nofix] [select source] [(only for " + "chipv1.1)normal|low]\n\t[Jungfrau] Disable or enable current " + "source with some parameters. The select source is 0-63 for " + "chipv1.0 and a 64 bit mask for chipv1.1. To disable, one needs " + "only one argument '0'." + << '\n'; + } else if (action == defs::GET_ACTION) { + if (args.size() != 0) { + WrongNumberOfParameters(0); + } + auto t = det->getCurrentSource(std::vector{det_id}); + os << OutString(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() == 1) { + det->setCurrentSource( + defs::currentSrcParameters(StringTo(args[0]))); + } else if (args.size() >= 3) { + // scan fix + bool fix = false; + if (args[1] == "fix") { + fix = true; + } else if (args[1] == "nofix") { + fix = false; + } else { + throw sls::RuntimeError("Invalid argument: " + args[1] + + ". Did you mean fix or nofix?"); + } + if (args.size() == 3) { + det->setCurrentSource(defs::currentSrcParameters( + fix, StringTo(args[2]))); + } else if (args.size() == 4) { + bool normalCurrent = false; + if (args[3] == "normal") { + normalCurrent = true; + } else if (args[3] == "low") { + normalCurrent = false; + } else { + throw sls::RuntimeError("Invalid argument: " + args[3] + + ". Did you mean normal or low?"); + } + det->setCurrentSource(defs::currentSrcParameters( + fix, StringTo(args[2]), normalCurrent)); + } else { + throw sls::RuntimeError( + "Invalid number of parareters for this command."); + } + } else { + throw sls::RuntimeError( + "Invalid number of parareters for this command."); + } + os << ToString(args) << '\n'; + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} + /** temperature */ std::string CmdProxy::TemperatureValues(int action) { std::ostringstream os; @@ -1095,6 +1157,82 @@ std::string CmdProxy::DacValues(int action) { return os.str(); } +std::string CmdProxy::ResetDacs(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[(optional) hard] " + "\n\t[Eiger][Jungfrau][Gotthard][Moench][Gotthard2][" + "Mythen3]Reset dac values to the defaults. A 'hard' optional " + "reset will reset the dacs to the hardcoded defaults in on-board " + "detector server." + << '\n'; + } else if (action == defs::GET_ACTION) { + throw sls::RuntimeError("Cannot get"); + } else if (action == defs::PUT_ACTION) { + bool hardReset = false; + if (args.size() == 1) { + if (args[0] != "hard") { + throw sls::RuntimeError("Unknown argument " + args[0] + + ". Did you mean hard?"); + } + hardReset = true; + } else if (args.size() > 1) { + WrongNumberOfParameters(1); + } + det->resetToDefaultDacs(hardReset, std::vector{det_id}); + os << "successful\n"; + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} + +std::string CmdProxy::DefaultDac(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[dac name][value][(optional)setting]\n\tSets the default for " + "that dac to this value.\n\t[Jungfrau][Mythen3] When settings is " + "provided, it sets the default value only for that setting" + << '\n'; + } else if (action == defs::GET_ACTION) { + if (args.size() < 1) { + WrongNumberOfParameters(1); + } + // optional settings + if (args.size() == 2) { + auto t = det->getDefaultDac( + StringTo(args[0]), + sls::StringTo(args[1]), + std::vector{det_id}); + os << args[0] << ' ' << args[1] << ' ' << OutString(t) << '\n'; + } else { + auto t = det->getDefaultDac(StringTo(args[0]), + std::vector{det_id}); + os << args[0] << ' ' << OutString(t) << '\n'; + } + } else if (action == defs::PUT_ACTION) { + if (args.size() < 2) { + WrongNumberOfParameters(2); + } + // optional settings + if (args.size() == 3) { + det->setDefaultDac( + StringTo(args[0]), StringTo(args[1]), + sls::StringTo(args[2]), + std::vector{det_id}); + os << args[0] << ' ' << args[2] << ' ' << args[1] << '\n'; + } else { + det->setDefaultDac(StringTo(args[0]), + StringTo(args[1])); + os << args[0] << ' ' << args[1] << '\n'; + } + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} /* acquisition */ std::string CmdProxy::ReceiverStatus(int action) { diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index d41420f07..4719821f3 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -584,6 +584,7 @@ class CmdProxy { {"detsizechan", "detsize"}, {"trimdir", "settingspath"}, {"settingsdir", "settingspath"}, + {"flippeddatax", "fliprows"}, /* acquisition parameters */ {"cycles", "triggers"}, @@ -591,6 +592,7 @@ class CmdProxy { {"clkdivider", "speed"}, {"vhighvoltage", "highvoltage"}, {"digitest", "imagetest"}, + {"filter", "filterresistor"}, /** temperature */ @@ -671,6 +673,8 @@ class CmdProxy { {"vipre_cds", "dac"}, {"ibias_sfp", "dac"}, + {"defaultdacs", "resetdacs"}, + /* acquisition */ {"busy", "clearbusy"}, {"receiver", "rx_status"}, @@ -767,6 +771,7 @@ class CmdProxy { {"trimval", &CmdProxy::trimval}, {"trimen", &CmdProxy::TrimEnergies}, {"gappixels", &CmdProxy::GapPixels}, + {"fliprows", &CmdProxy::fliprows}, /* acquisition parameters */ {"acquire", &CmdProxy::Acquire}, @@ -797,6 +802,8 @@ class CmdProxy { {"imagetest", &CmdProxy::imagetest}, {"extsig", &CmdProxy::ExternalSignal}, {"parallel", &CmdProxy::parallel}, + {"filterresistor", &CmdProxy::filterresistor}, + {"currentsource", &CmdProxy::CurrentSource}, /** temperature */ {"templist", &CmdProxy::templist}, @@ -816,7 +823,8 @@ class CmdProxy { {"dac", &CmdProxy::Dac}, {"daclist", &CmdProxy::daclist}, {"dacvalues", &CmdProxy::DacValues}, - {"defaultdacs", &CmdProxy::defaultdacs}, + {"resetdacs", &CmdProxy::ResetDacs}, + {"defaultdac", &CmdProxy::DefaultDac}, /* on chip dacs */ {"vchip_comp_fe", &CmdProxy::vchip_comp_fe}, @@ -903,7 +911,6 @@ class CmdProxy { {"subexptime", &CmdProxy::subexptime}, {"subdeadtime", &CmdProxy::subdeadtime}, {"overflow", &CmdProxy::overflow}, - {"flippeddatax", &CmdProxy::flippeddatax}, {"ratecorr", &CmdProxy::RateCorrection}, {"readnlines", &CmdProxy::readnlines}, {"interruptsubframe", &CmdProxy::interruptsubframe}, @@ -918,13 +925,17 @@ class CmdProxy { {"datastream", &CmdProxy::DataStream}, /* Jungfrau Specific */ + {"chipversion", &CmdProxy::chipversion}, {"temp_threshold", &CmdProxy::temp_threshold}, {"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}, + {"gainmode", &CmdProxy::gainmode}, + {"filtercell", &CmdProxy::filtercell}, /* Gotthard Specific */ {"roi", &CmdProxy::ROI}, @@ -941,8 +952,6 @@ class CmdProxy { {"vetofile", &CmdProxy::VetoFile}, {"burstmode", &CmdProxy::BurstMode}, {"cdsgain", &CmdProxy::cdsgain}, - {"filter", &CmdProxy::filter}, - {"currentsource", &CmdProxy::currentsource}, {"timingsource", &CmdProxy::timingsource}, {"veto", &CmdProxy::veto}, {"vetostream", &CmdProxy::VetoStreaming}, @@ -1088,11 +1097,14 @@ class CmdProxy { std::string MaxClockPhaseShift(int action); std::string ClockDivider(int action); std::string ExternalSignal(int action); + std::string CurrentSource(int action); /** temperature */ std::string TemperatureValues(int action); /* dacs */ std::string Dac(int action); std::string DacValues(int action); + std::string ResetDacs(int action); + std::string DefaultDac(int action); /* acquisition */ std::string ReceiverStatus(int action); std::string DetectorStatus(int action); @@ -1195,13 +1207,12 @@ class CmdProxy { settings, getSettings, setSettings, sls::StringTo, "[standard, fast, highgain, dynamicgain, lowgain, " - "mediumgain, veryhighgain, dynamichg0, " + "mediumgain, veryhighgain, highgain0, " "fixgain1, fixgain2, forceswitchg1, forceswitchg2, " "verylowgain, g1_hg, g1_lg, g2_hc_hg, g2_hc_lg, " - "g2_lc_hg, g2_lc_lg, g4_hg, g4_lg]" + "g2_lc_hg, g2_lc_lg, g4_hg, g4_lg, gain0]" "\n\t Detector Settings" - "\n\t[Jungfrau] - [dynamicgain | dynamichg0 | fixgain1 | " - "fixgain2 | forceswitchg1 | forceswitchg2]" + "\n\t[Jungfrau] - [ gain0 | highgain0]" "\n\t[Gotthard] - [dynamicgain | highgain | lowgain | " "mediumgain | veryhighgain]" "\n\t[Gotthard2] - [dynamicgain | fixgain1 | fixgain2]" @@ -1226,6 +1237,14 @@ class CmdProxy { "[n_trimval]\n\t[Eiger][Mythen3] All trimbits set to this " "value. Returns -1 if all trimbits are different values."); + INTEGER_COMMAND_VEC_ID( + fliprows, getFlipRows, setFlipRows, StringTo, + "[0, 1]\n\t[Eiger] flips rows paramater sent to slsreceiver " + "to stream as json parameter to flip rows in gui \n\t[Jungfrau] flips " + "rows in the detector itself. For bottom module and number of " + "interfaces must be set to 2. slsReceiver and slsDetectorGui " + "does not handle."); + /* acquisition parameters */ INTEGER_COMMAND_SET_NOID_GET_ID( @@ -1314,7 +1333,7 @@ class CmdProxy { "the chip. \n\t[Moench] Default is 0. \n\t[Jungfrau] Default is 0. Get " "will return power status. Can be off if temperature event occured " "(temperature over temp_threshold with temp_control " - "enabled.\n\t[Mythen3][Gotthard2] Default is 1. If module not " + "enabled. Will configure chip (only chip v1.1)\n\t[Mythen3][Gotthard2] Default is 1. If module not " "connected or wrong module, powerchip will fail."); INTEGER_COMMAND_VEC_ID( @@ -1331,6 +1350,12 @@ class CmdProxy { "acquisition will return ERROR status and take fewer " "frames than expected."); + INTEGER_COMMAND_VEC_ID( + filterresistor, getFilterResistor, setFilterResistor, StringTo, + "[value] [Gotthard2][Jungfrau] Set filter resistor. Increasing values " + "for increasing resistance.\n\t[Gotthard2] Options: [0|1|2|3]. Default " + "is 0.\n\t[Jungfrau] Options: [0|1]. Default is 1."); + /** temperature */ GET_COMMAND_NOID( templist, getTemperatureList, @@ -1381,10 +1406,6 @@ class CmdProxy { daclist, getDacList, "\n\tGets the list of commands for every dac for this detector."); - EXECUTE_SET_COMMAND(defaultdacs, setDefaultDacs, - "\n\t[Eiger][Jungfrau][Gotthard][Moench][Gotthard2][" - "Mythen3]Sets default dacs on to the detector."); - /* on chip dacs */ INTEGER_USER_IND_COMMAND( vchip_comp_fe, getOnChipDAC, setOnChipDAC, StringTo, @@ -1775,13 +1796,6 @@ class CmdProxy { "[0, 1]\n\t[Eiger] Enable or disable show overflow flag in " "32 bit mode. Default is disabled."); - INTEGER_COMMAND_VEC_ID( - flippeddatax, getBottom, setBottom, StringTo, - "[0, 1]\n\t[Eiger] Top or Bottom Half of Eiger module. 1 is bottom, 0 " - "is top. Used to let Gui (via zmq from receiver) know to flip the " - "bottom image over the x axis. Files are not written without the flip " - "however."); - INTEGER_COMMAND_VEC_ID( readnlines, getPartialReadout, setPartialReadout, StringTo, "[1 - 256]\n\t[Eiger] Number of rows to readout per half module " @@ -1812,6 +1826,9 @@ class CmdProxy { /* Jungfrau Specific */ + GET_COMMAND(chipversion, getChipVersion, + "\n\t[Jungfrau] Returns chip version. Can be 1.0 or 1.1"); + INTEGER_COMMAND_VEC_ID( temp_threshold, getThresholdTemperature, setThresholdTemperature, StringTo, @@ -1832,33 +1849,52 @@ 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, setNumberOfAdditionalStorageCells, StringTo, - "[0-15]\n\t[Jungfrau] Number of additional storage cells. Default is " + "[0-15]\n\t[Jungfrau] Only for chipv1.0. Number of additional storage cells. Default is " "0. For advanced users only. \n\tThe #images = #frames x #triggers x " "(#storagecells + 1)."); INTEGER_COMMAND_VEC_ID( storagecell_start, getStorageCellStart, setStorageCellStart, StringTo, - "[0-15]\n\t[Jungfrau] Storage cell that stores the first acquisition " - "of the series. Default is 15. For advanced users only."); + "[0-max]\n\t[Jungfrau] Storage cell that stores the first acquisition " + "of the series. max is 15 (default) for chipv1.0 and 3 (default) for chipv1.1. For advanced users only."); TIME_COMMAND( storagecell_delay, getStorageCellDelay, setStorageCellDelay, "[duration (0-1638375 ns)] [(optional unit) ns|us|ms|s]\n\t[Jungfrau] " "Additional time delay between 2 consecutive exposures in burst mode " - "(resolution of 25ns). For advanced users only."); + "(resolution of 25ns). Only applicable for chipv1.0. For advanced users only."); + + INTEGER_COMMAND_VEC_ID( + gainmode, getGainMode, setGainMode, + sls::StringTo, + "[dynamicgain|forceswitchg1|forceswitchg2|fixg1|fixg2|fixg0]\n\t[" + "Jungfrau] Gain mode.\n\tCAUTION: Do not use fixg0 without caution, " + "you can damage the detector!!!"); + + INTEGER_COMMAND_VEC_ID( + filtercell, getFilterCell, setFilterCell, sls::StringTo, + "[0-12]\n\t[Jungfrau] Set Filter Cell. Advanced user Command"); /* Gotthard Specific */ TIME_GET_COMMAND(exptimel, getExptimeLeft, @@ -1886,15 +1922,6 @@ class CmdProxy { "[0, 1]\n\t[Gotthard2] Enable or disable CDS gain. Default " "is disabled."); - INTEGER_COMMAND_VEC_ID( - filter, getFilter, setFilter, StringTo, - "[0|1|2|3]\n\t[Gotthard2] Set filter resistor. Default is 0."); - - INTEGER_COMMAND_VEC_ID( - currentsource, getCurrentSource, setCurrentSource, StringTo, - "[0, 1]\n\t[Gotthard2] Enable or disable current source. " - "Default is disabled."); - INTEGER_COMMAND_VEC_ID( timingsource, getTimingSource, setTimingSource, sls::StringTo, diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 9534a88ab..50e054a78 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -158,13 +158,11 @@ std::vector Detector::getSettingsList() const { defs::HIGHGAIN, defs::DYNAMICGAIN, defs::LOWGAIN, defs::MEDIUMGAIN, defs::VERYHIGHGAIN}; case defs::JUNGFRAU: - return std::vector{ - defs::DYNAMICGAIN, defs::DYNAMICHG0, defs::FIXGAIN1, - defs::FIXGAIN2, defs::FORCESWITCHG1, defs::FORCESWITCHG2}; + return std::vector{defs::GAIN0, + defs::HIGHGAIN0}; case defs::GOTTHARD2: return std::vector{ - defs::DYNAMICGAIN, defs::DYNAMICHG0, defs::FIXGAIN1, - defs::FIXGAIN2}; + defs::DYNAMICGAIN, defs::FIXGAIN1, defs::FIXGAIN2}; case defs::MOENCH: return std::vector{ defs::G1_HIGHGAIN, defs::G1_LOWGAIN, @@ -281,6 +279,14 @@ void Detector::setGapPixelsinCallback(bool enable) { pimpl->setGapPixelsinCallback(enable); } +Result Detector::getFlipRows(Positions pos) const { + return pimpl->Parallel(&Module::getFlipRows, pos); +} + +void Detector::setFlipRows(bool value, Positions pos) { + pimpl->Parallel(&Module::setFlipRows, pos, value); +} + Result Detector::isVirtualDetectorServer(Positions pos) const { return pimpl->Parallel(&Module::isVirtualDetectorServer, pos); } @@ -621,8 +627,38 @@ std::vector Detector::getDacList() const { return retval; } -void Detector::setDefaultDacs(Positions pos) { - pimpl->Parallel(&Module::setDefaultDacs, pos); +Result Detector::getDefaultDac(defs::dacIndex index, Positions pos) { + return pimpl->getDefaultDac(index, defs::UNDEFINED, pos); +} + +void Detector::setDefaultDac(defs::dacIndex index, int defaultValue, + Positions pos) { + pimpl->setDefaultDac(index, defaultValue, defs::UNDEFINED, pos); +} + +Result Detector::getDefaultDac(defs::dacIndex index, + defs::detectorSettings sett, + Positions pos) { + if (sett == defs::UNDEFINED) { + throw RuntimeError("Invalid settings given for default dac"); + } + return pimpl->getDefaultDac(index, sett, pos); +} + +void Detector::setDefaultDac(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos) { + if (sett == defs::UNDEFINED) { + throw RuntimeError("Invalid settings given for default dac"); + } + pimpl->setDefaultDac(index, defaultValue, sett, pos); +} + + + + + +void Detector::resetToDefaultDacs(const bool hardReset, Positions pos) { + pimpl->Parallel(&Module::resetToDefaultDacs, pos, hardReset); } Result Detector::getDAC(defs::dacIndex index, bool mV, @@ -663,6 +699,22 @@ void Detector::setParallelMode(bool value, Positions pos) { pimpl->Parallel(&Module::setParallelMode, pos, value); } +Result Detector::getFilterResistor(Positions pos) const { + return pimpl->Parallel(&Module::getFilterResistor, pos); +} + +void Detector::setFilterResistor(int value, Positions pos) { + pimpl->Parallel(&Module::setFilterResistor, pos, value); +} + +Result +Detector::getCurrentSource(Positions pos) const { + return pimpl->Parallel(&Module::getCurrentSource, pos); +} + +void Detector::setCurrentSource(defs::currentSrcParameters par, Positions pos) { + pimpl->Parallel(&Module::setCurrentSource, pos, par); +} // Acquisition void Detector::acquire() { pimpl->acquire(); } @@ -754,7 +806,7 @@ Result Detector::getNumberofUDPInterfaces(Positions pos) const { "Cannot set number of udp interfaces for this detector."); } // also called by vetostream (for gotthard2) - return getNumberofUDPInterfaces_(pos); + return pimpl->getNumberofUDPInterfaces(pos); } void Detector::setNumberofUDPInterfaces(int n, Positions pos) { @@ -766,10 +818,6 @@ void Detector::setNumberofUDPInterfaces(int n, Positions pos) { setNumberofUDPInterfaces_(n, pos); } -Result Detector::getNumberofUDPInterfaces_(Positions pos) const { - return pimpl->Parallel(&Module::getNumberofUDPInterfaces, pos); -} - void Detector::setNumberofUDPInterfaces_(int n, Positions pos) { bool previouslyClientStreaming = pimpl->getDataStreamingToClient(); bool useReceiver = getUseReceiverFlag().squash(false); @@ -1280,14 +1328,6 @@ void Detector::setOverFlowMode(bool value, Positions pos) { pimpl->Parallel(&Module::setOverFlowMode, pos, value); } -Result Detector::getBottom(Positions pos) const { - return pimpl->Parallel(&Module::getFlippedDataX, pos); -} - -void Detector::setBottom(bool value, Positions pos) { - pimpl->Parallel(&Module::setFlippedDataX, pos, value); -} - Result Detector::getRateCorrection(Positions pos) const { return pimpl->Parallel(&Module::getRateCorrection, pos); } @@ -1398,6 +1438,9 @@ void Detector::setDataStream(const defs::portPosition port, const bool enable, } // Jungfrau Specific +Result Detector::getChipVersion(Positions pos) const { + return pimpl->Parallel(&Module::getChipVersion, pos); +} Result Detector::getThresholdTemperature(Positions pos) const { return pimpl->Parallel(&Module::getThresholdTemperature, pos); @@ -1423,14 +1466,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); } @@ -1455,6 +1506,37 @@ void Detector::setStorageCellDelay(ns value, Positions pos) { pimpl->Parallel(&Module::setStorageCellDelay, pos, value.count()); } +std::vector Detector::getGainModeList() const { + switch (getDetectorType().squash()) { + case defs::JUNGFRAU: + return std::vector{defs::DYNAMIC, + defs::FORCE_SWITCH_G1, + defs::FORCE_SWITCH_G2, + defs::FIX_G1, + defs::FIX_G2, + defs::FIX_G0}; + break; + default: + throw RuntimeError("Gain mode is not implemented for this detector."); + } +} + +Result Detector::getGainMode(Positions pos) const { + return pimpl->Parallel(&Module::getGainMode, pos); +} + +void Detector::setGainMode(const defs::gainMode mode, Positions pos) { + pimpl->Parallel(&Module::setGainMode, pos, mode); +} + +Result Detector::getFilterCell(Positions pos) const { + return pimpl->Parallel(&Module::getFilterCell, pos); +} + +void Detector::setFilterCell(int cell, Positions pos) { + pimpl->Parallel(&Module::setFilterCell, pos, cell); +} + // Gotthard Specific Result Detector::getROI(Positions pos) const { @@ -1546,22 +1628,6 @@ void Detector::setCDSGain(bool value, Positions pos) { pimpl->Parallel(&Module::setCDSGain, pos, value); } -Result Detector::getFilter(Positions pos) const { - return pimpl->Parallel(&Module::getFilter, pos); -} - -void Detector::setFilter(int value, Positions pos) { - pimpl->Parallel(&Module::setFilter, pos, value); -} - -Result Detector::getCurrentSource(Positions pos) const { - return pimpl->Parallel(&Module::getCurrentSource, pos); -} - -void Detector::setCurrentSource(bool value, Positions pos) { - pimpl->Parallel(&Module::setCurrentSource, pos, value); -} - Result Detector::getTimingSource(Positions pos) const { return pimpl->Parallel(&Module::getTimingSource, pos); } @@ -1582,7 +1648,7 @@ Result Detector::getVetoStream(Positions pos) const { // 3gbe auto r3 = pimpl->Parallel(&Module::getVetoStream, pos); // 10gbe (debugging interface) opens 2nd udp interface in receiver - auto r10 = getNumberofUDPInterfaces_(pos); + auto r10 = pimpl->getNumberofUDPInterfaces(pos); Result res(r3.size()); for (unsigned int i = 0; i < res.size(); ++i) { @@ -1602,7 +1668,7 @@ void Detector::setVetoStream(defs::streamingInterface interface, Positions pos) pimpl->Parallel(&Module::setVetoStream, pos, LOW_LATENCY_LINK); // 10gbe (debugging interface) opens 2nd udp interface in receiver - int old_numinterfaces = getNumberofUDPInterfaces_(pos).tsquash( + int old_numinterfaces = pimpl->getNumberofUDPInterfaces(pos).tsquash( "retrieved inconsistent number of udp interfaces"); int numinterfaces = (((interface & defs::streamingInterface::ETHERNET_10GB) == defs::streamingInterface::ETHERNET_10GB) @@ -2167,7 +2233,7 @@ std::vector Detector::getPortNumbers(int start_port) { break; case defs::JUNGFRAU: case defs::GOTTHARD2: - if (getNumberofUDPInterfaces_({}).squash() == 2) { + if (pimpl->getNumberofUDPInterfaces({}).squash() == 2) { num_sockets_per_detector *= 2; } break; diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 188b53167..20b159875 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -490,8 +490,7 @@ void DetectorImpl::readFrameFromReceiver() { uint64_t currentAcquisitionIndex = -1, currentFrameIndex = -1, currentFileIndex = -1; double currentProgress = 0.00; - uint32_t currentSubFrameIndex = -1, coordX = -1, coordY = -1, - flippedDataX = -1; + uint32_t currentSubFrameIndex = -1, coordX = -1, coordY = -1, flipRows = -1; while (numZmqRunning != 0) { // reset data @@ -571,7 +570,7 @@ void DetectorImpl::readFrameFromReceiver() { if (eiger) { coordY = (nY - 1) - coordY; } - flippedDataX = zHeader.flippedDataX; + flipRows = zHeader.flipRows; if (zHeader.completeImage == 0) { completeImage = false; } @@ -585,7 +584,7 @@ void DetectorImpl::readFrameFromReceiver() { << "\n\tcurrentSubFrameIndex: " << currentSubFrameIndex << "\n\tcurrentProgress: " << currentProgress << "\n\tcoordX: " << coordX << "\n\tcoordY: " << coordY - << "\n\tflippedDataX: " << flippedDataX + << "\n\tflipRows: " << flipRows << "\n\tcompleteImage: " << completeImage; } @@ -609,7 +608,7 @@ void DetectorImpl::readFrameFromReceiver() { << "\n\tsingledetrowoffset: " << singledetrowoffset << "\n\trowoffset: " << rowoffset; - if (eiger && (flippedDataX != 0U)) { + if (eiger && (flipRows != 0U)) { for (uint32_t i = 0; i < nPixelsY; ++i) { memcpy((multiframe.get()) + ((yoffset + (nPixelsY - 1 - i)) * @@ -1369,4 +1368,19 @@ std::vector DetectorImpl::readProgrammingFile(const std::string &fname) { return buffer; } +sls::Result DetectorImpl::getNumberofUDPInterfaces(Positions pos) const { + return Parallel(&Module::getNumberofUDPInterfaces, pos); +} + +sls::Result DetectorImpl::getDefaultDac(defs::dacIndex index, + defs::detectorSettings sett, + Positions pos) { + return Parallel(&Module::getDefaultDac, pos, index, sett); +} + +void DetectorImpl::setDefaultDac(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos) { + Parallel(&Module::setDefaultDac, pos, index, defaultValue, sett); +} + } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index fa34c5ca1..8dd8f519b 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -291,6 +291,14 @@ class DetectorImpl : public virtual slsDetectorDefs { */ std::vector readProgrammingFile(const std::string &fname); + sls::Result getNumberofUDPInterfaces(Positions pos) const; + void setNumberofUDPInterfaces(int n, Positions pos); + sls::Result getDefaultDac(defs::dacIndex index, + defs::detectorSettings sett, + Positions pos = {}); + void setDefaultDac(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos); + private: /** * Creates/open shared memory, initializes detector structure and members diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 9a915791e..60c1d8727 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -458,6 +458,21 @@ int Module::setTrimEn(const std::vector &energies) { return shm()->trimEnergies.size(); } +bool Module::getFlipRows() const { + if (shm()->myDetectorType == EIGER) { + return sendToReceiver(F_GET_FLIP_ROWS_RECEIVER); + } + return sendToDetector(F_GET_FLIP_ROWS); +} + +void Module::setFlipRows(bool value) { + if (shm()->myDetectorType == EIGER) { + sendToReceiver(F_SET_FLIP_ROWS_RECEIVER, static_cast(value)); + } else { + sendToDetector(F_SET_FLIP_ROWS, static_cast(value), nullptr); + } +} + bool Module::isVirtualDetectorServer() const { return sendToDetector(F_IS_VIRTUAL); } @@ -618,8 +633,21 @@ int Module::getDAC(dacIndex index, bool mV) const { int args[]{static_cast(index), static_cast(mV), GET_FLAG}; return sendToDetector(F_SET_DAC, args); } +int Module::getDefaultDac(slsDetectorDefs::dacIndex index, + slsDetectorDefs::detectorSettings sett) { + int args[]{static_cast(index), static_cast(sett)}; + return sendToDetector(F_GET_DEFAULT_DAC, args); +} +void Module::setDefaultDac(slsDetectorDefs::dacIndex index, int defaultValue, + defs::detectorSettings sett) { + int args[]{static_cast(index), static_cast(sett), defaultValue}; + return sendToDetector(F_SET_DEFAULT_DAC, args, nullptr); +} -void Module::setDefaultDacs() { sendToDetector(F_SET_DEFAULT_DACS); } +void Module::resetToDefaultDacs(const bool hardReset) { + sendToDetector(F_RESET_TO_DEFAULT_DACS, static_cast(hardReset), + nullptr); +} void Module::setDAC(int val, dacIndex index, bool mV) { int args[]{static_cast(index), static_cast(mV), val}; @@ -676,6 +704,22 @@ void Module::setParallelMode(const bool enable) { sendToDetector(F_SET_PARALLEL_MODE, static_cast(enable), nullptr); } +int Module::getFilterResistor() const { + return sendToDetector(F_GET_FILTER_RESISTOR); +} + +void Module::setFilterResistor(int value) { + sendToDetector(F_SET_FILTER_RESISTOR, value, nullptr); +} + +defs::currentSrcParameters Module::getCurrentSource() const { + return sendToDetector(F_GET_CURRENT_SOURCE); +} + +void Module::setCurrentSource(defs::currentSrcParameters par) { + sendToDetector(F_SET_CURRENT_SOURCE, par, nullptr); +} + // Acquisition void Module::startReceiver() { @@ -1385,14 +1429,6 @@ void Module::setOverFlowMode(const bool enable) { sendToDetector(F_SET_OVERFLOW_MODE, static_cast(enable), nullptr); } -bool Module::getFlippedDataX() const { - return sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, GET_FLAG); -} - -void Module::setFlippedDataX(bool value) { - sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, static_cast(value)); -} - int64_t Module::getRateCorrection() const { return sendToDetector(F_GET_RATE_CORRECT); } @@ -1522,6 +1558,9 @@ void Module::setDataStream(const portPosition port, const bool enable) { } // Jungfrau Specific +double Module::getChipVersion() const { + return (sendToDetector(F_GET_CHIP_VERSION)) / 10.00; +} int Module::getThresholdTemperature() const { auto retval = sendToDetectorStop(F_THRESHOLD_TEMP, GET_FLAG); @@ -1561,6 +1600,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); } @@ -1585,6 +1632,22 @@ void Module::setStorageCellDelay(int64_t value) { sendToDetector(F_SET_STORAGE_CELL_DELAY, value, nullptr); } +slsDetectorDefs::gainMode Module::getGainMode() const { + return sendToDetector(F_GET_GAIN_MODE); +} + +void Module::setGainMode(const slsDetectorDefs::gainMode mode) { + sendToDetector(F_SET_GAIN_MODE, mode, nullptr); +} + +int Module::getFilterCell() const { + return sendToDetector(F_GET_FILTER_CELL); +} + +void Module::setFilterCell(int value) { + sendToDetector(F_SET_FILTER_CELL, value, nullptr); +} + // Gotthard Specific slsDetectorDefs::ROI Module::getROI() const { @@ -1859,20 +1922,6 @@ void Module::setCDSGain(bool value) { sendToDetector(F_SET_CDS_GAIN, static_cast(value), nullptr); } -int Module::getFilter() const { return sendToDetector(F_GET_FILTER); } - -void Module::setFilter(int value) { - sendToDetector(F_SET_FILTER, value, nullptr); -} - -bool Module::getCurrentSource() const { - return sendToDetector(F_GET_CURRENT_SOURCE); -} - -void Module::setCurrentSource(bool value) { - sendToDetector(F_SET_CURRENT_SOURCE, static_cast(value), nullptr); -} - slsDetectorDefs::timingSourceType Module::getTimingSource() const { return sendToDetector(F_GET_TIMING_SOURCE); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 2a2d9ed2e..782b8f442 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -114,6 +114,8 @@ class Module : public virtual slsDetectorDefs { void setAllTrimbits(int val); std::vector getTrimEn() const; int setTrimEn(const std::vector &energies = {}); + bool getFlipRows() const; + void setFlipRows(bool value); bool isVirtualDetectorServer() const; /************************************************** @@ -148,8 +150,11 @@ class Module : public virtual slsDetectorDefs { int getMaxClockPhaseShift(int clkIndex) const; int getClockFrequency(int clkIndex) const; void setClockFrequency(int clkIndex, int value); - /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ - void setDefaultDacs(); + int getDefaultDac(slsDetectorDefs::dacIndex index, + slsDetectorDefs::detectorSettings sett); + void setDefaultDac(slsDetectorDefs::dacIndex index, int defaultValue, + defs::detectorSettings sett); + void resetToDefaultDacs(const bool hardReset); int getDAC(dacIndex index, bool mV) const; void setDAC(int val, dacIndex index, bool mV); bool getPowerChip() const; @@ -165,7 +170,10 @@ class Module : public virtual slsDetectorDefs { void setExternalSignalFlags(int signalIndex, externalSignalFlag type); bool getParallelMode() const; void setParallelMode(const bool enable); - + int getFilterResistor() const; + void setFilterResistor(int value); + defs::currentSrcParameters getCurrentSource() const; + void setCurrentSource(defs::currentSrcParameters par); /************************************************** * * * Acquisition * @@ -320,8 +328,6 @@ class Module : public virtual slsDetectorDefs { void setSubDeadTime(int64_t value); bool getOverFlowMode() const; void setOverFlowMode(const bool enable); - bool getFlippedDataX() const; - void setFlippedDataX(bool value); int64_t getRateCorrection() const; void setDefaultRateCorrection(); void setRateCorrection(int64_t t = 0); @@ -351,6 +357,7 @@ class Module : public virtual slsDetectorDefs { * Jungfrau Specific * * * * ************************************************/ + double getChipVersion() const; int getThresholdTemperature() const; void setThresholdTemperature(int val); bool getTemperatureControl() const; @@ -359,13 +366,19 @@ 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; void setStorageCellStart(int pos); int64_t getStorageCellDelay() const; void setStorageCellDelay(int64_t value); - + gainMode getGainMode() const; + void setGainMode(const gainMode mode); + int getFilterCell() const; + void setFilterCell(int value); + /************************************************** * * * Gotthard Specific * @@ -400,10 +413,6 @@ class Module : public virtual slsDetectorDefs { void setBurstMode(burstMode value); bool getCDSGain() const; void setCDSGain(bool value); - int getFilter() const; - void setFilter(int value); - bool getCurrentSource() const; - void setCurrentSource(bool value); slsDetectorDefs::timingSourceType getTimingSource() const; void setTimingSource(slsDetectorDefs::timingSourceType value); bool getVeto() const; diff --git a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp index d47c0a75b..0e5ff1e38 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp @@ -340,27 +340,6 @@ TEST_CASE("overflow", "[.cmd]") { } } -TEST_CASE("flippeddatax", "[.cmd]") { - Detector det; - CmdProxy proxy(&det); - auto det_type = det.getDetectorType().squash(); - if (det_type == defs::EIGER) { - auto previous = det.getBottom(); - std::ostringstream oss1, oss2, oss3; - proxy.Call("flippeddatax", {"1"}, -1, PUT, oss1); - REQUIRE(oss1.str() == "flippeddatax 1\n"); - proxy.Call("flippeddatax", {}, -1, GET, oss2); - REQUIRE(oss2.str() == "flippeddatax 1\n"); - proxy.Call("flippeddatax", {"0"}, -1, PUT, oss3); - REQUIRE(oss3.str() == "flippeddatax 0\n"); - for (int i = 0; i != det.size(); ++i) { - det.setBottom(previous[i], {i}); - } - } else { - REQUIRE_THROWS(proxy.Call("flippeddatax", {}, -1, GET)); - } -} - TEST_CASE("ratecorr", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp index 50b0783f7..ac40d855a 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp @@ -519,66 +519,6 @@ TEST_CASE("cdsgain", "[.cmd]") { } } -TEST_CASE("filter", "[.cmd]") { - Detector det; - CmdProxy proxy(&det); - auto det_type = det.getDetectorType().squash(); - - if (det_type == defs::GOTTHARD2) { - auto prev_val = det.getFilter(); - { - std::ostringstream oss; - proxy.Call("filter", {"1"}, -1, PUT, oss); - REQUIRE(oss.str() == "filter 1\n"); - } - { - std::ostringstream oss; - proxy.Call("filter", {"0"}, -1, PUT, oss); - REQUIRE(oss.str() == "filter 0\n"); - } - { - std::ostringstream oss; - proxy.Call("filter", {}, -1, GET, oss); - REQUIRE(oss.str() == "filter 0\n"); - } - for (int i = 0; i != det.size(); ++i) { - det.setFilter(prev_val[i], {i}); - } - } else { - REQUIRE_THROWS(proxy.Call("filter", {}, -1, GET)); - } -} - -TEST_CASE("currentsource", "[.cmd]") { - Detector det; - CmdProxy proxy(&det); - auto det_type = det.getDetectorType().squash(); - - if (det_type == defs::GOTTHARD2) { - auto prev_val = det.getCurrentSource(); - { - std::ostringstream oss; - proxy.Call("currentsource", {"1"}, -1, PUT, oss); - REQUIRE(oss.str() == "currentsource 1\n"); - } - { - std::ostringstream oss; - proxy.Call("currentsource", {"0"}, -1, PUT, oss); - REQUIRE(oss.str() == "currentsource 0\n"); - } - { - std::ostringstream oss; - proxy.Call("currentsource", {}, -1, GET, oss); - REQUIRE(oss.str() == "currentsource 0\n"); - } - for (int i = 0; i != det.size(); ++i) { - det.setCurrentSource(prev_val[i], {i}); - } - } else { - REQUIRE_THROWS(proxy.Call("currentsource", {}, -1, GET)); - } -} - TEST_CASE("timingsource", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp index 9508daeee..b71d9678e 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp @@ -190,6 +190,18 @@ TEST_CASE("temp_threshold", "[.cmd]") { } } +TEST_CASE("chipversion", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU) { + REQUIRE_NOTHROW(proxy.Call("chipversion", {}, -1, GET)); + } else { + REQUIRE_THROWS(proxy.Call("chipversion", {}, -1, GET)); + } + REQUIRE_THROWS(proxy.Call("chipversion", {"0"}, -1, PUT)); +} + TEST_CASE("temp_control", "[.cmd]") { Detector det; CmdProxy proxy(&det); @@ -246,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); @@ -263,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)); @@ -271,35 +283,73 @@ 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); auto det_type = det.getDetectorType().squash(); if (det_type == defs::JUNGFRAU) { - auto prev_val = det.getNumberOfAdditionalStorageCells().tsquash( - "inconsistent #additional storage cells to test"); - { - std::ostringstream oss; - proxy.Call("storagecells", {"1"}, -1, PUT, oss); - REQUIRE(oss.str() == "storagecells 1\n"); + // chip version 1.0 + if (det.getChipVersion().squash()*10 == 10) { + auto prev_val = det.getNumberOfAdditionalStorageCells().tsquash( + "inconsistent #additional storage cells to test"); + { + std::ostringstream oss; + proxy.Call("storagecells", {"1"}, -1, PUT, oss); + REQUIRE(oss.str() == "storagecells 1\n"); + } + { + std::ostringstream oss; + proxy.Call("storagecells", {"15"}, -1, PUT, oss); + REQUIRE(oss.str() == "storagecells 15\n"); + } + { + std::ostringstream oss; + proxy.Call("storagecells", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "storagecells 0\n"); + } + { + std::ostringstream oss; + proxy.Call("storagecells", {}, -1, GET, oss); + REQUIRE(oss.str() == "storagecells 0\n"); + } + REQUIRE_THROWS(proxy.Call("storagecells", {"16"}, -1, PUT)); + det.setNumberOfAdditionalStorageCells(prev_val); + } + // chip version 1.1 + else { + // cannot set number of addl. storage cells + REQUIRE_THROWS(proxy.Call("storagecells", {"1"}, -1, PUT)); } - { - std::ostringstream oss; - proxy.Call("storagecells", {"15"}, -1, PUT, oss); - REQUIRE(oss.str() == "storagecells 15\n"); - } - { - std::ostringstream oss; - proxy.Call("storagecells", {"0"}, -1, PUT, oss); - REQUIRE(oss.str() == "storagecells 0\n"); - } - { - std::ostringstream oss; - proxy.Call("storagecells", {}, -1, GET, oss); - REQUIRE(oss.str() == "storagecells 0\n"); - } - REQUIRE_THROWS(proxy.Call("storagecells", {"16"}, -1, PUT)); - det.setNumberOfAdditionalStorageCells(prev_val); } else { REQUIRE_THROWS(proxy.Call("storagecells", {}, -1, GET)); REQUIRE_THROWS(proxy.Call("storagecells", {"0"}, -1, PUT)); @@ -317,10 +367,19 @@ TEST_CASE("storagecell_start", "[.cmd]") { proxy.Call("storagecell_start", {"1"}, -1, PUT, oss); REQUIRE(oss.str() == "storagecell_start 1\n"); } - { + // chip version 1.0 + if (det.getChipVersion().squash()*10 == 10) { std::ostringstream oss; proxy.Call("storagecell_start", {"15"}, -1, PUT, oss); REQUIRE(oss.str() == "storagecell_start 15\n"); + } + // chip version 1.1 + else { + // max is 3 + REQUIRE_THROWS(proxy.Call("storagecell_start", {"15"}, -1, PUT)); + std::ostringstream oss; + proxy.Call("storagecell_start", {"3"}, -1, PUT, oss); + REQUIRE(oss.str() == "storagecell_start 3\n"); } { std::ostringstream oss; @@ -347,28 +406,130 @@ TEST_CASE("storagecell_delay", "[.cmd]") { CmdProxy proxy(&det); auto det_type = det.getDetectorType().squash(); if (det_type == defs::JUNGFRAU) { - auto prev_val = det.getStorageCellDelay(); - { - std::ostringstream oss; - proxy.Call("storagecell_delay", {"1.62ms"}, -1, PUT, oss); - REQUIRE(oss.str() == "storagecell_delay 1.62ms\n"); - } - { - std::ostringstream oss; - proxy.Call("storagecell_delay", {}, -1, GET, oss); - REQUIRE(oss.str() == "storagecell_delay 1.62ms\n"); - } - { - std::ostringstream oss; - proxy.Call("storagecell_delay", {"0"}, -1, PUT, oss); - REQUIRE(oss.str() == "storagecell_delay 0\n"); - } - REQUIRE_THROWS(proxy.Call("storagecell_delay", {"1638376ns"}, -1, PUT)); - for (int i = 0; i != det.size(); ++i) { - det.setStorageCellDelay(prev_val[i], {i}); + // chip version 1.0 + if (det.getChipVersion().squash()*10 == 10) { + auto prev_val = det.getStorageCellDelay(); + { + std::ostringstream oss; + proxy.Call("storagecell_delay", {"1.62ms"}, -1, PUT, oss); + REQUIRE(oss.str() == "storagecell_delay 1.62ms\n"); + } + { + std::ostringstream oss; + proxy.Call("storagecell_delay", {}, -1, GET, oss); + REQUIRE(oss.str() == "storagecell_delay 1.62ms\n"); + } + { + std::ostringstream oss; + proxy.Call("storagecell_delay", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "storagecell_delay 0\n"); + } + REQUIRE_THROWS(proxy.Call("storagecell_delay", {"1638376ns"}, -1, PUT)); + for (int i = 0; i != det.size(); ++i) { + det.setStorageCellDelay(prev_val[i], {i}); + } + } + // chip version 1.1 + else { + // cannot set storage cell delay + REQUIRE_THROWS(proxy.Call("storagecell_delay", {"1.62ms"}, -1, PUT)); } } else { REQUIRE_THROWS(proxy.Call("storagecell_delay", {}, -1, GET)); REQUIRE_THROWS(proxy.Call("storagecell_delay", {"0"}, -1, PUT)); } -} \ No newline at end of file +} + +TEST_CASE("gainmode", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU) { + auto prev_val = det.getGainMode(); + { + std::ostringstream oss; + proxy.Call("gainmode", {"forceswitchg1"}, -1, PUT, oss); + REQUIRE(oss.str() == "gainmode forceswitchg1\n"); + } + { + std::ostringstream oss; + proxy.Call("gainmode", {}, -1, GET, oss); + REQUIRE(oss.str() == "gainmode forceswitchg1\n"); + } + { + std::ostringstream oss; + proxy.Call("gainmode", {"dynamic"}, -1, PUT, oss); + REQUIRE(oss.str() == "gainmode dynamic\n"); + } + { + std::ostringstream oss; + proxy.Call("gainmode", {"forceswitchg2"}, -1, PUT, oss); + REQUIRE(oss.str() == "gainmode forceswitchg2\n"); + } + { + std::ostringstream oss; + proxy.Call("gainmode", {"fixg1"}, -1, PUT, oss); + REQUIRE(oss.str() == "gainmode fixg1\n"); + } + { + std::ostringstream oss; + proxy.Call("gainmode", {"fixg2"}, -1, PUT, oss); + REQUIRE(oss.str() == "gainmode fixg2\n"); + } + { + std::ostringstream oss; + proxy.Call("gainmode", {"fixg0"}, -1, PUT, oss); + REQUIRE(oss.str() == "gainmode fixg0\n"); + } + for (int i = 0; i != det.size(); ++i) { + det.setGainMode(prev_val[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("gainmode", {}, -1, GET)); + } +} + +TEST_CASE("filtercell", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU) { + // chip version 1.1 + if (det.getChipVersion().squash() * 10 == 11) { + auto prev_val = det.getFilterCell(); + { + std::ostringstream oss; + proxy.Call("filtercell", {"1"}, -1, PUT, oss); + REQUIRE(oss.str() == "filtercell 1\n"); + } + { + std::ostringstream oss; + proxy.Call("filtercell", {"12"}, -1, PUT, oss); + REQUIRE(oss.str() == "filtercell 12\n"); + } + { + std::ostringstream oss; + proxy.Call("filtercell", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "filtercell 0\n"); + } + { + std::ostringstream oss; + proxy.Call("filtercell", {}, -1, GET, oss); + REQUIRE(oss.str() == "filtercell 0\n"); + } + REQUIRE_THROWS(proxy.Call("filtercell", {"13"}, -1, PUT)); + for (int i = 0; i != det.size(); ++i) { + det.setFilterCell(prev_val[i], {i}); + } + } + // chip version 1.0 + else { + // cannot set/get filter cell + REQUIRE_THROWS(proxy.Call("filtercell", {"1"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("filtercell", {}, -1, GET)); + } + } else { + REQUIRE_THROWS(proxy.Call("filtercell", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("filtercell", {"0"}, -1, PUT)); + } +} diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index b0cf8446f..c1e101a95 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -142,15 +142,35 @@ TEST_CASE("settings", "[.cmd]") { Detector det; CmdProxy proxy(&det); auto det_type = det.getDetectorType().squash(); + std::vector allSett; + allSett.push_back("standard"); + allSett.push_back("fast"); + allSett.push_back("highgain"); + allSett.push_back("dynamicgain"); + allSett.push_back("lowgain"); + allSett.push_back("mediumgain"); + allSett.push_back("veryhighgain"); + allSett.push_back("highgain0"); + allSett.push_back("fixgain1"); + allSett.push_back("fixgain2"); + allSett.push_back("verylowgain"); + allSett.push_back("g1_hg"); + allSett.push_back("g1_lg"); + allSett.push_back("g2_hc_hg"); + allSett.push_back("g2_hc_lg"); + allSett.push_back("g2_lc_hg"); + allSett.push_back("g2_lc_lg"); + allSett.push_back("g4_hg"); + allSett.push_back("g4_lg"); + allSett.push_back("forceswitchg1"); + allSett.push_back("forceswitchg2"); + allSett.push_back("gain0"); + std::vector sett; switch (det_type) { case defs::JUNGFRAU: - sett.push_back("dynamicgain"); - sett.push_back("dynamichg0"); - sett.push_back("fixgain1"); - sett.push_back("fixgain2"); - sett.push_back("forceswitchg1"); - sett.push_back("forceswitchg2"); + sett.push_back("gain0"); + sett.push_back("highgain0"); break; case defs::GOTTHARD: sett.push_back("highgain"); @@ -203,6 +223,11 @@ TEST_CASE("settings", "[.cmd]") { REQUIRE(oss.str() == "settings " + it + "\n"); } } + for (auto &it : allSett) { + if (std::find(sett.begin(), sett.end(), it) == sett.end()) { + REQUIRE_THROWS(proxy.Call("settings", {it}, -1, PUT)); + } + } for (int i = 0; i != det.size(); ++i) { if (prev_val[i] != defs::UNDEFINED && prev_val[i] != defs::UNINITIALIZED) { @@ -485,6 +510,34 @@ TEST_CASE("gappixels", "[.cmd]") { } } +TEST_CASE("fliprows", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::EIGER || det_type == defs::JUNGFRAU) { + auto previous = det.getFlipRows(); + auto previous_numudp = det.getNumberofUDPInterfaces(); + if (det_type == defs::JUNGFRAU) { + det.setNumberofUDPInterfaces(2); + } + std::ostringstream oss1, oss2, oss3; + proxy.Call("fliprows", {"1"}, -1, PUT, oss1); + REQUIRE(oss1.str() == "fliprows 1\n"); + proxy.Call("fliprows", {}, -1, GET, oss2); + REQUIRE(oss2.str() == "fliprows 1\n"); + proxy.Call("fliprows", {"0"}, -1, PUT, oss3); + REQUIRE(oss3.str() == "fliprows 0\n"); + for (int i = 0; i != det.size(); ++i) { + det.setFlipRows(previous[i], {i}); + if (det_type == defs::JUNGFRAU) { + det.setNumberofUDPInterfaces(previous_numudp[i], {i}); + } + } + } else { + REQUIRE_THROWS(proxy.Call("fliprows", {}, -1, GET)); + } +} + /* acquisition parameters */ // acquire: not testing @@ -1326,6 +1379,187 @@ TEST_CASE("parallel", "[.cmd]") { } } +TEST_CASE("filterresistor", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + + // only for chipv1.1 + bool chip11 = false; + if (det_type == defs::JUNGFRAU && + det.getChipVersion().squash() * 10 == 11) { + chip11 = true; + } + + if (det_type == defs::GOTTHARD2 || chip11) { + auto prev_val = det.getFilterResistor(); + { + std::ostringstream oss; + proxy.Call("filterresistor", {"1"}, -1, PUT, oss); + REQUIRE(oss.str() == "filterresistor 1\n"); + } + { + std::ostringstream oss; + proxy.Call("filterresistor", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "filterresistor 0\n"); + } + { + std::ostringstream oss; + proxy.Call("filterresistor", {}, -1, GET, oss); + REQUIRE(oss.str() == "filterresistor 0\n"); + } + if (det_type == defs::GOTTHARD2) { + REQUIRE_NOTHROW(proxy.Call("filterresistor", {"2"}, -1, PUT)); + REQUIRE_NOTHROW(proxy.Call("filterresistor", {"3"}, -1, PUT)); + } else { + REQUIRE_THROWS(proxy.Call("filterresistor", {"2"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("filterresistor", {"3"}, -1, PUT)); + } + for (int i = 0; i != det.size(); ++i) { + det.setFilterResistor(prev_val[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("filterresistor", {}, -1, GET)); + } +} + +TEST_CASE("currentsource", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + + if (det_type == defs::GOTTHARD2 || det_type == defs::JUNGFRAU) { + auto prev_val = det.getCurrentSource(); + + if (det_type == defs::GOTTHARD2) { + { + std::ostringstream oss; + proxy.Call("currentsource", {"1"}, -1, PUT, oss); + REQUIRE(oss.str() == "currentsource 1\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "currentsource 0\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {}, -1, GET, oss); + REQUIRE(oss.str() == "currentsource 0\n"); + } + REQUIRE_THROWS( + proxy.Call("currentsource", {"1", "fix", "42"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("currentsource", + {"1", "fix", "42", "normal"}, -1, PUT)); + } + // jungfrau + else { + int chipVersion = det.getChipVersion().tsquash( + "inconsistent chip versions to test") * + 10; + if (chipVersion == 10) { + REQUIRE_THROWS(proxy.Call("currentsource", {"1"}, -1, PUT)); + REQUIRE_THROWS( + proxy.Call("currentsource", {"1", "fix"}, -1, PUT)); + REQUIRE_THROWS( + proxy.Call("currentsource", {"1", "fix", "64"}, -1, PUT)); + REQUIRE_THROWS( + proxy.Call("currentsource", {"1", "dfg", "64"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call( + "currentsource", {"1", "fix", "63", "normal"}, -1, PUT)); + { + std::ostringstream oss; + proxy.Call("currentsource", {"1", "fix", "63"}, -1, PUT, + oss); + REQUIRE(oss.str() == "currentsource [1, fix, 63]\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "currentsource [0]\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {}, -1, GET, oss); + REQUIRE(oss.str() == "currentsource [disabled]\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {"1", "nofix", "63"}, -1, PUT, + oss); + REQUIRE(oss.str() == "currentsource [1, nofix, 63]\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {}, -1, GET, oss); + REQUIRE(oss.str() == + "currentsource [enabled, nofix, 63]\n"); + } + } + // chipv1.1 + else { + REQUIRE_THROWS(proxy.Call("currentsource", {"1"}, -1, PUT)); + REQUIRE_THROWS( + proxy.Call("currentsource", {"1", "fix"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call( + "currentsource", {"1", "ffgdfgix", "0x0000000000000041"}, + -1, PUT)); + REQUIRE_THROWS(proxy.Call( + "currentsource", + {"1", "fix", "0x0000000000000041", "normaldgf"}, -1, PUT)); + + { + std::ostringstream oss; + proxy.Call("currentsource", + {"1", "fix", "0x0000000000000041", "normal"}, -1, + PUT, oss); + REQUIRE( + oss.str() == + "currentsource [1, fix, 0x0000000000000041, normal]\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "currentsource [0]\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {}, -1, GET, oss); + REQUIRE(oss.str() == "currentsource [disabled]\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", + {"1", "nofix", "0x0000000000000041", "normal"}, + -1, PUT, oss); + REQUIRE(oss.str() == "currentsource [1, nofix, " + "0x0000000000000041, normal]\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", {}, -1, GET, oss); + REQUIRE(oss.str() == "currentsource [enabled, nofix, " + "0x0000000000000041, normal]\n"); + } + { + std::ostringstream oss; + proxy.Call("currentsource", + {"1", "nofix", "0x0000000000000041", "low"}, -1, + PUT, oss); + REQUIRE( + oss.str() == + "currentsource [1, nofix, 0x0000000000000041, low]\n"); + } + } + } + for (int i = 0; i != det.size(); ++i) { + det.setCurrentSource(prev_val[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("currentsource", {}, -1, GET)); + } +} + /** temperature */ TEST_CASE("templist", "[.cmd]") { @@ -1389,16 +1623,84 @@ TEST_CASE("dacvalues", "[.cmd]") { REQUIRE_THROWS(proxy.Call("dacvalues", {}, -1, PUT)); } -TEST_CASE("defaultdacs", "[.cmd]") { +TEST_CASE("defaultdac", "[.cmd]") { Detector det; CmdProxy proxy(&det); auto det_type = det.getDetectorType().squash(); if (det_type != defs::CHIPTESTBOARD) { - REQUIRE_THROWS(proxy.Call("defaultdacs", {}, -1, GET)); - REQUIRE_NOTHROW(proxy.Call("defaultdacs", {}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("defaultdac", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("defaultdac", {"blabla"}, -1, PUT)); + auto daclist = det.getDacList(); + for (auto it : daclist) { + auto dacname = sls::ToString(it); + auto prev_val = det.getDefaultDac(it); + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname, "1000"}, -1, PUT, oss); + REQUIRE(oss.str() == std::string("defaultdac ") + dacname + + std::string(" 1000\n")); + } + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname}, -1, GET, oss); + REQUIRE(oss.str() == std::string("defaultdac ") + dacname + + std::string(" 1000\n")); + } + for (int i = 0; i != det.size(); ++i) { + det.setDefaultDac(it, prev_val[i], {i}); + } + } + if (det_type == defs::JUNGFRAU) { + std::vector daclist = {defs::VB_COMP, defs::VREF_DS, + defs::VREF_COMP}; + for (auto it : daclist) { + auto dacname = sls::ToString(it); + auto prev_val = det.getDefaultDac(it, defs::DYNAMICGAIN); + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname, "1000", "dynamicgain"}, -1, + PUT, oss); + REQUIRE(oss.str() == + std::string("defaultdac ") + dacname + + std::string(" dynamicgain 1000\n")); + } + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname, "dynamicgain"}, -1, GET, + oss); + REQUIRE(oss.str() == + std::string("defaultdac ") + dacname + + std::string(" dynamicgain 1000\n")); + } + for (int i = 0; i != det.size(); ++i) { + det.setDefaultDac(it, prev_val[i], defs::DYNAMICGAIN, {i}); + } + } + } } else { - REQUIRE_THROWS(proxy.Call("defaultdacs", {}, -1, GET)); - REQUIRE_THROWS(proxy.Call("defaultdacs", {}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("defaultdac", {}, -1, GET)); + } +} + +TEST_CASE("resetdacs", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type != defs::CHIPTESTBOARD) { + auto prev_val = det.getSettings(); + + REQUIRE_THROWS(proxy.Call("resetdacs", {}, -1, GET)); + REQUIRE_NOTHROW(proxy.Call("resetdacs", {}, -1, PUT)); + REQUIRE_NOTHROW(proxy.Call("resetdacs", {"hard"}, -1, PUT)); + + // settings should not change especially for jungfrau and m3 + auto next_val = det.getSettings(); + for (int i = 0; i != det.size(); ++i) { + REQUIRE(prev_val[i] == next_val[i]); + } + } else { + REQUIRE_THROWS(proxy.Call("resetdacs", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("resetdacs", {}, -1, PUT)); } } diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index d882ba1d8..4dc63e33f 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -156,7 +156,8 @@ int ClientInterface::functionTable(){ flist[F_SET_RECEIVER_STREAMING] = &ClientInterface::set_streaming; flist[F_GET_RECEIVER_STREAMING] = &ClientInterface::get_streaming; flist[F_RECEIVER_STREAMING_TIMER] = &ClientInterface::set_streaming_timer; - flist[F_SET_FLIPPED_DATA_RECEIVER] = &ClientInterface::set_flipped_data; + flist[F_GET_FLIP_ROWS_RECEIVER] = &ClientInterface::get_flip_rows; + flist[F_SET_FLIP_ROWS_RECEIVER] = &ClientInterface::set_flip_rows; flist[F_SET_RECEIVER_FILE_FORMAT] = &ClientInterface::set_file_format; flist[F_GET_RECEIVER_FILE_FORMAT] = &ClientInterface::get_file_format; flist[F_SET_RECEIVER_STREAMING_PORT] = &ClientInterface::set_streaming_port; @@ -1020,21 +1021,33 @@ int ClientInterface::set_streaming_timer(Interface &socket) { return socket.sendResult(retval); } -int ClientInterface::set_flipped_data(Interface &socket) { +int ClientInterface::get_flip_rows(Interface &socket) { + if (myDetectorType != EIGER) + functionNotImplemented(); + + int retval = impl()->getFlipRows(); + LOG(logDEBUG1) << "Flip rows:" << retval; + return socket.sendResult(retval); +} + +int ClientInterface::set_flip_rows(Interface &socket) { auto arg = socket.Receive(); if (myDetectorType != EIGER) functionNotImplemented(); - if (arg >= 0) { - verifyIdle(socket); - LOG(logDEBUG1) << "Setting flipped data:" << arg; - impl()->setFlippedDataX(arg); + if (arg != 0 && arg != 1) { + throw RuntimeError("Could not set flip rows. Invalid argument: " + + std::to_string(arg)); } - int retval = impl()->getFlippedDataX(); - validate(arg, retval, std::string("set flipped data"), DEC); - LOG(logDEBUG1) << "Flipped Data:" << retval; - return socket.sendResult(retval); + verifyIdle(socket); + LOG(logDEBUG1) << "Setting flip rows:" << arg; + impl()->setFlipRows(static_cast(arg)); + + int retval = impl()->getFlipRows(); + validate(arg, retval, std::string("set flip rows"), DEC); + LOG(logDEBUG1) << "Flip rows:" << retval; + return socket.sendResult(retval); } int ClientInterface::set_file_format(Interface &socket) { diff --git a/slsReceiverSoftware/src/ClientInterface.h b/slsReceiverSoftware/src/ClientInterface.h index 64ed796c0..113bc77a8 100644 --- a/slsReceiverSoftware/src/ClientInterface.h +++ b/slsReceiverSoftware/src/ClientInterface.h @@ -107,7 +107,8 @@ class ClientInterface : private virtual slsDetectorDefs { int set_streaming(sls::ServerInterface &socket); int get_streaming(sls::ServerInterface &socket); int set_streaming_timer(sls::ServerInterface &socket); - int set_flipped_data(sls::ServerInterface &socket); + int get_flip_rows(sls::ServerInterface &socket); + int set_flip_rows(sls::ServerInterface &socket); int set_file_format(sls::ServerInterface &socket); int get_file_format(sls::ServerInterface &socket); int set_streaming_port(sls::ServerInterface &socket); diff --git a/slsReceiverSoftware/src/DataStreamer.cpp b/slsReceiverSoftware/src/DataStreamer.cpp index 86b41112f..d5ad9763e 100644 --- a/slsReceiverSoftware/src/DataStreamer.cpp +++ b/slsReceiverSoftware/src/DataStreamer.cpp @@ -15,9 +15,9 @@ const std::string DataStreamer::TypeName = "DataStreamer"; DataStreamer::DataStreamer(int ind, Fifo *f, uint32_t *dr, ROI *r, uint64_t *fi, - int fd, int *nm, bool *qe, uint64_t *tot) + bool fr, int *nm, bool *qe, uint64_t *tot) : ThreadObject(ind, TypeName), fifo(f), dynamicRange(dr), roi(r), - fileIndex(fi), flippedDataX(fd), quadEnable(qe), totalNumFrames(tot) { + fileIndex(fi), flipRows(fr), quadEnable(qe), totalNumFrames(tot) { numMods[0] = nm[0]; numMods[1] = nm[1]; @@ -65,7 +65,7 @@ void DataStreamer::SetNumberofModules(int *nm) { numMods[1] = nm[1]; } -void DataStreamer::SetFlippedDataX(int fd) { flippedDataX = fd; } +void DataStreamer::SetFlipRows(bool fd) { flipRows = fd; } void DataStreamer::SetAdditionalJsonHeader( const std::map &json) { @@ -240,7 +240,7 @@ int DataStreamer::SendHeader(sls_receiver_header *rheader, uint32_t size, zHeader.roundRNumber = header.roundRNumber; zHeader.detType = header.detType; zHeader.version = header.version; - zHeader.flippedDataX = flippedDataX; + zHeader.flipRows = static_cast(flipRows); zHeader.quad = *quadEnable; zHeader.completeImage = (header.packetNumber < generalData->packetsPerFrame ? false : true); diff --git a/slsReceiverSoftware/src/DataStreamer.h b/slsReceiverSoftware/src/DataStreamer.h index 45d4c0839..da598ebd3 100644 --- a/slsReceiverSoftware/src/DataStreamer.h +++ b/slsReceiverSoftware/src/DataStreamer.h @@ -30,12 +30,12 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject { * @param dr pointer to dynamic range * @param r roi * @param fi pointer to file index - * @param fd flipped data enable for x dimension + * @param fr flip rows * @param nm pointer to number of modules in each dimension * @param qe pointer to quad Enable * @param tot pointer to total number of frames */ - DataStreamer(int ind, Fifo *f, uint32_t *dr, ROI *r, uint64_t *fi, int fd, + DataStreamer(int ind, Fifo *f, uint32_t *dr, ROI *r, uint64_t *fi, bool fr, int *nm, bool *qe, uint64_t *tot); /** @@ -68,10 +68,10 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject { void SetNumberofModules(int *nm); /** - * Set Flipped data enable across x dimension - * @param fd data enable in x dimension + * Set Flipped rows + * @param fd flip rows enable */ - void SetFlippedDataX(int fd); + void SetFlipRows(bool fd); /** * Set additional json header @@ -165,8 +165,8 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject { /** Pointer to file index */ uint64_t *fileIndex; - /** flipped data across x axis */ - int flippedDataX; + /** flip rows */ + bool flipRows; /** additional json header */ std::map additionalJsonHeader; diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 1a8bdbefc..719ca8eb7 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -893,15 +893,15 @@ void Implementation::setNumberofUDPInterfaces(const int n) { // streamer threads if (dataStreamEnable) { try { - int fd = flippedDataX; + bool flip = flipRows; int nm[2] = {numMods[0], numMods[1]}; if (quadEnable) { - fd = i; + flip = (i == 1 ? true : false); nm[0] = 1; nm[1] = 2; } dataStreamer.push_back(sls::make_unique( - i, fifo[i].get(), &dynamicRange, &roi, &fileIndex, fd, + i, fifo[i].get(), &dynamicRange, &roi, &fileIndex, flip, (int *)nm, &quadEnable, &numberOfTotalFrames)); dataStreamer[i]->SetGeneralData(generalData); dataStreamer[i]->CreateZmqSockets( @@ -1022,15 +1022,15 @@ void Implementation::setDataStreamEnable(const bool enable) { if (enable) { for (int i = 0; i < numThreads; ++i) { try { - int fd = flippedDataX; + bool flip = flipRows; int nm[2] = {numMods[0], numMods[1]}; if (quadEnable) { - fd = i; + flip = (i == 1 ? true : false); nm[0] = 1; nm[1] = 2; } dataStreamer.push_back(sls::make_unique( - i, fifo[i].get(), &dynamicRange, &roi, &fileIndex, fd, + i, fifo[i].get(), &dynamicRange, &roi, &fileIndex, flip, (int *)nm, &quadEnable, &numberOfTotalFrames)); dataStreamer[i]->SetGeneralData(generalData); dataStreamer[i]->CreateZmqSockets( @@ -1458,22 +1458,24 @@ void Implementation::setTenGigaEnable(const bool b) { LOG(logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame); } -int Implementation::getFlippedDataX() const { return flippedDataX; } +bool Implementation::getFlipRows() const { return flipRows; } -void Implementation::setFlippedDataX(int enable) { - flippedDataX = (enable == 0) ? 0 : 1; +void Implementation::setFlipRows(bool enable) { + flipRows = enable; if (!quadEnable) { for (const auto &it : dataStreamer) { - it->SetFlippedDataX(flippedDataX); - } - } else { - if (dataStreamer.size() == 2) { - dataStreamer[0]->SetFlippedDataX(0); - dataStreamer[1]->SetFlippedDataX(1); + it->SetFlipRows(flipRows); } } - LOG(logINFO) << "Flipped Data X: " << flippedDataX; + // quad + else { + if (dataStreamer.size() == 2) { + dataStreamer[0]->SetFlipRows(false); + dataStreamer[1]->SetFlipRows(true); + } + } + LOG(logINFO) << "Flip Rows: " << flipRows; } bool Implementation::getQuad() const { return quadEnable; } @@ -1485,7 +1487,7 @@ void Implementation::setQuad(const bool b) { if (!quadEnable) { for (const auto &it : dataStreamer) { it->SetNumberofModules(numMods); - it->SetFlippedDataX(flippedDataX); + it->SetFlipRows(flipRows); } } else { int size[2] = {1, 2}; @@ -1493,8 +1495,8 @@ void Implementation::setQuad(const bool b) { it->SetNumberofModules(size); } if (dataStreamer.size() == 2) { - dataStreamer[0]->SetFlippedDataX(0); - dataStreamer[1]->SetFlippedDataX(1); + dataStreamer[0]->SetFlipRows(false); + dataStreamer[1]->SetFlipRows(true); } } } diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index 5a1650705..b711c68d2 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -202,8 +202,8 @@ class Implementation : private virtual slsDetectorDefs { bool getTenGigaEnable() const; /* [Eiger][Ctb] */ void setTenGigaEnable(const bool b); - int getFlippedDataX() const; - void setFlippedDataX(int enable = -1); + bool getFlipRows() const; + void setFlipRows(bool enable); bool getQuad() const; /* [Eiger] */ void setQuad(const bool b); @@ -347,7 +347,7 @@ class Implementation : private virtual slsDetectorDefs { uint32_t dynamicRange{16}; ROI roi{}; bool tengigaEnable{false}; - int flippedDataX{0}; + bool flipRows{false}; bool quadEnable{false}; bool activated{true}; std::array detectorDataStream = {{true, true}}; diff --git a/slsSupportLib/include/sls/ToString.h b/slsSupportLib/include/sls/ToString.h index d40b02ab9..0f18a6d4c 100644 --- a/slsSupportLib/include/sls/ToString.h +++ b/slsSupportLib/include/sls/ToString.h @@ -40,6 +40,7 @@ std::string ToString(const defs::M3_GainCaps s); std::string ToString(const defs::portPosition s); std::string ToString(const defs::streamingInterface s); std::string ToString(const defs::vetoAlgorithm s); +std::string ToString(const defs::gainMode s); std::string ToString(const slsDetectorDefs::xy &coord); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::xy &coord); @@ -51,7 +52,12 @@ std::ostream &operator<<(std::ostream &os, std::string ToString(const slsDetectorDefs::scanParameters &r); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::scanParameters &r); +std::string ToString(const slsDetectorDefs::currentSrcParameters &r); +std::ostream &operator<<(std::ostream &os, + const slsDetectorDefs::currentSrcParameters &r); + const std::string &ToString(const std::string &s); + /** Convert std::chrono::duration with specified output unit */ template typename std::enable_if::value, std::string>::type @@ -305,6 +311,7 @@ template <> defs::M3_GainCaps StringTo(const std::string &s); template <> defs::portPosition StringTo(const std::string &s); template <> defs::streamingInterface StringTo(const std::string &s); template <> defs::vetoAlgorithm StringTo(const std::string &s); +template <> defs::gainMode StringTo(const std::string &s); template <> uint32_t StringTo(const std::string &s); template <> uint64_t StringTo(const std::string &s); diff --git a/slsSupportLib/include/sls/ZmqSocket.h b/slsSupportLib/include/sls/ZmqSocket.h index 713f59a73..e6914f5b5 100644 --- a/slsSupportLib/include/sls/ZmqSocket.h +++ b/slsSupportLib/include/sls/ZmqSocket.h @@ -58,8 +58,8 @@ struct zmqHeader { uint16_t roundRNumber{0}; uint8_t detType{0}; uint8_t version{0}; - /** if image should be flipped across x axis */ - int flippedDataX{0}; + /** if rows of image should be flipped */ + int flipRows{0}; /** quad type (eiger hardware specific) */ uint32_t quad{0}; /** true if complete image, else missing packets */ diff --git a/slsSupportLib/include/sls/sls_detector_defs.h b/slsSupportLib/include/sls/sls_detector_defs.h index b22a4bde4..59dfd0609 100644 --- a/slsSupportLib/include/sls/sls_detector_defs.h +++ b/slsSupportLib/include/sls/sls_detector_defs.h @@ -345,11 +345,9 @@ typedef struct { LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, - DYNAMICHG0, + HIGHGAIN0, FIXGAIN1, FIXGAIN2, - FORCESWITCHG1, - FORCESWITCHG2, VERYLOWGAIN, G1_HIGHGAIN, G1_LOWGAIN, @@ -359,6 +357,7 @@ typedef struct { G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN, + GAIN0, UNDEFINED = 200, UNINITIALIZED }; @@ -416,6 +415,15 @@ typedef struct { enum vetoAlgorithm { DEFAULT_ALGORITHM }; + enum gainMode { + DYNAMIC, + FORCE_SWITCH_G1, + FORCE_SWITCH_G2, + FIX_G1, + FIX_G2, + FIX_G0 + }; + #ifdef __cplusplus /** scan structure */ @@ -448,6 +456,39 @@ typedef struct { } } __attribute__((packed)); + struct currentSrcParameters { + int enable; + int fix; + int normal; + uint64_t select; + + /** [Gotthard2][Jungfrau] disable */ + currentSrcParameters() : enable(0), fix(-1), normal(-1), select(0) {} + + /** [Gotthard2] enable or disable */ + currentSrcParameters(bool ena) + : enable(static_cast(ena)), fix(-1), normal(-1), select(0) {} + + /** [Jungfrau](chipv1.0) enable current src with fix or no fix, + * selectColumn is 0 to 63 columns only */ + currentSrcParameters(bool fixCurrent, uint64_t selectColumn) + : enable(1), fix(static_cast(fixCurrent)), normal(-1), + select(selectColumn) {} + + /** [Jungfrau](chipv1.1) enable current src, fixCurrent[fix|no fix], + * selectColumn is a mask of 63 bits (muliple columns can be selected + * simultaneously, normalCurrent [normal|low] */ + currentSrcParameters(bool fixCurrent, uint64_t selectColumn, + bool normalCurrent) + : enable(1), fix(static_cast(fixCurrent)), + normal(static_cast(normalCurrent)), select(selectColumn) {} + + bool operator==(const currentSrcParameters &other) const { + return ((enable == other.enable) && (fix == other.fix) && + (normal == other.normal) && (select == other.select)); + } + } __attribute__((packed)); + /** * structure to udpate receiver */ diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index a81e69d7b..19748de11 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -205,8 +205,8 @@ enum detFuncs { F_GET_SCAN_ERROR_MESSAGE, F_GET_CDS_GAIN, F_SET_CDS_GAIN, - F_GET_FILTER, - F_SET_FILTER, + F_GET_FILTER_RESISTOR, + F_SET_FILTER_RESISTOR, F_GET_ADC_CONFIGURATION, F_SET_ADC_CONFIGURATION, F_GET_BAD_CHANNELS, @@ -215,7 +215,7 @@ enum detFuncs { F_VALIDATE_UDP_CONFIG, F_GET_BURSTS_LEFT, F_START_READOUT, - F_SET_DEFAULT_DACS, + F_RESET_TO_DEFAULT_DACS, F_IS_VIRTUAL, F_GET_PATTERN, F_LOAD_DEFAULT_PATTERN, @@ -230,6 +230,17 @@ enum detFuncs { F_SET_VETO_STREAM, F_GET_VETO_ALGORITHM, F_SET_VETO_ALGORITHM, + F_GET_CHIP_VERSION, + F_GET_DEFAULT_DAC, + F_SET_DEFAULT_DAC, + F_GET_GAIN_MODE, + F_SET_GAIN_MODE, + F_GET_COMP_DISABLE_TIME, + F_SET_COMP_DISABLE_TIME, + F_GET_FLIP_ROWS, + F_SET_FLIP_ROWS, + F_GET_FILTER_CELL, + F_SET_FILTER_CELL, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this @@ -280,7 +291,8 @@ enum detFuncs { F_SET_RECEIVER_STREAMING, F_GET_RECEIVER_STREAMING, F_RECEIVER_STREAMING_TIMER, - F_SET_FLIPPED_DATA_RECEIVER, + F_GET_FLIP_ROWS_RECEIVER, + F_SET_FLIP_ROWS_RECEIVER, F_SET_RECEIVER_FILE_FORMAT, F_GET_RECEIVER_FILE_FORMAT, F_SET_RECEIVER_STREAMING_PORT, @@ -542,8 +554,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_GET_SCAN_ERROR_MESSAGE: return "F_GET_SCAN_ERROR_MESSAGE"; case F_GET_CDS_GAIN: return "F_GET_CDS_GAIN"; case F_SET_CDS_GAIN: return "F_SET_CDS_GAIN"; - case F_GET_FILTER: return "F_GET_FILTER"; - case F_SET_FILTER: return "F_SET_FILTER"; + case F_GET_FILTER_RESISTOR: return "F_GET_FILTER_RESISTOR"; + case F_SET_FILTER_RESISTOR: return "F_SET_FILTER_RESISTOR"; case F_SET_ADC_CONFIGURATION: return "F_SET_ADC_CONFIGURATION"; case F_GET_ADC_CONFIGURATION: return "F_GET_ADC_CONFIGURATION"; case F_GET_BAD_CHANNELS: return "F_GET_BAD_CHANNELS"; @@ -552,7 +564,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_VALIDATE_UDP_CONFIG: return "F_VALIDATE_UDP_CONFIG"; case F_GET_BURSTS_LEFT: return "F_GET_BURSTS_LEFT"; case F_START_READOUT: return "F_START_READOUT"; - case F_SET_DEFAULT_DACS: return "F_SET_DEFAULT_DACS"; + case F_RESET_TO_DEFAULT_DACS: return "F_RESET_TO_DEFAULT_DACS"; case F_IS_VIRTUAL: return "F_IS_VIRTUAL"; case F_GET_PATTERN: return "F_GET_PATTERN"; case F_LOAD_DEFAULT_PATTERN: return "F_LOAD_DEFAULT_PATTERN"; @@ -566,6 +578,17 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_VETO_STREAM: return "F_SET_VETO_STREAM"; case F_GET_VETO_ALGORITHM: return "F_GET_VETO_ALGORITHM"; case F_SET_VETO_ALGORITHM: return "F_SET_VETO_ALGORITHM"; + case F_GET_CHIP_VERSION: return "F_GET_CHIP_VERSION"; + case F_GET_DEFAULT_DAC: return "F_GET_DEFAULT_DAC"; + 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 F_GET_FLIP_ROWS: return "F_GET_FLIP_ROWS"; + case F_SET_FLIP_ROWS: return "F_SET_FLIP_ROWS"; + case F_GET_FILTER_CELL: return "F_GET_FILTER_CELL"; + case F_SET_FILTER_CELL: return "F_SET_FILTER_CELL"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; @@ -615,7 +638,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_RECEIVER_STREAMING: return "F_SET_RECEIVER_STREAMING"; case F_GET_RECEIVER_STREAMING: return "F_GET_RECEIVER_STREAMING"; case F_RECEIVER_STREAMING_TIMER: return "F_RECEIVER_STREAMING_TIMER"; - case F_SET_FLIPPED_DATA_RECEIVER: return "F_SET_FLIPPED_DATA_RECEIVER"; + case F_GET_FLIP_ROWS_RECEIVER: return "F_GET_FLIP_ROWS_RECEIVER"; + case F_SET_FLIP_ROWS_RECEIVER: return "F_SET_FLIP_ROWS_RECEIVER"; case F_SET_RECEIVER_FILE_FORMAT: return "F_SET_RECEIVER_FILE_FORMAT"; case F_GET_RECEIVER_FILE_FORMAT: return "F_GET_RECEIVER_FILE_FORMAT"; case F_SET_RECEIVER_STREAMING_PORT: return "F_SET_RECEIVER_STREAMING_PORT"; diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index b1f2968a6..9b2eed217 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -3,10 +3,11 @@ #define APILIB 0x210225 #define APIRECEIVER 0x210225 #define APIGUI 0x210225 -#define APICTB 0x210810 -#define APIGOTTHARD 0x210810 -#define APIGOTTHARD2 0x210810 -#define APIJUNGFRAU 0x210810 -#define APIMYTHEN3 0x210810 -#define APIMOENCH 0x210810 -#define APIEIGER 0x210810 + +#define APIEIGER 0x210811 +#define APICTB 0x210811 +#define APIGOTTHARD 0x210811 +#define APIGOTTHARD2 0x210811 +#define APIJUNGFRAU 0x210811 +#define APIMYTHEN3 0x210811 +#define APIMOENCH 0x210811 diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index 64efa75f6..b07d0d9ff 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -114,6 +114,40 @@ std::ostream &operator<<(std::ostream &os, return os << ToString(r); } +std::string ToString(const slsDetectorDefs::currentSrcParameters &r) { + std::ostringstream oss; + if (r.fix < -1 || r.fix > 1 || r.normal < -1 || r.normal > 1) { + throw sls::RuntimeError( + "Invalid current source parameters. Cannot print."); + } + oss << '['; + if (r.enable) { + oss << "enabled"; + // [jungfrau] + if (r.fix != -1) { + oss << (r.fix == 1 ? ", fix" : ", nofix"); + } + // [jungfrau chip v1.1] + if (r.normal != -1) { + oss << ", " << ToStringHex(r.select, 16); + oss << (r.normal == 1 ? ", normal" : ", low"); + } + // [jungfrau chip v1.0] + else { + oss << ", " << r.select; + } + } else { + oss << "disabled"; + } + oss << ']'; + return oss.str(); +} + +std::ostream &operator<<(std::ostream &os, + const slsDetectorDefs::currentSrcParameters &r) { + return os << ToString(r); +} + std::string ToString(const defs::runStatus s) { switch (s) { case defs::ERROR: @@ -170,16 +204,12 @@ std::string ToString(const defs::detectorSettings s) { return std::string("mediumgain"); case defs::VERYHIGHGAIN: return std::string("veryhighgain"); - case defs::DYNAMICHG0: - return std::string("dynamichg0"); + case defs::HIGHGAIN0: + return std::string("highgain0"); case defs::FIXGAIN1: return std::string("fixgain1"); case defs::FIXGAIN2: return std::string("fixgain2"); - case defs::FORCESWITCHG1: - return std::string("forceswitchg1"); - case defs::FORCESWITCHG2: - return std::string("forceswitchg2"); case defs::VERYLOWGAIN: return std::string("verylowgain"); case defs::G1_HIGHGAIN: @@ -198,6 +228,8 @@ std::string ToString(const defs::detectorSettings s) { return std::string("g4_hg"); case defs::G4_LOWGAIN: return std::string("g4_lg"); + case defs::GAIN0: + return std::string("gain0"); case defs::UNDEFINED: return std::string("undefined"); case defs::UNINITIALIZED: @@ -583,6 +615,25 @@ std::string ToString(const defs::vetoAlgorithm s) { } } +std::string ToString(const defs::gainMode s) { + switch (s) { + case defs::DYNAMIC: + return std::string("dynamic"); + case defs::FORCE_SWITCH_G1: + return std::string("forceswitchg1"); + case defs::FORCE_SWITCH_G2: + return std::string("forceswitchg2"); + case defs::FIX_G1: + return std::string("fixg1"); + case defs::FIX_G2: + return std::string("fixg2"); + case defs::FIX_G0: + return std::string("fixg0"); + default: + return std::string("Unknown"); + } +} + const std::string &ToString(const std::string &s) { return s; } template <> defs::detectorType StringTo(const std::string &s) { @@ -618,16 +669,12 @@ template <> defs::detectorSettings StringTo(const std::string &s) { return defs::MEDIUMGAIN; if (s == "veryhighgain") return defs::VERYHIGHGAIN; - if (s == "dynamichg0") - return defs::DYNAMICHG0; + if (s == "highgain0") + return defs::HIGHGAIN0; if (s == "fixgain1") return defs::FIXGAIN1; if (s == "fixgain2") return defs::FIXGAIN2; - if (s == "forceswitchg1") - return defs::FORCESWITCHG1; - if (s == "forceswitchg2") - return defs::FORCESWITCHG2; if (s == "verylowgain") return defs::VERYLOWGAIN; if (s == "g1_hg") @@ -644,6 +691,8 @@ template <> defs::detectorSettings StringTo(const std::string &s) { return defs::G2_LOWCAP_LOWGAIN; if (s == "g4_hg") return defs::G4_HIGHGAIN; + if (s == "gain0") + return defs::GAIN0; if (s == "g4_lg") return defs::G4_LOWGAIN; throw sls::RuntimeError("Unknown setting " + s); @@ -970,6 +1019,22 @@ template <> defs::vetoAlgorithm StringTo(const std::string &s) { throw sls::RuntimeError("Unknown veto algorithm " + s); } +template <> defs::gainMode StringTo(const std::string &s) { + if (s == "dynamic") + return defs::DYNAMIC; + if (s == "forceswitchg1") + return defs::FORCE_SWITCH_G1; + if (s == "forceswitchg2") + return defs::FORCE_SWITCH_G2; + if (s == "fixg1") + return defs::FIX_G1; + if (s == "fixg2") + return defs::FIX_G2; + if (s == "fixg0") + return defs::FIX_G0; + throw sls::RuntimeError("Unknown gain mode " + s); +} + template <> uint32_t StringTo(const std::string &s) { int base = s.find("0x") != std::string::npos ? 16 : 10; return std::stoul(s, nullptr, base); diff --git a/slsSupportLib/src/ZmqSocket.cpp b/slsSupportLib/src/ZmqSocket.cpp index f044eb48a..58b9de525 100644 --- a/slsSupportLib/src/ZmqSocket.cpp +++ b/slsSupportLib/src/ZmqSocket.cpp @@ -160,7 +160,7 @@ int ZmqSocket::SendHeader(int index, zmqHeader header) { "\"version\":%u, " // additional stuff - "\"flippedDataX\":%u, " + "\"flipRows\":%u, " "\"quad\":%u" ; //"}\n"; @@ -177,7 +177,7 @@ int ZmqSocket::SendHeader(int index, zmqHeader header) { header.detType, header.version, // additional stuff - header.flippedDataX, header.quad); + header.flipRows, header.quad); if (!header.addJsonHeader.empty()) { strcat(header_buffer.get(), ", "); @@ -303,7 +303,7 @@ int ZmqSocket::ParseHeader(const int index, int length, char *buff, zHeader.detType = document["detType"].GetUint(); zHeader.version = document["version"].GetUint(); - zHeader.flippedDataX = document["flippedDataX"].GetUint(); + zHeader.flipRows = document["flipRows"].GetUint(); zHeader.quad = document["quad"].GetUint(); zHeader.completeImage = document["completeImage"].GetUint();