mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-05 17:40:40 +02:00
merge from develpoer, locking complete set of start acq steps and stop steps in eiger server as it shouldnt be interrutped, moved prepare into startstatemachine (#577)
This commit is contained in:
parent
a921368dea
commit
74a2f07c7d
Binary file not shown.
@ -2424,42 +2424,44 @@ int setTransmissionDelayRight(int value) {
|
|||||||
|
|
||||||
/* aquisition */
|
/* 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() {
|
int startStateMachine() {
|
||||||
|
sharedMemory_lockAcqFlag();
|
||||||
|
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
// create udp socket
|
// create udp socket
|
||||||
if (createUDPSocket(0) != OK) {
|
if (createUDPSocket(0) != OK) {
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (createUDPSocket(1) != OK) {
|
if (createUDPSocket(1) != OK) {
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||||
if (sharedMemory_getStop() != 0) {
|
if (sharedMemory_getStop() != 0) {
|
||||||
LOG(logERROR, ("Cant start acquisition. "
|
LOG(logERROR, ("Cant start acquisition. "
|
||||||
"Stop server has not updated stop status to 0\n"));
|
"Stop server has not updated stop status to 0\n"));
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
sharedMemory_setStatus(RUNNING);
|
sharedMemory_setStatus(RUNNING);
|
||||||
if (pthread_create(&virtual_tid, NULL, &start_timer, NULL)) {
|
if (pthread_create(&virtual_tid, NULL, &start_timer, NULL)) {
|
||||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||||
sharedMemory_setStatus(IDLE);
|
sharedMemory_setStatus(IDLE);
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
LOG(logINFO, ("Virtual Acquisition started\n"));
|
LOG(logINFO, ("Virtual Acquisition started\n"));
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return OK;
|
return OK;
|
||||||
#else
|
#else
|
||||||
sharedMemory_lockLocalLink();
|
sharedMemory_lockLocalLink();
|
||||||
|
|
||||||
|
LOG(logINFO, ("Going to prepare for acquisition with counter_bit:%d\n",
|
||||||
|
Feb_Control_Get_Counter_Bit()));
|
||||||
|
Feb_Control_PrepareForAcquisition();
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
@ -2477,12 +2479,13 @@ int startStateMachine() {
|
|||||||
LOG(logERROR,
|
LOG(logERROR,
|
||||||
("Acquisition did not LOG(logERROR ouble reading register\n"));
|
("Acquisition did not LOG(logERROR ouble reading register\n"));
|
||||||
sharedMemory_unlockLocalLink();
|
sharedMemory_unlockLocalLink();
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
LOG(logINFOGREEN, ("Acquisition started\n"));
|
LOG(logINFOGREEN, ("Acquisition started\n"));
|
||||||
}
|
}
|
||||||
sharedMemory_unlockLocalLink();
|
sharedMemory_unlockLocalLink();
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return ret;
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2776,6 +2779,10 @@ void *start_timer(void *arg) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int stopStateMachine() {
|
int stopStateMachine() {
|
||||||
|
|
||||||
|
// acq lock for seamless stop
|
||||||
|
sharedMemory_lockAcqFlag();
|
||||||
|
|
||||||
LOG(logINFORED, ("Stopping state machine\n"));
|
LOG(logINFORED, ("Stopping state machine\n"));
|
||||||
// if scan active, stop scan
|
// if scan active, stop scan
|
||||||
if (sharedMemory_getScanStatus() == RUNNING) {
|
if (sharedMemory_getScanStatus() == RUNNING) {
|
||||||
@ -2788,6 +2795,7 @@ int stopStateMachine() {
|
|||||||
usleep(500);
|
usleep(500);
|
||||||
sharedMemory_setStop(0);
|
sharedMemory_setStop(0);
|
||||||
LOG(logINFO, ("Stopped State Machine\n"));
|
LOG(logINFO, ("Stopped State Machine\n"));
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return OK;
|
return OK;
|
||||||
#else
|
#else
|
||||||
sharedMemory_lockLocalLink();
|
sharedMemory_lockLocalLink();
|
||||||
@ -2795,6 +2803,7 @@ int stopStateMachine() {
|
|||||||
if (!Feb_Control_StopAcquisition()) {
|
if (!Feb_Control_StopAcquisition()) {
|
||||||
LOG(logERROR, ("failed to stop acquisition\n"));
|
LOG(logERROR, ("failed to stop acquisition\n"));
|
||||||
sharedMemory_unlockLocalLink();
|
sharedMemory_unlockLocalLink();
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
sharedMemory_unlockLocalLink();
|
sharedMemory_unlockLocalLink();
|
||||||
@ -2805,6 +2814,7 @@ int stopStateMachine() {
|
|||||||
// wait for beb to send out all packets
|
// wait for beb to send out all packets
|
||||||
if (Beb_IsTransmitting(&isTransmitting, send_to_ten_gig, 1) == FAIL) {
|
if (Beb_IsTransmitting(&isTransmitting, send_to_ten_gig, 1) == FAIL) {
|
||||||
LOG(logERROR, ("failed to stop beb acquisition\n"));
|
LOG(logERROR, ("failed to stop beb acquisition\n"));
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (isTransmitting) {
|
if (isTransmitting) {
|
||||||
@ -2815,12 +2825,11 @@ int stopStateMachine() {
|
|||||||
|
|
||||||
// reset feb and beb
|
// reset feb and beb
|
||||||
sharedMemory_lockLocalLink();
|
sharedMemory_lockLocalLink();
|
||||||
// uncommenting this out as it randomly does not set the processing bit to
|
Feb_Control_Reset();
|
||||||
// high
|
|
||||||
// Feb_Control_Reset();
|
|
||||||
sharedMemory_unlockLocalLink();
|
sharedMemory_unlockLocalLink();
|
||||||
if (!Beb_StopAcquisition()) {
|
if (!Beb_StopAcquisition()) {
|
||||||
LOG(logERROR, ("failed to stop acquisition\n"));
|
LOG(logERROR, ("failed to stop acquisition\n"));
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2830,6 +2839,7 @@ int stopStateMachine() {
|
|||||||
Beb_SetNextFrameNumber(retval + 1);
|
Beb_SetNextFrameNumber(retval + 1);
|
||||||
}
|
}
|
||||||
LOG(logINFOBLUE, ("Stopping state machine complete\n\n"));
|
LOG(logINFOBLUE, ("Stopping state machine complete\n\n"));
|
||||||
|
sharedMemory_unlockAcqFlag();
|
||||||
return OK;
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,6 @@ int sharedMemory_getScanStop();
|
|||||||
#ifdef EIGERD
|
#ifdef EIGERD
|
||||||
void sharedMemory_lockLocalLink();
|
void sharedMemory_lockLocalLink();
|
||||||
void sharedMemory_unlockLocalLink();
|
void sharedMemory_unlockLocalLink();
|
||||||
|
void sharedMemory_lockAcqFlag();
|
||||||
|
void sharedMemory_unlockAcqFlag();
|
||||||
#endif
|
#endif
|
@ -652,9 +652,6 @@ int setTransmissionDelayRight(int value);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// aquisition
|
// aquisition
|
||||||
#ifdef EIGERD
|
|
||||||
int prepareAcquisition();
|
|
||||||
#endif
|
|
||||||
int startStateMachine();
|
int startStateMachine();
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
void *start_timer(void *arg);
|
void *start_timer(void *arg);
|
||||||
|
@ -20,6 +20,7 @@ typedef struct Memory {
|
|||||||
pthread_mutex_t lockStatus;
|
pthread_mutex_t lockStatus;
|
||||||
#ifdef EIGERD
|
#ifdef EIGERD
|
||||||
pthread_mutex_t lockLocalLink;
|
pthread_mutex_t lockLocalLink;
|
||||||
|
pthread_mutex_t lockAcqFlag;
|
||||||
#endif
|
#endif
|
||||||
enum runStatus scanStatus; // idle, running or error
|
enum runStatus scanStatus; // idle, running or error
|
||||||
int scanStop;
|
int scanStop;
|
||||||
@ -120,6 +121,7 @@ int sharedMemory_initialize() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EIGERD
|
#ifdef EIGERD
|
||||||
|
// local link mutex
|
||||||
pthread_mutexattr_t lockLocalLinkAttribute;
|
pthread_mutexattr_t lockLocalLinkAttribute;
|
||||||
if (pthread_mutexattr_init(&lockLocalLinkAttribute) != 0) {
|
if (pthread_mutexattr_init(&lockLocalLinkAttribute) != 0) {
|
||||||
LOG(logERROR,
|
LOG(logERROR,
|
||||||
@ -141,6 +143,28 @@ int sharedMemory_initialize() {
|
|||||||
"shared memory\n"));
|
"shared memory\n"));
|
||||||
return FAIL;
|
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
|
#endif
|
||||||
shm->scanStatus = IDLE;
|
shm->scanStatus = IDLE;
|
||||||
shm->scanStop = 0;
|
shm->scanStop = 0;
|
||||||
@ -266,4 +290,10 @@ void sharedMemory_lockLocalLink() { pthread_mutex_lock(&(shm->lockLocalLink)); }
|
|||||||
void sharedMemory_unlockLocalLink() {
|
void sharedMemory_unlockLocalLink() {
|
||||||
pthread_mutex_unlock(&(shm->lockLocalLink));
|
pthread_mutex_unlock(&(shm->lockLocalLink));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sharedMemory_lockAcqFlag() { pthread_mutex_lock(&(shm->lockAcqFlag)); }
|
||||||
|
|
||||||
|
void sharedMemory_unlockAcqFlag() {
|
||||||
|
pthread_mutex_unlock(&(shm->lockAcqFlag));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
@ -2022,9 +2022,6 @@ void *start_state_machine(void *arg) {
|
|||||||
}
|
}
|
||||||
usleep(scanSettleTime_ns / 1000);
|
usleep(scanSettleTime_ns / 1000);
|
||||||
}
|
}
|
||||||
#ifdef EIGERD
|
|
||||||
prepareAcquisition();
|
|
||||||
#endif
|
|
||||||
ret = startStateMachine();
|
ret = startStateMachine();
|
||||||
LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret));
|
LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret));
|
||||||
if (ret == FAIL) {
|
if (ret == FAIL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user