locking in list

This commit is contained in:
maliakal_d 2020-09-16 14:57:52 +02:00
parent 515a0c05b9
commit e91420bd16
3 changed files with 209 additions and 27 deletions

View File

@ -2,6 +2,7 @@
#include "Beb.h" #include "Beb.h"
#include "FebRegisterDefs.h" #include "FebRegisterDefs.h"
#include "clogger.h" #include "clogger.h"
#include "sharedMemory.h"
#include "slsDetectorServer_defs.h" #include "slsDetectorServer_defs.h"
#include <errno.h> #include <errno.h>
@ -752,16 +753,24 @@ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag) {
return 1; return 1;
} }
int Feb_Control_WaitForFinishedFlag(int sleep_time_us) { int Feb_Control_WaitForFinishedFlag(int sleep_time_us, int tempLock) {
int is_running = Feb_Control_AcquisitionInProgress(); int is_running = Feb_Control_AcquisitionInProgress();
// unlock for stop server
if (tempLock) {
sharedMemory_unlockLocalLink();
}
int check_error = 0; int check_error = 0;
// it will break out if it is idle or if check_error is more than 5 times // it will break out if it is idle or if check_error is more than 5 times
while (is_running != STATUS_IDLE) { while (is_running != STATUS_IDLE) {
usleep(sleep_time_us); usleep(sleep_time_us);
if (tempLock) {
sharedMemory_lockLocalLink();
}
is_running = Feb_Control_AcquisitionInProgress(); is_running = Feb_Control_AcquisitionInProgress();
if (tempLock) {
sharedMemory_unlockLocalLink();
}
// check error only 5 times (ensuring it is not something that happens // check error only 5 times (ensuring it is not something that happens
// sometimes) // sometimes)
if (is_running == STATUS_ERROR) { if (is_running == STATUS_ERROR) {
@ -772,6 +781,10 @@ int Feb_Control_WaitForFinishedFlag(int sleep_time_us) {
else else
check_error = 0; check_error = 0;
} }
// lock it again to be unlocked later
if (tempLock) {
sharedMemory_lockLocalLink();
}
return is_running; return is_running;
} }
@ -800,7 +813,7 @@ int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us) {
return 0; return 0;
} }
} }
return Feb_Control_WaitForFinishedFlag(sleep_time_us); return Feb_Control_WaitForFinishedFlag(sleep_time_us, 0);
} }
int Feb_Control_Reset() { int Feb_Control_Reset() {
@ -816,7 +829,7 @@ int Feb_Control_Reset() {
return 0; return 0;
} }
} }
return Feb_Control_WaitForFinishedFlag(5000); return Feb_Control_WaitForFinishedFlag(5000, 0);
} }
int Feb_Control_ResetChipCompletely() { int Feb_Control_ResetChipCompletely() {

View File

@ -42,7 +42,7 @@ unsigned int *Feb_Control_GetTrimbits();
int Feb_Control_AcquisitionInProgress(); int Feb_Control_AcquisitionInProgress();
int Feb_Control_AcquisitionStartedBit(); int Feb_Control_AcquisitionStartedBit();
int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag); int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag);
int Feb_Control_WaitForFinishedFlag(int sleep_time_us); int Feb_Control_WaitForFinishedFlag(int sleep_time_us, int tempLock);
int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, int Feb_Control_GetDAQStatusRegister(unsigned int dst_address,
unsigned int *ret_status); unsigned int *ret_status);
int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us); int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us);

View File

