diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 346f2076a..3a30712b2 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -2101,59 +2101,68 @@ class Detector { /** Advanced user Function! \n * Goes to stop server. Hence, can be called while calling blocking * acquire(). \n [Eiger] Address is +0x100 for only left, +0x200 for only - * right. \n [Ctb][Xilinx_Ctb] If custom address name defined using - * setRegisterDefinition, RegisterAddress can be retrieved using - * getRegisterDefinition */ + * right.*/ Result readRegister(RegisterAddress addr, Positions pos = {}) const; - /** Advanced user Function! */ - [[deprecated("Use the overload taking RegisterAddress instead of " - "uint32_t")]] Result - readRegister(uint32_t addr, Positions pos = {}) const; - /** Advanced user Function! \n * Goes to stop server. Hence, can be called while calling blocking * acquire(). \n [Eiger] Address is +0x100 for only left, +0x200 for only - * right. \n [Ctb][Xilinx_Ctb]] If custom address name defined using - * setRegisterDefinition, RegisterAddress can be retrieved using - * getRegisterDefinition */ + * right.*/ void writeRegister(RegisterAddress addr, RegisterValue val, bool validate = false, Positions pos = {}); /** Advanced user Function! */ + void setBit(BitAddress addr, bool validate = false, Positions pos = {}); + + /** Advanced user Function!*/ + void clearBit(BitAddress addr, bool validate = false, Positions pos = {}); + + /** Advanced user Function! */ + Result getBit(BitAddress addr, Positions pos = {}) const; + + /** [CTB][Xilinx CTB] Advanced user Function! */ + Result readRegister(const std::string ®_name, + Positions pos = {}) const; + + /** [CTB][Xilinx CTB] Advanced user Function! */ + void writeRegister(const std::string ®_name, RegisterValue val, + bool validate = false, Positions pos = {}); + + /** [CTB][Xilinx CTB] Advanced user Function! */ + void setBit(const std::string &bit_name, bool validate = false, + Positions pos = {}); + + /** [CTB][Xilinx CTB] Advanced user Function! */ + void clearBit(const std::string &bit_name, bool validate = false, + Positions pos = {}); + + /** [CTB][Xilinx CTB] Advanced user Function! */ + Result getBit(const std::string &bit_name, Positions pos = {}) const; + + /** Deprecated Advanced user Function! */ + [[deprecated("Use the overload taking RegisterAddress instead of " + "uint32_t")]] Result + readRegister(uint32_t addr, Positions pos = {}) const; + + /** Deprecated Advanced user Function! */ [[deprecated("Use the overload taking RegisterAddress and RegisterValue " "instead of uint32_t")]] void writeRegister(uint32_t addr, uint32_t val, bool validate = false, Positions pos = {}); - /** Advanced user Function! \n - * [Ctb][Xilinx_Ctb] Bit position can be picked up from a custom name using - * getBitDefinition that was set up prior using setBitDefinition. */ - void setBit(BitAddress addr, bool validate = false, Positions pos = {}); - - /** Advanced user Function! */ + /** Deprecated Advanced user Function! */ [[deprecated("Use the overload taking BitAddress instead of uint32_t and " "int")]] void setBit(uint32_t addr, int bitnr, bool validate = false, Positions pos = {}); - /** Advanced user Function! \n - * [Ctb][Xilinx_Ctb] Bit position can be picked up from a custom name using - * getBitDefinition that was set up prior using setBitDefinition. */ - void clearBit(BitAddress addr, bool validate = false, Positions pos = {}); - - /** Advanced user Function! */ + /** Deprecated Advanced user Function! */ [[deprecated("Use the overload taking BitAddress instead of uint32_t and " "int")]] void clearBit(uint32_t addr, int bitnr, bool validate = false, Positions pos = {}); - /** Advanced user Function! \n - * [Ctb][Xilinx_Ctb] Bit position can be picked up from a custom name using - * getBitDefinition that was set up prior using setBitDefinition. */ - Result getBit(BitAddress addr, Positions pos = {}) const; - - /** Advanced user Function! */ + /** Deprecated Advanced user Function! */ [[deprecated("Use the overload taking BitAddress instead of uint32_t and " "int")]] Result getBit(uint32_t addr, int bitnr, Positions pos = {}) const; diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 009d3289d..7d59e80ff 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -2784,56 +2784,78 @@ void Detector::setUpdateMode(const bool updatemode, Positions pos) { } } -Result Detector::readRegister(uint32_t addr, Positions pos) const { - return pimpl->Parallel(&Module::readRegister, pos, addr); -} - -void Detector::writeRegister(uint32_t addr, uint32_t val, bool validate, - Positions pos) { - pimpl->Parallel(&Module::writeRegister, pos, addr, val, validate); -} - -void Detector::setBit(uint32_t addr, int bitnr, bool validate, Positions pos) { - pimpl->Parallel(&Module::setBit, pos, addr, bitnr, validate); -} - -void Detector::clearBit(uint32_t addr, int bitnr, bool validate, - Positions pos) { - pimpl->Parallel(&Module::clearBit, pos, addr, bitnr, validate); -} - -Result Detector::getBit(uint32_t addr, int bitnr, Positions pos) const { - return pimpl->Parallel(&Module::getBit, pos, addr, bitnr); -} - Result Detector::readRegister(RegisterAddress addr, Positions pos) const { - auto t = pimpl->Parallel(&Module::readRegister, pos, addr); - Result res; - for (const auto &val : t) { - res.push_back(RegisterValue(val)); - } - return res; + return pimpl->readRegister(addr, pos); } void Detector::writeRegister(RegisterAddress addr, RegisterValue val, bool validate, Positions pos) { - pimpl->Parallel(&Module::writeRegister, pos, addr, val, validate); + pimpl->writeRegister(addr, val, validate, pos); } void Detector::setBit(BitAddress addr, bool validate, Positions pos) { - pimpl->Parallel(&Module::setBit, pos, addr.address(), addr.bitPosition(), - validate); + pimpl->setBit(addr, validate, pos); } void Detector::clearBit(BitAddress addr, bool validate, Positions pos) { - pimpl->Parallel(&Module::clearBit, pos, addr.address(), addr.bitPosition(), - validate); + pimpl->clearBit(addr, validate, pos); } Result Detector::getBit(BitAddress addr, Positions pos) const { - return pimpl->Parallel(&Module::getBit, pos, addr.address(), - addr.bitPosition()); + return pimpl->getBit(addr, pos); +} + +Result Detector::readRegister(const std::string ®_name, + Positions pos) const { + return pimpl->readRegister(reg_name, pos); +} + +void Detector::writeRegister(const std::string ®_name, RegisterValue val, + bool validate, Positions pos) { + pimpl->writeRegister(reg_name, val, validate, pos); +} + +void Detector::setBit(const std::string &bit_name, bool validate, + Positions pos) { + pimpl->setBit(bit_name, validate, pos); +} + +void Detector::clearBit(const std::string &bit_name, bool validate, + Positions pos) { + pimpl->clearBit(bit_name, validate, pos); +} + +Result Detector::getBit(const std::string &bit_name, Positions pos) const { + return pimpl->getBit(bit_name, pos); +} + +Result Detector::readRegister(uint32_t addr, Positions pos) const { + auto t = pimpl->readRegister(RegisterAddress(addr), pos); + Result res; + for (const auto &val : t) { + res.push_back(val); + } + return res; +} + +void Detector::writeRegister(uint32_t addr, uint32_t val, bool validate, + Positions pos) { + pimpl->writeRegister(RegisterAddress(addr), RegisterValue(val), validate, + pos); +} + +void Detector::setBit(uint32_t addr, int bitnr, bool validate, Positions pos) { + pimpl->setBit(BitAddress(RegisterAddress(addr), bitnr), validate, pos); +} + +void Detector::clearBit(uint32_t addr, int bitnr, bool validate, + Positions pos) { + pimpl->clearBit(BitAddress(RegisterAddress(addr), bitnr), validate, pos); +} + +Result Detector::getBit(uint32_t addr, int bitnr, Positions pos) const { + return pimpl->getBit(BitAddress(RegisterAddress(addr), bitnr), pos); } void Detector::executeFirmwareTest(Positions pos) { diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index d737f19b0..b29f7c05c 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -2171,4 +2171,76 @@ std::map DetectorImpl::getBitDefinitions() const { return ctb_shm()->getBitNames(); } +Result DetectorImpl::readRegister(const std::string ®_name, + Positions pos) const { + if (!isChipTestBoard()) { + throw RuntimeError("Register Definitions only for CTB. Use hard coded " + "values instead."); + } + auto addr = getRegisterDefinition(reg_name); + return readRegister(addr, pos); +} + +void DetectorImpl::writeRegister(const std::string ®_name, RegisterValue val, + bool validate, Positions pos) { + if (!isChipTestBoard()) { + throw RuntimeError("Register Definitions only for CTB. Use hard coded " + "values instead."); + } + auto addr = getRegisterDefinition(reg_name); + writeRegister(addr, val, validate, pos); +} + +void DetectorImpl::setBit(const std::string &bit_name, bool validate, + Positions pos) { + if (!isChipTestBoard()) { + throw RuntimeError( + "Bit Definitions only for CTB. Use hard coded values instead."); + } + auto addr = getBitDefinition(bit_name); + setBit(addr, validate, pos); +} + +void DetectorImpl::clearBit(const std::string &bit_name, bool validate, + Positions pos) { + if (!isChipTestBoard()) { + throw RuntimeError( + "Bit Definitions only for CTB. Use hard coded values instead."); + } + auto addr = getBitDefinition(bit_name); + clearBit(addr, validate, pos); +} + +Result DetectorImpl::getBit(const std::string &bit_name, + Positions pos) const { + if (!isChipTestBoard()) { + throw RuntimeError( + "Bit Definitions only for CTB. Use hard coded values instead."); + } + auto addr = getBitDefinition(bit_name); + return getBit(addr, pos); +} + +Result DetectorImpl::readRegister(RegisterAddress addr, + Positions pos) const { + return Parallel(&Module::readRegister, pos, addr); +} + +void DetectorImpl::writeRegister(RegisterAddress addr, RegisterValue val, + bool validate, Positions pos) { + Parallel(&Module::writeRegister, pos, addr, val, validate); +} + +void DetectorImpl::setBit(BitAddress addr, bool validate, Positions pos) { + Parallel(&Module::setBit, pos, addr, validate); +} + +void DetectorImpl::clearBit(BitAddress addr, bool validate, Positions pos) { + Parallel(&Module::clearBit, pos, addr, validate); +} + +Result DetectorImpl::getBit(BitAddress addr, Positions pos) const { + return Parallel(&Module::getBit, pos, addr); +} + } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index adb377d4b..080442fc9 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -353,6 +353,22 @@ class DetectorImpl : public virtual slsDetectorDefs { void setBitDefinitions(const std::map &list); std::map getBitDefinitions() const; + Result readRegister(const std::string ®_name, + Positions pos) const; + void writeRegister(const std::string ®_name, RegisterValue val, + bool validate, Positions pos); + void setBit(const std::string &bit_name, bool validate, Positions pos); + void clearBit(const std::string &bit_name, bool validate, Positions pos); + Result getBit(const std::string &bit_name, Positions pos) const; + + Result readRegister(RegisterAddress addr, + Positions pos = {}) const; + void writeRegister(RegisterAddress addr, RegisterValue val, + bool validate = false, Positions pos = {}); + void setBit(BitAddress addr, bool validate = false, Positions pos = {}); + void clearBit(BitAddress addr, bool validate = false, Positions pos = {}); + Result getBit(BitAddress addr, Positions pos = {}) const; + private: /** * Creates/open shared memory, initializes detector structure and members diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 8076048fa..b13156eef 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -2915,29 +2915,33 @@ void Module::setUpdateMode(const bool updatemode) { << "): Update Mode set to " << updatemode << "!"; } -uint32_t Module::readRegister(uint32_t addr) const { - return sendToDetectorStop(F_READ_REGISTER, addr); +RegisterValue Module::readRegister(RegisterAddress addr) const { + return sendToDetectorStop(F_READ_REGISTER, addr); } -void Module::writeRegister(uint32_t addr, uint32_t val, bool validate) { +void Module::writeRegister(RegisterAddress addr, RegisterValue val, + bool validate) { uint32_t args[]{addr, val, static_cast(validate)}; return sendToDetectorStop(F_WRITE_REGISTER, args, nullptr); } -void Module::setBit(uint32_t addr, int n, bool validate) { - uint32_t args[] = {addr, static_cast(n), +void Module::setBit(BitAddress bitAddr, bool validate) { + uint32_t args[] = {bitAddr.address(), + static_cast(bitAddr.bitPosition()), static_cast(validate)}; sendToDetectorStop(F_SET_BIT, args, nullptr); } -void Module::clearBit(uint32_t addr, int n, bool validate) { - uint32_t args[] = {addr, static_cast(n), +void Module::clearBit(BitAddress bitAddr, bool validate) { + uint32_t args[] = {bitAddr.address(), + static_cast(bitAddr.bitPosition()), static_cast(validate)}; sendToDetectorStop(F_CLEAR_BIT, args, nullptr); } -int Module::getBit(uint32_t addr, int n) { - uint32_t args[2] = {addr, static_cast(n)}; +int Module::getBit(BitAddress bitAddr) const { + uint32_t args[2] = {bitAddr.address(), + static_cast(bitAddr.bitPosition())}; return sendToDetectorStop(F_GET_BIT, args); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index d1fd4a325..d23cc095e 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -5,6 +5,7 @@ #include "sls/ClientSocket.h" #include "sls/Pattern.h" #include "sls/StaticVector.h" +#include "sls/bit_utils.h" #include "sls/logger.h" #include "sls/network_utils.h" #include "sls/sls_detector_defs.h" @@ -579,11 +580,11 @@ class Module : public virtual slsDetectorDefs { void rebootController(); bool getUpdateMode() const; void setUpdateMode(const bool updatemode); - uint32_t readRegister(uint32_t addr) const; - void writeRegister(uint32_t addr, uint32_t val, bool validate); - void setBit(uint32_t addr, int n, bool validate); - void clearBit(uint32_t addr, int n, bool validate); - int getBit(uint32_t addr, int n); + RegisterValue readRegister(RegisterAddress addr) const; + void writeRegister(RegisterAddress addr, RegisterValue val, bool validate); + void setBit(BitAddress bitAddr, bool validate); + void clearBit(BitAddress bitAddr, bool validate); + int getBit(BitAddress bitAddr) const; void executeFirmwareTest(); void executeBusTest(); void writeAdcRegister(uint32_t addr, uint32_t val);