diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv6.1.2.rc3 b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv6.1.2.rc3 new file mode 100755 index 000000000..0ae1749f2 Binary files /dev/null and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv6.1.2.rc3 differ diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv6.1.2.rc4 b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv6.1.2.rc4 new file mode 100755 index 000000000..0d57ca101 Binary files /dev/null and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv6.1.2.rc4 differ diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv6.1.2.rc5 b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv6.1.2.rc5 new file mode 100755 index 000000000..292ecaf7f Binary files /dev/null and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServerv6.1.2.rc5 differ diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 04ffe504c..ff4102bc2 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -2217,43 +2217,44 @@ int setTransmissionDelayRight(int value) { /* aquisition */ -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; -} - int startStateMachine() { + sharedMemory_lockAcqFlag(); + #ifdef VIRTUAL // create udp socket if (createUDPSocket(0) != OK) { + sharedMemory_unlockAcqFlag(); return FAIL; } if (createUDPSocket(1) != OK) { + sharedMemory_unlockAcqFlag(); return FAIL; } LOG(logINFOBLUE, ("Starting State Machine\n")); if (sharedMemory_getStop() != 0) { LOG(logERROR, ("Cant start acquisition. " "Stop server has not updated stop status to 0\n")); + sharedMemory_unlockAcqFlag(); return FAIL; } sharedMemory_setStatus(RUNNING); if (pthread_create(&virtual_tid, NULL, &start_timer, NULL)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); sharedMemory_setStatus(IDLE); + sharedMemory_unlockAcqFlag(); return FAIL; } LOG(logINFO, ("Virtual Acquisition started\n")); + sharedMemory_unlockAcqFlag(); return OK; #else sharedMemory_lockLocalLink(); - LOG(logINFO, ("Acquisition started bit toggled\n")); + + LOG(logINFO, ("Going to prepare for acquisition with counter_bit:%d\n", + Feb_Control_Get_Counter_Bit())); + Feb_Control_PrepareForAcquisition(); + + int ret = OK, prev_flag; // get the DAQ toggle bit prev_flag = Feb_Control_AcquisitionStartedBit(); @@ -2270,12 +2271,14 @@ int startStateMachine() { LOG(logERROR, ("Acquisition did not LOG(logERROR ouble reading register\n")); sharedMemory_unlockLocalLink(); + sharedMemory_unlockAcqFlag(); return FAIL; } + usleep(100 * 1000); LOG(logINFOGREEN, ("Acquisition started\n")); } sharedMemory_unlockLocalLink(); - + sharedMemory_unlockAcqFlag(); return ret; #endif } @@ -2508,6 +2511,10 @@ void *start_timer(void *arg) { #endif int stopStateMachine() { + + // acq lock for seamless stop + sharedMemory_lockAcqFlag(); + LOG(logINFORED, ("Stopping state machine\n")); // if scan active, stop scan if (sharedMemory_getScanStatus() == RUNNING) { @@ -2520,6 +2527,7 @@ int stopStateMachine() { usleep(500); sharedMemory_setStop(0); LOG(logINFO, ("Stopped State Machine\n")); + sharedMemory_unlockAcqFlag(); return OK; #else sharedMemory_lockLocalLink(); @@ -2527,6 +2535,7 @@ int stopStateMachine() { if (!Feb_Control_StopAcquisition()) { LOG(logERROR, ("failed to stop acquisition\n")); sharedMemory_unlockLocalLink(); + sharedMemory_unlockAcqFlag(); return FAIL; } sharedMemory_unlockLocalLink(); @@ -2537,6 +2546,7 @@ int stopStateMachine() { // wait for beb to send out all packets if (Beb_IsTransmitting(&isTransmitting, send_to_ten_gig, 1) == FAIL) { LOG(logERROR, ("failed to stop beb acquisition\n")); + sharedMemory_unlockAcqFlag(); return FAIL; } if (isTransmitting) { @@ -2547,11 +2557,11 @@ int stopStateMachine() { // reset feb and beb sharedMemory_lockLocalLink(); - // uncommenting this out as it randomly does not set the processing bit to high - //Feb_Control_Reset(); + Feb_Control_Reset(); sharedMemory_unlockLocalLink(); if (!Beb_StopAcquisition()) { LOG(logERROR, ("failed to stop acquisition\n")); + sharedMemory_unlockAcqFlag(); return FAIL; } @@ -2561,6 +2571,7 @@ int stopStateMachine() { Beb_SetNextFrameNumber(retval + 1); } LOG(logINFOBLUE, ("Stopping state machine complete\n\n")); + sharedMemory_unlockAcqFlag(); return OK; #endif } diff --git a/slsDetectorServers/slsDetectorServer/include/sharedMemory.h b/slsDetectorServers/slsDetectorServer/include/sharedMemory.h index 297312df0..288006a21 100644 --- a/slsDetectorServers/slsDetectorServer/include/sharedMemory.h +++ b/slsDetectorServers/slsDetectorServer/include/sharedMemory.h @@ -25,4 +25,6 @@ int sharedMemory_getScanStop(); #ifdef EIGERD void sharedMemory_lockLocalLink(); void sharedMemory_unlockLocalLink(); +void sharedMemory_lockAcqFlag(); +void sharedMemory_unlockAcqFlag(); #endif \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 0506650f6..eac0e2ecb 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -600,9 +600,6 @@ int setTransmissionDelayRight(int value); #endif // aquisition -#ifdef EIGERD -int prepareAcquisition(); -#endif int startStateMachine(); #ifdef VIRTUAL void *start_timer(void *arg); diff --git a/slsDetectorServers/slsDetectorServer/src/sharedMemory.c b/slsDetectorServers/slsDetectorServer/src/sharedMemory.c index ce4bee979..b14fe29c3 100644 --- a/slsDetectorServers/slsDetectorServer/src/sharedMemory.c +++ b/slsDetectorServers/slsDetectorServer/src/sharedMemory.c @@ -20,6 +20,7 @@ typedef struct Memory { pthread_mutex_t lockStatus; #ifdef EIGERD pthread_mutex_t lockLocalLink; + pthread_mutex_t lockAcqFlag; #endif enum runStatus scanStatus; // idle, running or error int scanStop; @@ -120,6 +121,7 @@ int sharedMemory_initialize() { #endif #ifdef EIGERD + // local link mutex pthread_mutexattr_t lockLocalLinkAttribute; if (pthread_mutexattr_init(&lockLocalLinkAttribute) != 0) { LOG(logERROR, @@ -141,6 +143,28 @@ int sharedMemory_initialize() { "shared memory\n")); return FAIL; } + // acq flag mutex + pthread_mutexattr_t lockAcqFlagAttribute; + if (pthread_mutexattr_init(&lockAcqFlagAttribute) != 0) { + LOG(logERROR, + ("Failed to initialize mutex attribute for lockAcqFlag for " + "shared memory\n")); + return FAIL; + } + + if (pthread_mutexattr_setpshared(&lockAcqFlagAttribute, + PTHREAD_PROCESS_SHARED) != 0) { + LOG(logERROR, ("Failed to set attribute property to process shared for " + "lockAcqFlag for shared memory\n")); + return FAIL; + } + + if (pthread_mutex_init(&(shm->lockAcqFlag), &lockAcqFlagAttribute) != + 0) { + LOG(logERROR, ("Failed to initialize pthread_mutex_t lockAcqFlag for " + "shared memory\n")); + return FAIL; + } #endif shm->scanStatus = IDLE; shm->scanStop = 0; @@ -266,4 +290,10 @@ void sharedMemory_lockLocalLink() { pthread_mutex_lock(&(shm->lockLocalLink)); } void sharedMemory_unlockLocalLink() { pthread_mutex_unlock(&(shm->lockLocalLink)); } + +void sharedMemory_lockAcqFlag() { pthread_mutex_lock(&(shm->lockAcqFlag)); } + +void sharedMemory_unlockAcqFlag() { + pthread_mutex_unlock(&(shm->lockAcqFlag)); +} #endif \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 1187580fb..363da4cbf 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -1909,9 +1909,6 @@ void *start_state_machine(void *arg) { } usleep(scanSettleTime_ns / 1000); } -#ifdef EIGERD - prepareAcquisition(); -#endif ret = startStateMachine(); LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret)); if (ret == FAIL) {