diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer deleted file mode 100755 index 1afb3757e..000000000 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and /dev/null differ diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index 3f8418bcb..c7b6df6b6 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 11f2d7155..aa73fc651 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -932,6 +932,59 @@ int readRegister(uint32_t offset, uint32_t *retval) { #endif } +int setBit(const uint32_t addr, const int nBit) { +#ifndef VIRTUAL + uint32_t regval = 0; + if (readRegister(addr, ®val) == FAIL) { + return FAIL; + } + uint32_t bitmask = (1 << nBit); + uint32_t val = regval | bitmask; + + sharedMemory_lockLocalLink(); + if (!Feb_Control_WriteRegister_BitMask(addr, val, bitmask)) { + sharedMemory_unlockLocalLink(); + return FAIL; + } + sharedMemory_unlockLocalLink(); +#endif + return OK; +} + +int clearBit(const uint32_t addr, const int nBit) { +#ifndef VIRTUAL + uint32_t regval = 0; + if (readRegister(addr, ®val) == FAIL) { + return FAIL; + } + uint32_t bitmask = (1 << nBit); + uint32_t val = regval & ~bitmask; + + sharedMemory_lockLocalLink(); + if (!Feb_Control_WriteRegister_BitMask(addr, val, bitmask)) { + sharedMemory_unlockLocalLink(); + return FAIL; + } + sharedMemory_unlockLocalLink(); +#endif + return OK; +} + +int getBit(const uint32_t addr, const int nBit, int *retval) { +#ifndef VIRTUAL + uint32_t regval = 0; + uint32_t bitmask = (1 << nBit); + sharedMemory_lockLocalLink(); + if (!Feb_Control_ReadRegister_BitMask(addr, ®val, bitmask)) { + sharedMemory_unlockLocalLink(); + return FAIL; + } + sharedMemory_unlockLocalLink(); + *retval = (regval >> nBit); +#endif + return OK; +} + /* set parameters - dr, roi */ int setDynamicRange(int dr) { diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index f30601627..90db1d4ee 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer index 0c52b5ea9..bb955bec3 100755 Binary files a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer and b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer differ diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index c0febc991..fb1183b2b 100755 Binary files a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer and b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer differ diff --git a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer index 6b7eede39..298c614db 100755 Binary files a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer and b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index adf9675fe..ee7e3b33d 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index a1f9ba6fe..2ae9ccac0 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -163,6 +163,9 @@ void resetToHardwareSettings(); #ifdef EIGERD int writeRegister(uint32_t offset, uint32_t data); int readRegister(uint32_t offset, uint32_t *retval); +int setBit(const uint32_t addr, int nBit); +int clearBit(const uint32_t addr, int nBit); +int getBit(const uint32_t addr, const int nBit, int *retval); #elif GOTTHARDD uint32_t writeRegister16And32(uint32_t offset, uint32_t data); // FIXME its not there in ctb diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index f18a0b141..b9f931049 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -310,3 +310,6 @@ int get_synchronization(int); int set_synchronization(int); int get_hardware_version(int); int get_frontend_firmware_version(int); +int get_bit(int); +int set_bit(int); +int clear_bit(int); diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index c6f05b37e..43a8ea2a4 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -473,6 +473,9 @@ void function_table() { flist[F_SET_SYNCHRONIZATION] = &set_synchronization; flist[F_GET_HARDWARE_VERSION] = &get_hardware_version; flist[F_GET_FRONTEND_FIRMWARE_VERSION] = &get_frontend_firmware_version; + flist[F_GET_BIT] = &get_bit; + flist[F_SET_BIT] = &set_bit; + flist[F_CLEAR_BIT] = &clear_bit; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -10236,4 +10239,136 @@ int get_frontend_firmware_version(int file_des) { } #endif return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); +} + +int set_bit(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + uint32_t args[2] = {-1, -1}; + + if (receiveData(file_des, args, sizeof(args), INT32) < 0) + return printSocketReadError(); + uint32_t addr = args[0]; + int nBit = (int)args[1]; + LOG(logDEBUG1, ("Setting bit %d of reg 0x%x\n", nBit, addr)); + + // only set + if (Server_VerifyLock() == OK) { + if (nBit < 0 || nBit > 31) { + ret = FAIL; + sprintf( + mess, + "Could not set bit. Bit nr %d out of range. Must be 0-31\n", + nBit); + LOG(logERROR, (mess)); + } else { +#ifdef EIGERD + ret = setBit(addr, nBit); + if (ret == FAIL) { +#else + uint32_t bitmask = (1 << nBit); +#ifdef GOTTHARDD + uint32_t val = readRegister16And32(addr) | bitmask; + uint32_t retval = writeRegister16And32(addr, val); +#else + uint32_t val = readRegister(addr) | bitmask; + uint32_t retval = writeRegister(addr, val); +#endif + if (!(retval & bitmask)) { + ret = FAIL; +#endif + sprintf(mess, "Could not set bit %d.\n", nBit); + LOG(logERROR, (mess)); + } + } + } + return Server_SendResult(file_des, INT32, NULL, 0); +} + +int clear_bit(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + uint32_t args[2] = {-1, -1}; + + if (receiveData(file_des, args, sizeof(args), INT32) < 0) + return printSocketReadError(); + uint32_t addr = args[0]; + int nBit = (int)args[1]; + LOG(logDEBUG1, ("Clearing bit %d of reg 0x%x\n", nBit, addr)); + + // only set + if (Server_VerifyLock() == OK) { + if (nBit < 0 || nBit > 31) { + ret = FAIL; + sprintf( + mess, + "Could not clear bit. Bit nr %d out of range. Must be 0-31\n", + nBit); + LOG(logERROR, (mess)); + } else { +#ifdef EIGERD + ret = clearBit(addr, nBit); + if (ret == FAIL) { +#else + uint32_t bitmask = (1 << nBit); +#ifdef GOTTHARDD + uint32_t val = readRegister16And32(addr) & ~bitmask; + uint32_t retval = writeRegister16And32(addr, val); +#else + uint32_t val = readRegister(addr) & ~bitmask; + uint32_t retval = writeRegister(addr, val); +#endif + if (retval & bitmask) { + ret = FAIL; +#endif + sprintf(mess, "Could not clear bit %d.\n", nBit); + LOG(logERROR, (mess)); + } + } + } + return Server_SendResult(file_des, INT32, NULL, 0); +} + +int get_bit(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + uint32_t args[2] = {-1, -1}; + int retval = 0; + + if (receiveData(file_des, args, sizeof(args), INT32) < 0) + return printSocketReadError(); + uint32_t addr = args[0]; + int nBit = (int)args[1]; + LOG(logDEBUG1, ("Getting bit %d of reg 0x%x\n", nBit, addr)); + + // only set + if (Server_VerifyLock() == OK) { + if (nBit < 0 || nBit > 31) { + ret = FAIL; + sprintf( + mess, + "Could not get bit. Bit nr %d out of range. Must be 0-31\n", + nBit); + LOG(logERROR, (mess)); + } else { +#ifdef EIGERD + ret = getBit(addr, nBit, &retval); + LOG(logDEBUG1, ("retval: %d\n", retval)); + if (ret == FAIL) { +#else +#ifdef GOTTHARDD + retval = readRegister16And32(addr); +#else + retval = readRegister(addr); +#endif + LOG(logDEBUG1, ("retval: %d\n", retval)); + if (retval & (1 << nBit)) { + ret = FAIL; +#endif + sprintf(mess, "Could not get bit %d.\n", nBit); + LOG(logERROR, (mess)); + } + } + } + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); } \ No newline at end of file diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index f7d437927..c783c1714 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -2747,29 +2747,18 @@ uint32_t Module::writeRegister(uint32_t addr, uint32_t val) { } void Module::setBit(uint32_t addr, int n) { - if (n < 0 || n > 31) { - throw RuntimeError("Bit number " + std::to_string(n) + " out of Range"); - } else { - uint32_t val = readRegister(addr); - writeRegister(addr, val | 1 << n); - } + uint32_t args[2] = {addr, static_cast(n)}; + sendToDetectorStop(F_SET_BIT, args, nullptr); } void Module::clearBit(uint32_t addr, int n) { - if (n < 0 || n > 31) { - throw RuntimeError("Bit number " + std::to_string(n) + " out of Range"); - } else { - uint32_t val = readRegister(addr); - writeRegister(addr, val & ~(1 << n)); - } + uint32_t args[2] = {addr, static_cast(n)}; + sendToDetectorStop(F_CLEAR_BIT, args, nullptr); } int Module::getBit(uint32_t addr, int n) { - if (n < 0 || n > 31) { - throw RuntimeError("Bit number " + std::to_string(n) + " out of Range"); - } else { - return ((readRegister(addr) >> n) & 0x1); - } + uint32_t args[2] = {addr, static_cast(n)}; + return sendToDetectorStop(F_GET_BIT, args); } void Module::executeFirmwareTest() { sendToDetector(F_SET_FIRMWARE_TEST); } diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index c776bed75..7443af1e8 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -277,6 +277,9 @@ enum detFuncs { F_SET_SYNCHRONIZATION, F_GET_HARDWARE_VERSION, F_GET_FRONTEND_FIRMWARE_VERSION, + F_GET_BIT, + F_SET_BIT, + F_CLEAR_BIT, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 512, /**< detector function should not exceed this @@ -657,6 +660,10 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_SYNCHRONIZATION: return "F_SET_SYNCHRONIZATION"; case F_GET_HARDWARE_VERSION: return "F_GET_HARDWARE_VERSION"; case F_GET_FRONTEND_FIRMWARE_VERSION: return "F_GET_FRONTEND_FIRMWARE_VERSION"; + case F_GET_BIT: return "F_GET_BIT"; + case F_SET_BIT: return "F_SET_BIT"; + case F_CLEAR_BIT: return "F_CLEAR_BIT"; + case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index ea6164157..79c9d3f00 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -2,12 +2,12 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package /** API versions */ #define RELEASE "developer" +#define APILIB "developer 0x230224" +#define APIRECEIVER "developer 0x230224" +#define APIJUNGFRAU "developer 0x230515" +#define APIMOENCH "developer 0x230515" #define APIGOTTHARD "developer 0x230224" #define APIGOTTHARD2 "developer 0x230224" #define APIMYTHEN3 "developer 0x230224" -#define APILIB "developer 0x230224" -#define APIRECEIVER "developer 0x230224" #define APIEIGER "developer 0x230224" -#define APIJUNGFRAU "developer 0x230508" -#define APIMOENCH "developer 0x230508" #define APICTB "developer 0x230523"