diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.c b/slsDetectorServers/eigerDetectorServer/FebControl.c index 343a4530d..bbeb7d01a 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.c +++ b/slsDetectorServers/eigerDetectorServer/FebControl.c @@ -998,11 +998,15 @@ int Feb_Control_StartAcquisition() { int Feb_Control_StopAcquisition() { return Feb_Control_Reset(); } -int Feb_Control_GetExposureStatus(int *rising, int *falling, int *exposure) { +int Feb_Control_GetExposureStatus(int left, int *rising, int *falling, + int *exposure) { + + unsigned int addr = + (left == 1 ? Feb_Control_leftAddress : Feb_Control_rightAddress); unsigned int value = 0; - if (!Feb_Interface_ReadRegister(Feb_Control_AddressToAll(), FEB_REG_STATUS, - &value)) { - LOG(logERROR, ("Could not read FEB_REG_STATUS reg\n")); + if (!Feb_Interface_ReadRegister(addr, FEB_REG_STATUS, &value)) { + LOG(logERROR, ("Could not read %s FEB_REG_STATUS reg\n", + (left == 1 ? "left" : "right"))); return 0; } LOG(logINFORED, ("febregstatus:0x%x\n", value)); @@ -1046,58 +1050,75 @@ int Feb_Control_SendSoftwareTrigger() { int Feb_Control_SoftwareTrigger(int block) { if (Feb_Control_activated) { - int rising = 0, falling = 0, exposure = 0; - if (!Feb_Control_GetExposureStatus(&rising, &falling, &exposure)) { - return 0; + int rising[2] = {0, 0}, falling[2] = {0, 0}, exposure[2] = {0, 0}, + prev_toggle[2] = {0, 0}; + for (int i = 0; i < 1; ++i) { + if (!Feb_Control_GetExposureStatus(i, &rising[i], &falling[i], + &exposure[i])) { + return 0; + } + + if (exposure[i]) { + LOG(logERROR, + ("Software trigger failed. %s FPGA still exposing.\n", + i == 1 ? "left" : "right")); + return 0; + } + + // remember previous rising toggle + prev_toggle[i] = rising[i]; } - if (exposure) { - LOG(logERROR, ("Software trigger failed. Still exposing.\n")); - return 0; - } - - // remember previous rising toggle - int prev_toggle = rising; - + // send trigger to both fpgas Feb_Control_SendSoftwareTrigger(); // will need to wait if delay after trigger introduced // usleep(0); - // get current toggle value - if (!Feb_Control_GetExposureStatus(&rising, &falling, &exposure)) { - return 0; - } + for (int i = 0; i < 1; ++i) { + // get current toggle value + if (!Feb_Control_GetExposureStatus(i, &rising[i], &falling[i], + &exposure[i])) { + return 0; + } - // no toggle error - if (rising == prev_toggle) { - LOG(logERROR, ("Software trigger failed. No exposure toggle " - "detected.\n")); - return 0; - } + // no toggle error + if (rising[i] == prev_toggle[i]) { + LOG(logERROR, ("Software trigger failed. No exposure toggle " + "detected on %s fpga.\n", + i == 1 ? "left" : "right")); + return 0; + } - // no exposure - if (!exposure) { - LOG(logERROR, ("Software trigger failed. No exposure detected.\n")); - return 0; + // no exposure + if (!exposure[i]) { + LOG(logERROR, ("Software trigger failed. No exposure detected " + "on %s fpga.\n", + i == 1 ? "left" : "right")); + return 0; + } } // wait for exposure to be done if (block) { - prev_toggle = falling; - while (prev_toggle == falling) { - usleep(5000); - if (!Feb_Control_GetExposureStatus(&rising, &falling, - &exposure)) { + for (int i = 0; i < 1; ++i) { + prev_toggle[i] = falling[i]; + while (prev_toggle[i] == falling[i]) { + usleep(5000); + if (!Feb_Control_GetExposureStatus( + i, &rising[i], &falling[i], &exposure[i])) { + return 0; + } + } + // exposure low + if (exposure[i]) { + LOG(logERROR, + ("Software trigger failed. Still exposing after " + "exposure finished toggled in %s fpga.\n", + i == 1 ? "left" : "right")); return 0; } } - // exposure low - if (exposure) { - LOG(logERROR, ("Software trigger failed. Still exposing after " - "exposure finished toggled.\n")); - return 0; - } } } return 1; diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.h b/slsDetectorServers/eigerDetectorServer/FebControl.h index 4ec9efd11..d15705008 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.h +++ b/slsDetectorServers/eigerDetectorServer/FebControl.h @@ -55,7 +55,8 @@ int Feb_Control_PrepareForAcquisition(); void Feb_Control_PrintAcquisitionSetup(); int Feb_Control_StartAcquisition(); int Feb_Control_StopAcquisition(); -int Feb_Control_GetExposureStatus(int *rising, int *falling, int *exposure); +int Feb_Control_GetExposureStatus(int left, int *rising, int *falling, + int *exposure); int Feb_Control_SendSoftwareTrigger(); int Feb_Control_SoftwareTrigger(int block);