mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 03:10:02 +02:00
set bit and clear bit only verifies that bit (#746)
This commit is contained in:
parent
6834294437
commit
0a7fd0a51a
Binary file not shown.
Binary file not shown.
@ -932,6 +932,59 @@ int readRegister(uint32_t offset, uint32_t *retval) {
|
|||||||
#endif
|
#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 */
|
/* set parameters - dr, roi */
|
||||||
|
|
||||||
int setDynamicRange(int dr) {
|
int setDynamicRange(int dr) {
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -163,6 +163,9 @@ void resetToHardwareSettings();
|
|||||||
#ifdef EIGERD
|
#ifdef EIGERD
|
||||||
int writeRegister(uint32_t offset, uint32_t data);
|
int writeRegister(uint32_t offset, uint32_t data);
|
||||||
int readRegister(uint32_t offset, uint32_t *retval);
|
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
|
#elif GOTTHARDD
|
||||||
uint32_t writeRegister16And32(uint32_t offset,
|
uint32_t writeRegister16And32(uint32_t offset,
|
||||||
uint32_t data); // FIXME its not there in ctb
|
uint32_t data); // FIXME its not there in ctb
|
||||||
|
@ -310,3 +310,6 @@ int get_synchronization(int);
|
|||||||
int set_synchronization(int);
|
int set_synchronization(int);
|
||||||
int get_hardware_version(int);
|
int get_hardware_version(int);
|
||||||
int get_frontend_firmware_version(int);
|
int get_frontend_firmware_version(int);
|
||||||
|
int get_bit(int);
|
||||||
|
int set_bit(int);
|
||||||
|
int clear_bit(int);
|
||||||
|
@ -473,6 +473,9 @@ void function_table() {
|
|||||||
flist[F_SET_SYNCHRONIZATION] = &set_synchronization;
|
flist[F_SET_SYNCHRONIZATION] = &set_synchronization;
|
||||||
flist[F_GET_HARDWARE_VERSION] = &get_hardware_version;
|
flist[F_GET_HARDWARE_VERSION] = &get_hardware_version;
|
||||||
flist[F_GET_FRONTEND_FIRMWARE_VERSION] = &get_frontend_firmware_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
|
// check
|
||||||
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
||||||
@ -10236,4 +10239,136 @@ int get_frontend_firmware_version(int file_des) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
|
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));
|
||||||
}
|
}
|
@ -2747,29 +2747,18 @@ uint32_t Module::writeRegister(uint32_t addr, uint32_t val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Module::setBit(uint32_t addr, int n) {
|
void Module::setBit(uint32_t addr, int n) {
|
||||||
if (n < 0 || n > 31) {
|
uint32_t args[2] = {addr, static_cast<uint32_t>(n)};
|
||||||
throw RuntimeError("Bit number " + std::to_string(n) + " out of Range");
|
sendToDetectorStop(F_SET_BIT, args, nullptr);
|
||||||
} else {
|
|
||||||
uint32_t val = readRegister(addr);
|
|
||||||
writeRegister(addr, val | 1 << n);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::clearBit(uint32_t addr, int n) {
|
void Module::clearBit(uint32_t addr, int n) {
|
||||||
if (n < 0 || n > 31) {
|
uint32_t args[2] = {addr, static_cast<uint32_t>(n)};
|
||||||
throw RuntimeError("Bit number " + std::to_string(n) + " out of Range");
|
sendToDetectorStop(F_CLEAR_BIT, args, nullptr);
|
||||||
} else {
|
|
||||||
uint32_t val = readRegister(addr);
|
|
||||||
writeRegister(addr, val & ~(1 << n));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Module::getBit(uint32_t addr, int n) {
|
int Module::getBit(uint32_t addr, int n) {
|
||||||
if (n < 0 || n > 31) {
|
uint32_t args[2] = {addr, static_cast<uint32_t>(n)};
|
||||||
throw RuntimeError("Bit number " + std::to_string(n) + " out of Range");
|
return sendToDetectorStop<int>(F_GET_BIT, args);
|
||||||
} else {
|
|
||||||
return ((readRegister(addr) >> n) & 0x1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::executeFirmwareTest() { sendToDetector(F_SET_FIRMWARE_TEST); }
|
void Module::executeFirmwareTest() { sendToDetector(F_SET_FIRMWARE_TEST); }
|
||||||
|
@ -277,6 +277,9 @@ enum detFuncs {
|
|||||||
F_SET_SYNCHRONIZATION,
|
F_SET_SYNCHRONIZATION,
|
||||||
F_GET_HARDWARE_VERSION,
|
F_GET_HARDWARE_VERSION,
|
||||||
F_GET_FRONTEND_FIRMWARE_VERSION,
|
F_GET_FRONTEND_FIRMWARE_VERSION,
|
||||||
|
F_GET_BIT,
|
||||||
|
F_SET_BIT,
|
||||||
|
F_CLEAR_BIT,
|
||||||
|
|
||||||
NUM_DET_FUNCTIONS,
|
NUM_DET_FUNCTIONS,
|
||||||
RECEIVER_ENUM_START = 512, /**< detector function should not exceed this
|
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_SET_SYNCHRONIZATION: return "F_SET_SYNCHRONIZATION";
|
||||||
case F_GET_HARDWARE_VERSION: return "F_GET_HARDWARE_VERSION";
|
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_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 NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
|
||||||
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";
|
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
/** API versions */
|
/** API versions */
|
||||||
#define RELEASE "developer"
|
#define RELEASE "developer"
|
||||||
|
#define APILIB "developer 0x230224"
|
||||||
|
#define APIRECEIVER "developer 0x230224"
|
||||||
|
#define APIJUNGFRAU "developer 0x230515"
|
||||||
|
#define APIMOENCH "developer 0x230515"
|
||||||
#define APIGOTTHARD "developer 0x230224"
|
#define APIGOTTHARD "developer 0x230224"
|
||||||
#define APIGOTTHARD2 "developer 0x230224"
|
#define APIGOTTHARD2 "developer 0x230224"
|
||||||
#define APIMYTHEN3 "developer 0x230224"
|
#define APIMYTHEN3 "developer 0x230224"
|
||||||
#define APILIB "developer 0x230224"
|
|
||||||
#define APIRECEIVER "developer 0x230224"
|
|
||||||
#define APIEIGER "developer 0x230224"
|
#define APIEIGER "developer 0x230224"
|
||||||
#define APIJUNGFRAU "developer 0x230508"
|
|
||||||
#define APIMOENCH "developer 0x230508"
|
|
||||||
#define APICTB "developer 0x230523"
|
#define APICTB "developer 0x230523"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user