Merge pull request #184 from slsdetectorgroup/eigerserverlock

Eigerserverlock
This commit is contained in:
Dhanya Thattil 2020-09-21 17:29:03 +02:00 committed by GitHub
commit ca0192e27e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 297 additions and 97 deletions

View File

@ -151,7 +151,7 @@ void Beb_Beb(int id) {
Beb_bit_mode = 4;
// ll_beb = &ll_beb_local;
// Local_LocalLinkInterface1(ll_beb,XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR);
// Local_LocalLinkInterface(ll_beb,XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR);
// Beb_SetByteOrder();
}

View File

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

View File

@ -42,7 +42,7 @@ unsigned int *Feb_Control_GetTrimbits();
int Feb_Control_AcquisitionInProgress();
int Feb_Control_AcquisitionStartedBit();
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,
unsigned int *ret_status);
int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us);

View File

@ -37,7 +37,7 @@ void Feb_Interface_FebInterface() {
malloc((Feb_Interface_recv_buffer_size + 1) * sizeof(unsigned int));
Feb_Interface_recv_data = &Feb_Interface_recv_data_raw[1];
Local_LocalLinkInterface1(
Local_LocalLinkInterface(
ll, XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
}

View File

@ -6,8 +6,8 @@
#include <sys/mman.h>
#include <unistd.h>
void Local_LocalLinkInterface1(struct LocalLinkInterface *ll,
unsigned int ll_fifo_badr) {
void Local_LocalLinkInterface(struct LocalLinkInterface *ll,
unsigned int ll_fifo_badr) {
LOG(logDEBUG1, ("Initialize PLB LL FIFOs\n"));
ll->ll_fifo_base = 0;
ll->ll_fifo_ctrl_reg = 0;
@ -20,16 +20,12 @@ void Local_LocalLinkInterface1(struct LocalLinkInterface *ll,
("\tCould not map LocalLink : 0x%08x\n\n\n", ll_fifo_badr));
}
void Local_LocalLinkInterface(struct LocalLinkInterface *ll) {
LOG(logDEBUG1, ("Initializing new memory\n"));
}
int Local_Init(struct LocalLinkInterface *ll, unsigned int ll_fifo_badr) {
int fd;
void *plb_ll_fifo_ptr;
if ((fd = open("/dev/mem", O_RDWR)) < 0) {
fprintf(stderr, "Could not open /dev/mem\n");
LOG(logERROR, ("Could not open /dev/mem for local link\n"));
return 0;
}
@ -38,7 +34,7 @@ int Local_Init(struct LocalLinkInterface *ll, unsigned int ll_fifo_badr) {
close(fd);
if (plb_ll_fifo_ptr == MAP_FAILED) {
perror("mmap");
LOG(logERROR, ("mmap error for local link\n"));
return 0;
}
@ -78,6 +74,7 @@ unsigned int Local_StatusVector(struct LocalLinkInterface *ll) {
int Local_Write(struct LocalLinkInterface *ll, unsigned int buffer_len,
void *buffer) {
// note: buffer must be word (4 byte) aligned
// frame_len in byte
int vacancy = 0;
@ -87,8 +84,9 @@ int Local_Write(struct LocalLinkInterface *ll, unsigned int buffer_len,
unsigned int fifo_ctrl;
xfs_u32 status;
if (buffer_len < 1)
if (buffer_len < 1) {
return -1;
}
last_word = (buffer_len - 1) / 4;
word_ptr = (unsigned int *)buffer;
@ -131,11 +129,13 @@ int Local_Write(struct LocalLinkInterface *ll, unsigned int buffer_len,
word_ptr[words_send++]);
}
}
return buffer_len;
}
int Local_Read(struct LocalLinkInterface *ll, unsigned int buffer_len,
void *buffer) {
static unsigned int buffer_ptr = 0;
// note: buffer must be word (4 byte) aligned
// frame_len in byte
@ -184,7 +184,6 @@ int Local_Read(struct LocalLinkInterface *ll, unsigned int buffer_len,
}
}
} while (!(status & PLB_LL_FIFO_STATUS_EMPTY));
return 0;
}

View File

@ -11,8 +11,8 @@ int Local_Init(struct LocalLinkInterface *ll, unsigned int ll_fifo_badr);
int Local_Reset1(struct LocalLinkInterface *ll, unsigned int rst_mask);
int Local_ctrl_reg_write_mask(struct LocalLinkInterface *ll, unsigned int mask,
unsigned int val);
void Local_LocalLinkInterface1(struct LocalLinkInterface *ll,
unsigned int ll_fifo_badr);
void Local_LocalLinkInterface(struct LocalLinkInterface *ll,
unsigned int ll_fifo_badr);
unsigned int Local_StatusVector(struct LocalLinkInterface *ll);
int Local_Reset(struct LocalLinkInterface *ll);
int Local_Write(struct LocalLinkInterface *ll, unsigned int buffer_len,
@ -21,4 +21,3 @@ int Local_Read(struct LocalLinkInterface *ll, unsigned int buffer_len,
void *buffer);
int Local_Test(struct LocalLinkInterface *ll, unsigned int buffer_len,
void *buffer);
void Local_LocalLinkInterface(struct LocalLinkInterface *ll);

View File

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

View File

@ -63,6 +63,10 @@ enum ADCINDEX {
TEMP_FPGAFEBL,
TEMP_FPGAFEBR
};
#define ADC_NAMES \
"FPGA EXT", "10GE", "DCDC", "SODL", "SODR", "FPGA", "FPGA_FL", "FPGA_FR"
enum NETWORKINDEX { TXN_LEFT, TXN_RIGHT, TXN_FRAME, FLOWCTRL_10G };
enum ROINDEX { E_PARALLEL, E_NON_PARALLEL };
enum CLKINDEX { RUN_CLK, NUM_CLOCKS };
@ -130,7 +134,7 @@ enum MASTERINDEX { MASTER_HARDWARE, OW_MASTER, OW_SLAVE };
#define DAC_MAX_STEPS (4096)
#define MAX_SUBFRAME_EXPOSURE_VAL_IN_10NS \
(0x1FFFFFFF) // 29 bit register for max subframe exposure value
(0x1FFFFFFF) // 29 bit register for max subframe exposure value
#define SLAVE_HIGH_VOLTAGE_READ_VAL (-999)
#define HIGH_VOLTAGE_TOLERANCE (5)

View File

@ -8,8 +8,8 @@ int sharedMemory_open(int port);
int sharedMemory_attach();
int sharedMemory_detach();
int sharedMemory_remove();
void sharedMemory_lock();
void sharedMemory_unlock();
void sharedMemory_lockStatus();
void sharedMemory_unlockStatus();
#ifdef VIRTUAL
void sharedMemory_setStatus(enum runStatus s);
enum runStatus sharedMemory_getStatus();
@ -19,4 +19,8 @@ int sharedMemory_getStop();
void sharedMemory_setScanStatus(enum runStatus s);
enum runStatus sharedMemory_getScanStatus();
void sharedMemory_setScanStop(int s);
int sharedMemory_getScanStop();
int sharedMemory_getScanStop();
#ifdef EIGERD
void sharedMemory_lockLocalLink();
void sharedMemory_unlockLocalLink();
#endif

View File

@ -2,20 +2,27 @@
#include "clogger.h"
#include <errno.h>
#include <pthread.h>
#include <semaphore.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#define SHM_NAME "sls_server_shared_memory"
#define SHM_NAME "sls_server_shared_memory"
#ifdef EIGERD
#define SHM_VERSION 0x200915
#else
#define SHM_VERSION 0x200625
#define SHM_KEY 5678
#define MEM_SIZE 128
#endif
#define SHM_KEY 5678
#define MEM_SIZE 128
typedef struct Memory {
int version;
pthread_mutex_t lock;
sem_t semStatus;
#ifdef EIGERD
sem_t semLocalLink;
#endif
enum runStatus scanStatus; // idle, running or error
int scanStop;
#ifdef VIRTUAL
@ -80,11 +87,18 @@ int sharedMemory_create(int port) {
int sharedMemory_initialize() {
shm->version = SHM_VERSION;
if (pthread_mutex_init(&(shm->lock), NULL) != 0) {
LOG(logERROR,
("Failed to initialize pthread lock for shared memory\n"));
if (sem_init(&(shm->semStatus), 1, 1) != 0) {
LOG(logERROR, ("Failed to initialize semaphore semStatus for "
"shared memory\n"));
return FAIL;
}
#ifdef EIGERD
if (sem_init(&(shm->semLocalLink), 1, 1) != 0) {
LOG(logERROR, ("Failed to initialize semaphore semLocalLink for "
"shared memory\n"));
return FAIL;
}
#endif
shm->scanStatus = IDLE;
shm->scanStop = 0;
#ifdef VIRTUAL
@ -141,64 +155,70 @@ int sharedMemory_remove() {
return OK;
}
void sharedMemory_lock() { pthread_mutex_lock(&(shm->lock)); }
void sharedMemory_lockStatus() { sem_wait(&(shm->semStatus)); }
void sharedMemory_unlock() { pthread_mutex_unlock(&(shm->lock)); }
void sharedMemory_unlockStatus() { sem_post(&(shm->semStatus)); }
#ifdef VIRTUAL
void sharedMemory_setStatus(enum runStatus s) {
sharedMemory_lock();
sharedMemory_lockStatus();
shm->status = s;
sharedMemory_unlock();
sharedMemory_unlockStatus();
}
enum runStatus sharedMemory_getStatus() {
enum runStatus s = 0;
sharedMemory_lock();
sharedMemory_lockStatus();
s = shm->status;
sharedMemory_unlock();
sharedMemory_unlockStatus();
return s;
}
void sharedMemory_setStop(int s) {
sharedMemory_lock();
sharedMemory_lockStatus();
shm->stop = s;
sharedMemory_unlock();
sharedMemory_unlockStatus();
}
int sharedMemory_getStop() {
int s = 0;
sharedMemory_lock();
sharedMemory_lockStatus();
s = shm->stop;
sharedMemory_unlock();
sharedMemory_unlockStatus();
return s;
}
#endif
void sharedMemory_setScanStatus(enum runStatus s) {
sharedMemory_lock();
sharedMemory_lockStatus();
shm->scanStatus = s;
sharedMemory_unlock();
sharedMemory_unlockStatus();
}
enum runStatus sharedMemory_getScanStatus() {
enum runStatus s = IDLE;
sharedMemory_lock();
sharedMemory_lockStatus();
s = shm->scanStatus;
sharedMemory_unlock();
sharedMemory_unlockStatus();
return s;
}
void sharedMemory_setScanStop(int s) {
sharedMemory_lock();
sharedMemory_lockStatus();
shm->scanStop = s;
sharedMemory_unlock();
sharedMemory_unlockStatus();
}
int sharedMemory_getScanStop() {
int s = 0;
sharedMemory_lock();
sharedMemory_lockStatus();
s = shm->scanStop;
sharedMemory_unlock();
sharedMemory_unlockStatus();
return s;
}
}
#ifdef EIGERD
void sharedMemory_lockLocalLink() { sem_wait(&(shm->semLocalLink)); }
void sharedMemory_unlockLocalLink() { sem_post(&(shm->semLocalLink)); }
#endif

View File

@ -367,9 +367,7 @@ class Detector {
* [Jungfrau] Options: TEMPERATURE_ADC, TEMPERATURE_FPGA \n
* [Eiger] Options: TEMPERATURE_FPGA, TEMPERATURE_FPGAEXT, TEMPERATURE_10GE,
* TEMPERATURE_DCDC, TEMPERATURE_SODL, TEMPERATURE_SODR, TEMPERATURE_FPGA2,
* TEMPERATURE_FPGA3 \n
* Cannot call TEMPERATURE_FPGA2 and TEMPERATURE_FPGA3 when blocking acquire
* in progress \n [CTB] Options: SLOW_ADC_TEMP
* TEMPERATURE_FPGA3 \n [CTB] Options: SLOW_ADC_TEMP
*/
Result<int> getTemperature(defs::dacIndex index, Positions pos = {}) const;

View File

@ -1351,13 +1351,11 @@ class CmdProxy {
GET_IND_COMMAND(
temp_fpgafl, getTemperature, slsDetectorDefs::TEMPERATURE_FPGA2, " °C",
"[n_value]\n\t[Eiger]Temperature of the left front end board fpga. "
"Cannot call this while blocking acquire is going on.");
"[n_value]\n\t[Eiger]Temperature of the left front end board fpga.");
GET_IND_COMMAND(
temp_fpgafr, getTemperature, slsDetectorDefs::TEMPERATURE_FPGA3, " °C",
"[n_value]\n\t[Eiger]Temperature of the left front end board fpga. "
"Cannot call this while blocking acquire is going on.");
"[n_value]\n\t[Eiger]Temperature of the left front end board fpga.");
GET_IND_COMMAND(temp_slowadc, getTemperature,
slsDetectorDefs::SLOW_ADC_TEMP, " °C",

View File

@ -357,10 +357,6 @@ void Module::setImageTestMode(const int value) {
}
int Module::getADC(dacIndex index) const {
// cannot access fpga links simultaneously (eiger) temp fix
if (index == TEMPERATURE_FPGA2 || index == TEMPERATURE_FPGA3) {
return sendToDetector<int>(F_GET_ADC, index);
}
return sendToDetectorStop<int>(F_GET_ADC, index);
}

View File

@ -1,13 +1,13 @@
/** API versions */
#define GITBRANCH "developer"
#define APILIB 0x200810
#define APIRECEIVER 0x200810
#define APIGUI 0x200804
#define GITBRANCH "developer"
#define APILIB 0x200810
#define APIRECEIVER 0x200810
#define APIGUI 0x200804
#define APICTB 0x200910
#define APIMOENCH 0x200910
#define APIEIGER 0x200910
#define APIMYTHEN3 0x200910
#define APIGOTTHARD 0x200917
#define APIJUNGFRAU 0x200917
#define APICTB 0x200910
#define APIMOENCH 0x200910
#define APIGOTTHARD2 0x200918
#define APIMYTHEN3 0x200910
#define APIGOTTHARD 0x200917
#define APIJUNGFRAU 0x200917
#define APIEIGER 0x200918