@ -324,6 +324,7 @@ void initControlServer() {
readDetectorNumber(); readDetectorNumber();
getModuleConfiguration(); getModuleConfiguration();
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
Feb_Control_SetMasterVariable(master); Feb_Control_SetMasterVariable(master);
Feb_Interface_FebInterface(); Feb_Interface_FebInterface();
Feb_Control_FebControl(); Feb_Control_FebControl();
@ -333,6 +334,7 @@ void initControlServer() {
sprintf(initErrorMessage, "Could not intitalize feb control\n"); sprintf(initErrorMessage, "Could not intitalize feb control\n");
LOG(logERROR, (initErrorMessage)); LOG(logERROR, (initErrorMessage));
initCheckDone = 1; initCheckDone = 1;
sharedMemory_unlockLocalLink();
return; return;
} }
// master of 9M, check high voltage serial communication to blackfin // master of 9M, check high voltage serial communication to blackfin
@ -344,9 +346,11 @@ void initControlServer() {
"Could not intitalize feb control serial communication\n"); "Could not intitalize feb control serial communication\n");
LOG(logERROR, (initErrorMessage)); LOG(logERROR, (initErrorMessage));
initCheckDone = 1; initCheckDone = 1;
sharedMemory_unlockLocalLink();
return; return;
} }
} }
sharedMemory_unlockLocalLink();
LOG(logDEBUG1, ("Control server: FEB Initialization done\n")); LOG(logDEBUG1, ("Control server: FEB Initialization done\n"));
Beb_SetTopVariable(top); Beb_SetTopVariable(top);
Beb_Beb(detid); Beb_Beb(detid);
@ -373,11 +377,13 @@ void initStopServer() {
// exit(-1); // exit(-1);
readDetectorNumber(); readDetectorNumber();
getModuleConfiguration(); getModuleConfiguration();
sharedMemory_lockLocalLink();
Feb_Control_SetMasterVariable(master); Feb_Control_SetMasterVariable(master);
Feb_Interface_FebInterface(); Feb_Interface_FebInterface();
Feb_Control_FebControl(); Feb_Control_FebControl();
// same addresses for top and bottom // same addresses for top and bottom
Feb_Control_Init(master, normal, getDetectorNumber()); Feb_Control_Init(master, normal, getDetectorNumber());
sharedMemory_unlockLocalLink();
LOG(logDEBUG1, ("Stop server: FEB Initialization done\n")); LOG(logDEBUG1, ("Stop server: FEB Initialization done\n"));
#endif #endif
// client first connect (from shm) will activate // client first connect (from shm) will activate
@ -493,14 +499,17 @@ int readConfigFile() {
top, line); top, line);
break; break;
} }
sharedMemory_lockLocalLink();
if (!Feb_Control_SetTop(ind, 1, 1)) { if (!Feb_Control_SetTop(ind, 1, 1)) {
sprintf( sprintf(
initErrorMessage, initErrorMessage,
"Could not overwrite top to %d in Feb from on-board server " "Could not overwrite top to %d in Feb from on-board server "
"config file. Line:[%s].\n", "config file. Line:[%s].\n",
top, line); top, line);
sharedMemory_unlockLocalLink();
break; break;
} }
sharedMemory_unlockLocalLink();
// validate change // validate change
int actual_top = -1, temp = -1, temp2 = -1; int actual_top = -1, temp = -1, temp2 = -1;
Beb_GetModuleConfiguration(&temp, &actual_top, &temp2); Beb_GetModuleConfiguration(&temp, &actual_top, &temp2);
@ -533,14 +542,17 @@ int readConfigFile() {
master, line); master, line);
break; break;
} }
sharedMemory_lockLocalLink();
if (!Feb_Control_SetMaster(ind)) { if (!Feb_Control_SetMaster(ind)) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not overwrite master to %d in Feb from on-board " "Could not overwrite master to %d in Feb from on-board "
"server " "server "
"config file. Line:[%s].\n", "config file. Line:[%s].\n",
master, line); master, line);
sharedMemory_unlockLocalLink();
break; break;
} }
sharedMemory_unlockLocalLink();
// validate change // validate change
int actual_master = -1, temp = -1, temp2 = -1; int actual_master = -1, temp = -1, temp2 = -1;
Beb_GetModuleConfiguration(&actual_master, &temp, &temp2); Beb_GetModuleConfiguration(&actual_master, &temp, &temp2);
@ -550,7 +562,9 @@ int readConfigFile() {
actual_master); actual_master);
break; break;
} }
sharedMemory_lockLocalLink();
Feb_Control_SetMasterVariable(master); Feb_Control_SetMasterVariable(master);
sharedMemory_unlockLocalLink();
#endif #endif
} }
@ -592,13 +606,16 @@ void resetToHardwareSettings() {
LOG(logERROR, ("%s\n\n", initErrorMessage)); LOG(logERROR, ("%s\n\n", initErrorMessage));
return; return;
} }
sharedMemory_lockLocalLink();
if (!Feb_Control_SetTop(TOP_HARDWARE, 1, 1)) { if (!Feb_Control_SetTop(TOP_HARDWARE, 1, 1)) {
initError = FAIL; initError = FAIL;
strcpy(initErrorMessage, strcpy(initErrorMessage,
"Could not reset Top flag to Feb hardware settings.\n"); "Could not reset Top flag to Feb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage)); LOG(logERROR, ("%s\n\n", initErrorMessage));
sharedMemory_unlockLocalLink();
return; return;
} }
sharedMemory_unlockLocalLink();
int temp = -1, temp2 = -1; int temp = -1, temp2 = -1;
Beb_GetModuleConfiguration(&temp, &top, &temp2); Beb_GetModuleConfiguration(&temp, &top, &temp2);
Beb_SetTopVariable(top); Beb_SetTopVariable(top);
@ -612,16 +629,21 @@ void resetToHardwareSettings() {
LOG(logERROR, ("%s\n\n", initErrorMessage)); LOG(logERROR, ("%s\n\n", initErrorMessage));
return; return;
} }
sharedMemory_lockLocalLink();
if (!Feb_Control_SetMaster(TOP_HARDWARE)) { if (!Feb_Control_SetMaster(TOP_HARDWARE)) {
initError = FAIL; initError = FAIL;
strcpy(initErrorMessage, strcpy(initErrorMessage,
"Could not reset Master flag to Feb hardware settings.\n"); "Could not reset Master flag to Feb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage)); LOG(logERROR, ("%s\n\n", initErrorMessage));
sharedMemory_unlockLocalLink();
return; return;
} }
sharedMemory_unlockLocalLink();
int temp = -1, temp2 = -1; int temp = -1, temp2 = -1;
Beb_GetModuleConfiguration(&master, &temp, &temp2); Beb_GetModuleConfiguration(&master, &temp, &temp2);
sharedMemory_lockLocalLink();
Feb_Control_SetMasterVariable(master); Feb_Control_SetMasterVariable(master);
sharedMemory_unlockLocalLink();
} }
#endif #endif
} }
@ -699,16 +721,21 @@ void setupDetector() {
int enable[2] = {DEFAULT_EXT_GATING_ENABLE, DEFAULT_EXT_GATING_POLARITY}; int enable[2] = {DEFAULT_EXT_GATING_ENABLE, DEFAULT_EXT_GATING_POLARITY};
setExternalGating(enable); // disable external gating setExternalGating(enable); // disable external gating
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
Feb_Control_SetInTestModeVariable(DEFAULT_TEST_MODE); Feb_Control_SetInTestModeVariable(DEFAULT_TEST_MODE);
sharedMemory_unlockLocalLink();
#endif #endif
setHighVoltage(DEFAULT_HIGH_VOLTAGE); setHighVoltage(DEFAULT_HIGH_VOLTAGE);
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
if (!Feb_Control_CheckSetup()) { if (!Feb_Control_CheckSetup()) {
initError = FAIL; initError = FAIL;
sprintf(initErrorMessage, "Could not pass feb control setup checks\n"); sprintf(initErrorMessage, "Could not pass feb control setup checks\n");
LOG(logERROR, (initErrorMessage)); LOG(logERROR, (initErrorMessage));
sharedMemory_unlockLocalLink();
return; return;
} }
sharedMemory_unlockLocalLink();
#endif #endif
// force top or master if in config file // force top or master if in config file
if (readConfigFile() == FAIL) { if (readConfigFile() == FAIL) {
@ -732,9 +759,12 @@ int writeRegister(uint32_t offset, uint32_t data) {
#ifdef VIRTUAL #ifdef VIRTUAL
return OK; return OK;
#else #else
sharedMemory_lockLocalLink();
if (!Feb_Control_WriteRegister(offset, data)) { if (!Feb_Control_WriteRegister(offset, data)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink();
return OK; return OK;
#endif #endif
} }
@ -743,9 +773,12 @@ int readRegister(uint32_t offset, uint32_t *retval) {
#ifdef VIRTUAL #ifdef VIRTUAL
return OK; return OK;
#else #else
sharedMemory_lockLocalLink();
if (!Feb_Control_ReadRegister(offset, retval)) { if (!Feb_Control_ReadRegister(offset, retval)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink();
return OK; return OK;
#endif #endif
} }
@ -757,21 +790,26 @@ int setDynamicRange(int dr) {
if (dr > 0) { if (dr > 0) {
LOG(logDEBUG1, ("Setting dynamic range: %d\n", dr)); LOG(logDEBUG1, ("Setting dynamic range: %d\n", dr));
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
if (Feb_Control_SetDynamicRange(dr)) { if (Feb_Control_SetDynamicRange(dr)) {
on_dst = 0; on_dst = 0;
for (int i = 0; i < 32; ++i) for (int i = 0; i < 32; ++i)
dst_requested[i] = 0; // clear dst requested dst_requested[i] = 0; // clear dst requested
if (!Beb_SetUpTransferParameters(dr)) { if (!Beb_SetUpTransferParameters(dr)) {
LOG(logERROR, ("Could not set bit mode in the back end\n")); LOG(logERROR, ("Could not set bit mode in the back end\n"));
sharedMemory_unlockLocalLink();
return eiger_dynamicrange; return eiger_dynamicrange;
} }
} }
sharedMemory_unlockLocalLink();
#endif #endif
eiger_dynamicrange = dr; eiger_dynamicrange = dr;
} }
// getting dr // getting dr
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
eiger_dynamicrange = Feb_Control_GetDynamicRange(); eiger_dynamicrange = Feb_Control_GetDynamicRange();
sharedMemory_unlockLocalLink();
#endif #endif
return eiger_dynamicrange; return eiger_dynamicrange;
} }
@ -781,9 +819,12 @@ int setDynamicRange(int dr) {
int setParallelMode(int mode) { int setParallelMode(int mode) {
mode = (mode == 0 ? E_NON_PARALLEL : E_PARALLEL); mode = (mode == 0 ? E_NON_PARALLEL : E_PARALLEL);
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
if (!Feb_Control_SetReadoutMode(mode)) { if (!Feb_Control_SetReadoutMode(mode)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink();
#endif #endif
eiger_parallelmode = mode; eiger_parallelmode = mode;
return OK; return OK;
@ -828,6 +869,7 @@ void setNumFrames(int64_t val) {
if (val > 0) { if (val > 0) {
LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val)); LOG(logINFO, ("Setting number of frames %lld\n", (long long int)val));
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
if (Feb_Control_SetNExposures((unsigned int)val * eiger_ntriggers)) { if (Feb_Control_SetNExposures((unsigned int)val * eiger_ntriggers)) {
eiger_nexposures = val; eiger_nexposures = val;
on_dst = 0; on_dst = 0;
@ -836,6 +878,7 @@ void setNumFrames(int64_t val) {
ndsts_in_use = 1; ndsts_in_use = 1;
nimages_per_request = eiger_nexposures * eiger_ntriggers; nimages_per_request = eiger_nexposures * eiger_ntriggers;
} }
sharedMemory_unlockLocalLink();
#else #else
eiger_nexposures = val; eiger_nexposures = val;
nimages_per_request = eiger_nexposures * eiger_ntriggers; nimages_per_request = eiger_nexposures * eiger_ntriggers;
@ -849,6 +892,7 @@ void setNumTriggers(int64_t val) {
if (val > 0) { if (val > 0) {
LOG(logINFO, ("Setting number of triggers %lld\n", (long long int)val)); LOG(logINFO, ("Setting number of triggers %lld\n", (long long int)val));
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
if (Feb_Control_SetNExposures((unsigned int)val * eiger_nexposures)) { if (Feb_Control_SetNExposures((unsigned int)val * eiger_nexposures)) {
eiger_ntriggers = val; eiger_ntriggers = val;
on_dst = 0; on_dst = 0;
@ -856,6 +900,7 @@ void setNumTriggers(int64_t val) {
dst_requested[i] = 0; // clear dst requested dst_requested[i] = 0; // clear dst requested
nimages_per_request = eiger_nexposures * eiger_ntriggers; nimages_per_request = eiger_nexposures * eiger_ntriggers;
} }
sharedMemory_unlockLocalLink();
#else #else
eiger_ntriggers = val; eiger_ntriggers = val;
nimages_per_request = eiger_nexposures * eiger_ntriggers; nimages_per_request = eiger_nexposures * eiger_ntriggers;
@ -868,7 +913,9 @@ int64_t getNumTriggers() { return eiger_ntriggers; }
int setExpTime(int64_t val) { int setExpTime(int64_t val) {
LOG(logINFO, ("Setting exptime %lld ns\n", (long long int)val)); LOG(logINFO, ("Setting exptime %lld ns\n", (long long int)val));
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
Feb_Control_SetExposureTime(val / (1E9)); Feb_Control_SetExposureTime(val / (1E9));
sharedMemory_unlockLocalLink();
#else #else
eiger_virtual_exptime = val; eiger_virtual_exptime = val;
#endif #endif
@ -877,7 +924,10 @@ int setExpTime(int64_t val) {
int64_t getExpTime() { int64_t getExpTime() {
#ifndef VIRTUAL #ifndef VIRTUAL
return (Feb_Control_GetExposureTime() * (1E9)); sharedMemory_lockLocalLink();
int64_t retval = (Feb_Control_GetExposureTime() * (1E9));
sharedMemory_unlockLocalLink();
return retval;
#else #else
return eiger_virtual_exptime; return eiger_virtual_exptime;
#endif #endif
@ -886,7 +936,9 @@ int64_t getExpTime() {
int setPeriod(int64_t val) { int setPeriod(int64_t val) {
LOG(logINFO, ("Setting period %lld ns\n", (long long int)val)); LOG(logINFO, ("Setting period %lld ns\n", (long long int)val));
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
Feb_Control_SetExposurePeriod(val / (1E9)); Feb_Control_SetExposurePeriod(val / (1E9));
sharedMemory_unlockLocalLink();
#else #else
eiger_virtual_period = val; eiger_virtual_period = val;
#endif #endif
@ -895,7 +947,10 @@ int setPeriod(int64_t val) {
int64_t getPeriod() { int64_t getPeriod() {
#ifndef VIRTUAL #ifndef VIRTUAL
return (Feb_Control_GetExposurePeriod() * (1E9)); sharedMemory_lockLocalLink();
int64_t retval = (Feb_Control_GetExposurePeriod() * (1E9));
sharedMemory_unlockLocalLink();
return retval;
#else #else
return eiger_virtual_period; return eiger_virtual_period;
#endif #endif
@ -904,12 +959,14 @@ int64_t getPeriod() {
int setSubExpTime(int64_t val) { int setSubExpTime(int64_t val) {
LOG(logINFO, ("Setting subexptime %lld ns\n", (long long int)val)); LOG(logINFO, ("Setting subexptime %lld ns\n", (long long int)val));
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
// calculate subdeadtime before settings subexptime // calculate subdeadtime before settings subexptime
int64_t subdeadtime = int64_t subdeadtime =
Feb_Control_GetSubFramePeriod() - Feb_Control_GetSubFrameExposureTime(); Feb_Control_GetSubFramePeriod() - Feb_Control_GetSubFrameExposureTime();
Feb_Control_SetSubFrameExposureTime(val / 10); Feb_Control_SetSubFrameExposureTime(val / 10);
// set subperiod // set subperiod
Feb_Control_SetSubFramePeriod((val + subdeadtime) / 10); Feb_Control_SetSubFramePeriod((val + subdeadtime) / 10);
sharedMemory_unlockLocalLink();
#else #else
int64_t subdeadtime = int64_t subdeadtime =
eiger_virtual_subperiod * 10 - eiger_virtual_subexptime * 10; eiger_virtual_subperiod * 10 - eiger_virtual_subexptime * 10;
@ -921,7 +978,10 @@ int setSubExpTime(int64_t val) {
int64_t getSubExpTime() { int64_t getSubExpTime() {
#ifndef VIRTUAL #ifndef VIRTUAL
return (Feb_Control_GetSubFrameExposureTime()); sharedMemory_lockLocalLink();
int64_t retval = (Feb_Control_GetSubFrameExposureTime());
sharedMemory_unlockLocalLink();
return retval;
#else #else
return eiger_virtual_subexptime * 10; return eiger_virtual_subexptime * 10;
#endif #endif
@ -930,8 +990,10 @@ int64_t getSubExpTime() {
int setSubDeadTime(int64_t val) { int setSubDeadTime(int64_t val) {
LOG(logINFO, ("Setting subdeadtime %lld ns\n", (long long int)val)); LOG(logINFO, ("Setting subdeadtime %lld ns\n", (long long int)val));
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
// get subexptime // get subexptime
int64_t subexptime = Feb_Control_GetSubFrameExposureTime(); int64_t subexptime = Feb_Control_GetSubFrameExposureTime();
sharedMemory_unlockLocalLink();
#else #else
int64_t subexptime = eiger_virtual_subexptime * 10; int64_t subexptime = eiger_virtual_subexptime * 10;
#endif #endif
@ -942,7 +1004,9 @@ int setSubDeadTime(int64_t val) {
// calculate subperiod // calculate subperiod
val += subexptime; val += subexptime;
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
Feb_Control_SetSubFramePeriod(val / 10); Feb_Control_SetSubFramePeriod(val / 10);
sharedMemory_unlockLocalLink();
#else #else
eiger_virtual_subperiod = (val / 10); eiger_virtual_subperiod = (val / 10);
#endif #endif
@ -951,13 +1015,18 @@ int setSubDeadTime(int64_t val) {
int64_t getSubDeadTime() { int64_t getSubDeadTime() {
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
// get subexptime // get subexptime
int64_t subexptime = Feb_Control_GetSubFrameExposureTime(); int64_t subexptime = Feb_Control_GetSubFrameExposureTime();
sharedMemory_unlockLocalLink();
#else #else
int64_t subexptime = eiger_virtual_subexptime * 10; int64_t subexptime = eiger_virtual_subexptime * 10;
#endif #endif
#ifndef VIRTUAL #ifndef VIRTUAL
return (Feb_Control_GetSubFramePeriod() - subexptime); sharedMemory_lockLocalLink();
int64_t retval = (Feb_Control_GetSubFramePeriod() - subexptime);
sharedMemory_unlockLocalLink();
return retval;
#else #else
return (eiger_virtual_subperiod * 10 - subexptime); return (eiger_virtual_subperiod * 10 - subexptime);
#endif #endif
@ -967,7 +1036,10 @@ int64_t getMeasuredPeriod() {
#ifdef VIRTUAL #ifdef VIRTUAL
return 0; return 0;
#else #else
return Feb_Control_GetMeasuredPeriod(); sharedMemory_lockLocalLink();
int64_t retval = Feb_Control_GetMeasuredPeriod();
sharedMemory_unlockLocalLink();
return retval;
#endif #endif
} }
@ -975,7 +1047,10 @@ int64_t getMeasuredSubPeriod() {
#ifdef VIRTUAL #ifdef VIRTUAL
return 0; return 0;
#else #else
return Feb_Control_GetSubMeasuredPeriod(); sharedMemory_lockLocalLink();
int64_t retval = Feb_Control_GetSubMeasuredPeriod();
sharedMemory_unlockLocalLink();
return retval;
#endif #endif
} }
@ -1054,14 +1129,17 @@ int setModule(sls_detector_module myMod, char *mess) {
} }
// set trimbits // set trimbits
sharedMemory_lockLocalLink();
if (!Feb_Control_SetTrimbits(tt, top)) { if (!Feb_Control_SetTrimbits(tt, top)) {
sprintf(mess, "Could not set module. Could not set trimbits\n"); sprintf(mess, "Could not set module. Could not set trimbits\n");
LOG(logERROR, (mess)); LOG(logERROR, (mess));
setSettings(UNDEFINED); setSettings(UNDEFINED);
LOG(logERROR, ("Settings has been changed to undefined (random " LOG(logERROR, ("Settings has been changed to undefined (random "
"trim file)\n")); "trim file)\n"));
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink();
} }
#endif #endif
@ -1185,9 +1263,11 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
return; return;
} }
} }
sharedMemory_lockLocalLink();
if (Feb_Control_SetDAC(ind, dacval)) { if (Feb_Control_SetDAC(ind, dacval)) {
(detectorModules)->dacs[ind] = dacval; (detectorModules)->dacs[ind] = dacval;
} }
sharedMemory_unlockLocalLink();
#endif #endif
} }
@ -1242,10 +1322,14 @@ int getADC(enum ADCINDEX ind) {
retval = getBebFPGATemp(); retval = getBebFPGATemp();
break; break;
case TEMP_FPGAFEBL: case TEMP_FPGAFEBL:
sharedMemory_lockLocalLink();
retval = Feb_Control_GetLeftFPGATemp(); retval = Feb_Control_GetLeftFPGATemp();
sharedMemory_unlockLocalLink();
break; break;
case TEMP_FPGAFEBR: case TEMP_FPGAFEBR:
sharedMemory_lockLocalLink();
retval = Feb_Control_GetRightFPGATemp(); retval = Feb_Control_GetRightFPGATemp();
sharedMemory_unlockLocalLink();
break; break;
case TEMP_FPGAEXT: case TEMP_FPGAEXT:
case TEMP_10GE: case TEMP_10GE:
@ -1289,7 +1373,9 @@ int setHighVoltage(int val) {
// set // set
if (val != -1) { if (val != -1) {
eiger_theo_highvoltage = val; eiger_theo_highvoltage = val;
sharedMemory_lockLocalLink();
int ret = Feb_Control_SetHighVoltage(val); int ret = Feb_Control_SetHighVoltage(val);
sharedMemory_unlockLocalLink();
if (!ret) // could not set if (!ret) // could not set
return -2; return -2;
else if (ret == -1) // outside range else if (ret == -1) // outside range
@ -1297,10 +1383,13 @@ int setHighVoltage(int val) {
} }
// get // get
sharedMemory_lockLocalLink();
if (!Feb_Control_GetHighVoltage(&eiger_highvoltage)) { if (!Feb_Control_GetHighVoltage(&eiger_highvoltage)) {
LOG(logERROR, ("Could not read high voltage\n")); LOG(logERROR, ("Could not read high voltage\n"));
sharedMemory_unlockLocalLink();
return -3; return -3;
} }
sharedMemory_unlockLocalLink();
// tolerance of 5 // tolerance of 5
if (abs(eiger_theo_highvoltage - eiger_highvoltage) > if (abs(eiger_theo_highvoltage - eiger_highvoltage) >
@ -1339,9 +1428,14 @@ void setTiming(enum timingMode arg) {
} }
LOG(logDEBUG1, ("Setting Triggering Mode: %d\n", (int)ret)); LOG(logDEBUG1, ("Setting Triggering Mode: %d\n", (int)ret));
#ifndef VIRTUAL #ifndef VIRTUAL
if (Feb_Control_SetTriggerMode(ret)) sharedMemory_lockLocalLink();
#endif if (Feb_Control_SetTriggerMode(ret)) {
eiger_triggermode = ret; eiger_triggermode = ret;
}
sharedMemory_unlockLocalLink();
#else
eiger_triggermode = ret;
#endif
} }
enum timingMode getTiming() { enum timingMode getTiming() {
@ -1469,9 +1563,12 @@ int setQuad(int value) {
if (Beb_SetQuad(value) == FAIL) { if (Beb_SetQuad(value) == FAIL) {
return FAIL; return FAIL;
} }
sharedMemory_lockLocalLink();
if (!Feb_Control_SetQuad(value)) { if (!Feb_Control_SetQuad(value)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink();
#else #else
eiger_virtual_quad_mode = value; eiger_virtual_quad_mode = value;
#endif #endif
@ -1490,9 +1587,12 @@ int setInterruptSubframe(int value) {
if (value < 0) if (value < 0)
return FAIL; return FAIL;
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
if (!Feb_Control_SetInterruptSubframe(value)) { if (!Feb_Control_SetInterruptSubframe(value)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink();
#else #else
eiger_virtual_interrupt_subframe = value; eiger_virtual_interrupt_subframe = value;
#endif #endif
@ -1503,7 +1603,10 @@ int getInterruptSubframe() {
#ifdef VIRTUAL #ifdef VIRTUAL
return eiger_virtual_interrupt_subframe; return eiger_virtual_interrupt_subframe;
#else #else
return Feb_Control_GetInterruptSubframe(); sharedMemory_lockLocalLink();
int retval = Feb_Control_GetInterruptSubframe();
sharedMemory_unlockLocalLink();
return retval;
#endif #endif
} }
@ -1511,9 +1614,12 @@ int setReadNLines(int value) {
if (value < 0) if (value < 0)
return FAIL; return FAIL;
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
if (!Feb_Control_SetReadNLines(value)) { if (!Feb_Control_SetReadNLines(value)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink();
Beb_SetReadNLines(value); Beb_SetReadNLines(value);
#else #else
eiger_virtual_read_nlines = value; eiger_virtual_read_nlines = value;
@ -1525,7 +1631,10 @@ int getReadNLines() {
#ifdef VIRTUAL #ifdef VIRTUAL
return eiger_virtual_read_nlines; return eiger_virtual_read_nlines;
#else #else
return Feb_Control_GetReadNLines(); sharedMemory_lockLocalLink();
int retval = Feb_Control_GetReadNLines();
sharedMemory_unlockLocalLink();
return retval;
#endif #endif
} }
@ -1549,10 +1658,15 @@ int setClockDivider(enum CLKINDEX ind, int val) {
if (val >= 0) { if (val >= 0) {
LOG(logINFO, ("Setting Read out Speed: %d\n", val)); LOG(logINFO, ("Setting Read out Speed: %d\n", val));
#ifndef VIRTUAL #ifndef VIRTUAL
if (Feb_Control_SetReadoutSpeed(val)) sharedMemory_lockLocalLink();
#endif if (Feb_Control_SetReadoutSpeed(val)) {
eiger_readoutspeed = val; eiger_readoutspeed = val;
} }
sharedMemory_unlockLocalLink();
#else
eiger_readoutspeed = val;
#endif
}
return OK; return OK;
} }
@ -1568,10 +1682,15 @@ int setIODelay(int val) {
if (val != -1) { if (val != -1) {
LOG(logDEBUG1, ("Setting IO Delay: %d\n", val)); LOG(logDEBUG1, ("Setting IO Delay: %d\n", val));
#ifndef VIRTUAL #ifndef VIRTUAL
if (Feb_Control_SetIDelays(val)) sharedMemory_lockLocalLink();
#endif if (Feb_Control_SetIDelays(val)) {
eiger_iodelay = val; eiger_iodelay = val;
} }
sharedMemory_unlockLocalLink();
#else
eiger_iodelay = val;
#endif
}
return eiger_iodelay; return eiger_iodelay;
} }
@ -1581,36 +1700,53 @@ int setCounterBit(int val) {
#ifdef VIRTUAL #ifdef VIRTUAL
eiger_virtual_counter_bit = val; eiger_virtual_counter_bit = val;
#else #else
sharedMemory_lockLocalLink();
Feb_Control_Set_Counter_Bit(val); Feb_Control_Set_Counter_Bit(val);
sharedMemory_unlockLocalLink();
#endif #endif
} }
#ifdef VIRTUAL #ifdef VIRTUAL
return eiger_virtual_counter_bit; return eiger_virtual_counter_bit;
#else #else
return Feb_Control_Get_Counter_Bit(); sharedMemory_lockLocalLink();
int retval = Feb_Control_Get_Counter_Bit();
sharedMemory_unlockLocalLink();
return retval;
#endif #endif
} }
int pulsePixel(int n, int x, int y) { int pulsePixel(int n, int x, int y) {
#ifndef VIRTUAL #ifndef VIRTUAL
if (!Feb_Control_Pulse_Pixel(n, x, y)) sharedMemory_lockLocalLink();
if (!Feb_Control_Pulse_Pixel(n, x, y)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
}
sharedMemory_unlockLocalLink();
#endif #endif
return OK; return OK;
} }
int pulsePixelNMove(int n, int x, int y) { int pulsePixelNMove(int n, int x, int y) {
#ifndef VIRTUAL #ifndef VIRTUAL
if (!Feb_Control_PulsePixelNMove(n, x, y)) sharedMemory_lockLocalLink();
if (!Feb_Control_PulsePixelNMove(n, x, y)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
}
sharedMemory_unlockLocalLink();
#endif #endif
return OK; return OK;
} }
int pulseChip(int n) { int pulseChip(int n) {
#ifndef VIRTUAL #ifndef VIRTUAL
if (!Feb_Control_PulseChip(n)) sharedMemory_lockLocalLink();
if (!Feb_Control_PulseChip(n)) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
}
sharedMemory_unlockLocalLink();
#endif #endif
return OK; return OK;
} }
@ -1716,10 +1852,12 @@ int setRateCorrection(
return OK; return OK;
#else #else
sharedMemory_lockLocalLink();
// deactivating rate correction // deactivating rate correction
if (custom_tau_in_nsec == 0) { if (custom_tau_in_nsec == 0) {
Feb_Control_SetRateCorrectionVariable(0); Feb_Control_SetRateCorrectionVariable(0);
sharedMemory_unlockLocalLink();
return OK; return OK;
} }
@ -1758,6 +1896,7 @@ int setRateCorrection(
LOG(logERROR, LOG(logERROR,
("Rate correction failed. Deactivating rate correction\n")); ("Rate correction failed. Deactivating rate correction\n"));
Feb_Control_SetRateCorrectionVariable(0); Feb_Control_SetRateCorrectionVariable(0);
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
} }
@ -1766,6 +1905,7 @@ int setRateCorrection(
LOG(logINFO, ("Rate Correction Value set to %lld ns\n", LOG(logINFO, ("Rate Correction Value set to %lld ns\n",
(long long int)Feb_Control_Get_RateTable_Tau_in_nsec())); (long long int)Feb_Control_Get_RateTable_Tau_in_nsec()));
Feb_Control_PrintCorrectedValues(); Feb_Control_PrintCorrectedValues();
sharedMemory_unlockLocalLink();
return OK; return OK;
#endif #endif
@ -1775,7 +1915,10 @@ int getRateCorrectionEnable() {
#ifdef VIRTUAL #ifdef VIRTUAL
return eiger_virtual_ratecorrection_variable; return eiger_virtual_ratecorrection_variable;
#else #else
return Feb_Control_GetRateCorrectionVariable(); sharedMemory_lockLocalLink();
int retval = Feb_Control_GetRateCorrectionVariable();
sharedMemory_unlockLocalLink();
return retval;
#endif #endif
} }
@ -1792,7 +1935,9 @@ int64_t getCurrentTau() {
return 0; return 0;
} else { } else {
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
eiger_tau_ns = Feb_Control_Get_RateTable_Tau_in_nsec(); eiger_tau_ns = Feb_Control_Get_RateTable_Tau_in_nsec();
sharedMemory_unlockLocalLink();
#else #else
eiger_tau_ns = eiger_virtual_ratetable_tau_in_ns; eiger_tau_ns = eiger_virtual_ratetable_tau_in_ns;
#endif #endif
@ -1805,9 +1950,11 @@ void setExternalGating(int enable[]) {
// default: disable gating with positive polarity // default: disable gating with positive polarity
if (enable[0] >= 0 && enable[1] >= 0) { if (enable[0] >= 0 && enable[1] >= 0) {
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
Feb_Control_SetExternalEnableMode( Feb_Control_SetExternalEnableMode(
enable[0], enable[1]); // enable = 0 or 1, polarity = 0 or 1 , where enable[0], enable[1]); // enable = 0 or 1, polarity = 0 or 1 , where
// 1 is positive // 1 is positive
sharedMemory_unlockLocalLink();
#endif #endif
eiger_extgating = enable[0]; eiger_extgating = enable[0];
eiger_extgatingpolarity = enable[1]; eiger_extgatingpolarity = enable[1];
@ -1819,10 +1966,13 @@ void setExternalGating(int enable[]) {
int setAllTrimbits(int val) { int setAllTrimbits(int val) {
LOG(logINFO, ("Setting all trimbits to %d\n", val)); LOG(logINFO, ("Setting all trimbits to %d\n", val));
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
if (!Feb_Control_SaveAllTrimbitsTo(val, top)) { if (!Feb_Control_SaveAllTrimbitsTo(val, top)) {
LOG(logERROR, ("Could not set all trimbits\n")); LOG(logERROR, ("Could not set all trimbits\n"));
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink();
#endif #endif
if (detectorModules) { if (detectorModules) {
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) { for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
@ -1867,7 +2017,9 @@ int setActivate(int enable) {
if (!Beb_SetActivate(enable)) { if (!Beb_SetActivate(enable)) {
return FAIL; return FAIL;
} }
sharedMemory_lockLocalLink();
Feb_Control_activate(enable); Feb_Control_activate(enable);
sharedMemory_unlockLocalLink();
#endif #endif
if (enable) { if (enable) {
LOG(logINFOGREEN, ("Activated in %s Server!\n", LOG(logINFOGREEN, ("Activated in %s Server!\n",
@ -1970,9 +2122,11 @@ int setTransmissionDelayRight(int value) {
int prepareAcquisition() { int prepareAcquisition() {
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink();
LOG(logINFO, ("Going to prepare for acquisition with counter_bit:%d\n", LOG(logINFO, ("Going to prepare for acquisition with counter_bit:%d\n",
Feb_Control_Get_Counter_Bit())); Feb_Control_Get_Counter_Bit()));
Feb_Control_PrepareForAcquisition(); Feb_Control_PrepareForAcquisition();
sharedMemory_unlockLocalLink();
#endif #endif
return OK; return OK;
} }
@ -2001,6 +2155,7 @@ int startStateMachine() {
LOG(logINFO, ("Virtual Acquisition started\n")); LOG(logINFO, ("Virtual Acquisition started\n"));
return OK; return OK;
#else #else
sharedMemory_lockLocalLink();
LOG(logINFO, ("Acquisition started bit toggled\n")); LOG(logINFO, ("Acquisition started bit toggled\n"));
int ret = OK, prev_flag; int ret = OK, prev_flag;
// get the DAQ toggle bit // get the DAQ toggle bit
@ -2017,10 +2172,12 @@ int startStateMachine() {
if (!Feb_Control_WaitForStartedFlag(5000, prev_flag)) { if (!Feb_Control_WaitForStartedFlag(5000, prev_flag)) {
LOG(logERROR, LOG(logERROR,
("Acquisition did not LOG(logERROR ouble reading register\n")); ("Acquisition did not LOG(logERROR ouble reading register\n"));
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Acquisition started\n")); LOG(logINFOGREEN, ("Acquisition started\n"));
} }
sharedMemory_unlockLocalLink();
return ret; return ret;
#endif #endif
@ -2223,11 +2380,14 @@ int stopStateMachine() {
LOG(logINFO, ("Stopped State Machine\n")); LOG(logINFO, ("Stopped State Machine\n"));
return OK; return OK;
#else #else
sharedMemory_lockLocalLink();
if ((Feb_Control_StopAcquisition() != STATUS_IDLE) || if ((Feb_Control_StopAcquisition() != STATUS_IDLE) ||
(!Beb_StopAcquisition())) { (!Beb_StopAcquisition())) {
LOG(logERROR, ("failed to stop acquisition\n")); LOG(logERROR, ("failed to stop acquisition\n"));
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink();
// ensure all have same starting frame numbers // ensure all have same starting frame numbers
uint64_t retval = 0; uint64_t retval = 0;
@ -2242,8 +2402,12 @@ int softwareTrigger() {
#ifdef VIRTUAL #ifdef VIRTUAL
return OK; return OK;
#else #else
if (!Feb_Control_SoftwareTrigger()) sharedMemory_lockLocalLink();
if (!Feb_Control_SoftwareTrigger()) {
sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
}
sharedMemory_unlockLocalLink();
return OK; return OK;
#endif #endif
} }
@ -2294,7 +2458,9 @@ enum runStatus getRunStatus() {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE; return IDLE;
#else #else
sharedMemory_lockLocalLink();
int i = Feb_Control_AcquisitionInProgress(); int i = Feb_Control_AcquisitionInProgress();
sharedMemory_unlockLocalLink();
if (i == STATUS_ERROR) { if (i == STATUS_ERROR) {
LOG(logERROR, ("Status: ERROR reading status register\n")); LOG(logERROR, ("Status: ERROR reading status register\n"));
return ERROR; return ERROR;
@ -2325,11 +2491,14 @@ void readFrame(int *ret, char *mess) {
return; return;
#else #else
if (Feb_Control_WaitForFinishedFlag(5000) == STATUS_ERROR) { sharedMemory_lockLocalLink();
if (Feb_Control_WaitForFinishedFlag(5000, 1) == STATUS_ERROR) {
sharedMemory_unlockLocalLink();
LOG(logERROR, ("Waiting for finished flag\n")); LOG(logERROR, ("Waiting for finished flag\n"));
*ret = FAIL; *ret = FAIL;
return; return;
} }
sharedMemory_unlockLocalLink();
LOG(logINFOGREEN, ("Acquisition finished\n")); LOG(logINFOGREEN, ("Acquisition finished\n"));
// wait for detector to send // wait for detector to send