This commit is contained in:
maliakal_d 2020-06-29 20:01:55 +02:00
parent 75e9d63341
commit 285ef30439
10 changed files with 154 additions and 65 deletions

View File

@ -2360,6 +2360,10 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus()) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (!isControlServer) {
virtual_stop = 1; virtual_stop = 1;
@ -2380,26 +2384,25 @@ int stopStateMachine() {
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STP_ACQSTN_MSK); bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STP_ACQSTN_MSK);
usleep(WAIT_TIME_US_STP_ACQ); usleep(WAIT_TIME_US_STP_ACQ);
bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_STP_ACQSTN_MSK); bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_STP_ACQSTN_MSK);
LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG))); LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
return OK; return OK;
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
LOG(logDEBUG1, ("Getting status\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) {
virtual_status = sharedMemory_getStatus();
}
if (virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
} else {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n")); if (sharedMemory_getScanStatus()) {
LOG(logINFOBLUE, ("Status: Scan RUNNING\n"));
return RUNNING;
}
uint32_t retval = bus_r(STATUS_REG); uint32_t retval = bus_r(STATUS_REG);
LOG(logINFO, ("Status Register: %08x\n", retval)); LOG(logINFO, ("Status Register: %08x\n", retval));

View File

@ -2219,7 +2219,11 @@ void *start_timer(void *arg) {
#endif #endif
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Going to stop acquisition\n")); LOG(logINFORED, ("Stopping state machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus()) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (!isControlServer) {
virtual_stop = 1; virtual_stop = 1;
@ -2289,19 +2293,19 @@ int startReadOut() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
LOG(logDEBUG1, ("Getting status\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) {
virtual_status = sharedMemory_getStatus(); LOG(logINFOBLUE, ("Status: RUNNING\n"));
}
if (virtual_status == 0) {
LOG(logINFO, ("Status: IDLE\n"));
return IDLE;
} else {
LOG(logINFO, ("Status: RUNNING...\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#else #else
if (sharedMemory_getScanStatus()) {
LOG(logINFOBLUE, ("Status: Scan RUNNING\n"));
return RUNNING;
}
int i = Feb_Control_AcquisitionInProgress(); int i = Feb_Control_AcquisitionInProgress();
if (i == STATUS_ERROR) { if (i == STATUS_ERROR) {
LOG(logERROR, ("Status: ERROR reading status register\n")); LOG(logERROR, ("Status: ERROR reading status register\n"));

View File

@ -2407,6 +2407,10 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus()) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (!isControlServer) {
virtual_stop = 1; virtual_stop = 1;
@ -2430,19 +2434,19 @@ int stopStateMachine() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
LOG(logDEBUG1, ("Getting status\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) {
virtual_status = sharedMemory_getStatus();
}
if (virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
} else {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n")); if (sharedMemory_getScanStatus()) {
LOG(logINFOBLUE, ("Status: Scan RUNNING\n"));
return RUNNING;
}
uint32_t retval = bus_r(FLOW_STATUS_REG); uint32_t retval = bus_r(FLOW_STATUS_REG);
LOG(logINFO, ("Status Register: %08x\n", retval)); LOG(logINFO, ("Status Register: %08x\n", retval));

View File

@ -1635,6 +1635,10 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus()) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (!isControlServer) {
virtual_stop = 1; virtual_stop = 1;
@ -1669,20 +1673,19 @@ int stopStateMachine() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
LOG(logDEBUG1, ("Getting status\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) {
virtual_status = sharedMemory_getStatus();
}
if (virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
} else {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n")); if (sharedMemory_getScanStatus()) {
LOG(logINFOBLUE, ("Status: Scan RUNNING\n"));
return RUNNING;
}
enum runStatus s = IDLE; enum runStatus s = IDLE;
u_int32_t retval = runState(logINFO); u_int32_t retval = runState(logINFO);

View File

@ -1829,6 +1829,10 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus()) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (!isControlServer) {
virtual_stop = 1; virtual_stop = 1;
@ -1855,20 +1859,19 @@ int stopStateMachine() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
LOG(logDEBUG1, ("Getting status\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) {
virtual_status = sharedMemory_getStatus();
}
if (virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
} else {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n")); if (sharedMemory_getScanStatus()) {
LOG(logINFOBLUE, ("Status: Scan RUNNING\n"));
return RUNNING;
}
enum runStatus s; enum runStatus s;
u_int32_t retval = bus_r(STATUS_REG); u_int32_t retval = bus_r(STATUS_REG);
LOG(logINFO, ("Status Register: %08x\n", retval)); LOG(logINFO, ("Status Register: %08x\n", retval));

View File

@ -1992,6 +1992,10 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus()) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (!isControlServer) {
virtual_stop = 1; virtual_stop = 1;
@ -2019,20 +2023,19 @@ int stopStateMachine() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
LOG(logDEBUG1, ("Getting status\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) {
virtual_status = sharedMemory_getStatus();
}
if (virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
} else {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n")); if (sharedMemory_getScanStatus()) {
LOG(logINFOBLUE, ("Status: Scan RUNNING\n"));
return RUNNING;
}
uint32_t retval = bus_r(STATUS_REG); uint32_t retval = bus_r(STATUS_REG);
LOG(logINFO, ("Status Register: %08x\n", retval)); LOG(logINFO, ("Status Register: %08x\n", retval));

View File

@ -2102,6 +2102,10 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus()) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (!isControlServer) {
virtual_stop = 1; virtual_stop = 1;
@ -2125,19 +2129,19 @@ int stopStateMachine() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
LOG(logDEBUG1, ("Getting status\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) {
virtual_status = sharedMemory_getStatus();
}
if (virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
} else {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n")); if (sharedMemory_getScanStatus()) {
LOG(logINFOBLUE, ("Status: Scan RUNNING\n"));
return RUNNING;
}
uint32_t retval = bus_r(FLOW_STATUS_REG); uint32_t retval = bus_r(FLOW_STATUS_REG);
LOG(logINFO, ("Status Register: %08x\n", retval)); LOG(logINFO, ("Status Register: %08x\n", retval));

View File

@ -12,8 +12,13 @@ int sharedMemory_detach();
int sharedMemory_remove(); int sharedMemory_remove();
void sharedMemory_lock(); void sharedMemory_lock();
void sharedMemory_unlock(); void sharedMemory_unlock();
#ifdef VIRTUAL
void sharedMemory_setStatus(int s); void sharedMemory_setStatus(int s);
int sharedMemory_getStatus(); int sharedMemory_getStatus();
void sharedMemory_setStop(int s); void sharedMemory_setStop(int s);
int sharedMemory_getStop(); int sharedMemory_getStop();
#endif
void sharedMemory_setScanStatus(int s);
int sharedMemory_getScanStatus();
void sharedMemory_setScanStop(int s);
int sharedMemory_getScanStop();

View File

@ -20,6 +20,8 @@
typedef struct Memory { typedef struct Memory {
int version; int version;
sem_t sem; sem_t sem;
int scanStatus;
int scanStop;
#ifdef VIRTUAL #ifdef VIRTUAL
int status; int status;
int stop; int stop;
@ -139,6 +141,7 @@ void sharedMemory_lock() { sem_wait(&(shm->sem)); }
void sharedMemory_unlock() { sem_post(&(shm->sem)); } void sharedMemory_unlock() { sem_post(&(shm->sem)); }
#ifdef VIRTUAL
void sharedMemory_setStatus(int s) { void sharedMemory_setStatus(int s) {
sharedMemory_lock(); sharedMemory_lock();
shm->status = s; shm->status = s;
@ -166,3 +169,32 @@ int sharedMemory_getStop() {
sharedMemory_unlock(); sharedMemory_unlock();
return s; return s;
} }
#endif
void sharedMemory_setScanStatus(int s) {
sharedMemory_lock();
shm->scanStatus = s;
sharedMemory_unlock();
}
int sharedMemory_getScanStatus() {
int s = 0;
sharedMemory_lock();
s = shm->scanStatus;
sharedMemory_unlock();
return s;
}
void sharedMemory_setScanStop(int s) {
sharedMemory_lock();
shm->scanStop = s;
sharedMemory_unlock();
}
int sharedMemory_getScanStop() {
int s = 0;
sharedMemory_lock();
s = shm->scanStop;
sharedMemory_unlock();
return s;
}

View File

@ -1,6 +1,7 @@
#include "slsDetectorServer_funcs.h" #include "slsDetectorServer_funcs.h"
#include "clogger.h" #include "clogger.h"
#include "communication_funcs.h" #include "communication_funcs.h"
#include "sharedMemory.h"
#include "slsDetectorFunctionList.h" #include "slsDetectorFunctionList.h"
#include "sls_detector_funcs.h" #include "sls_detector_funcs.h"
@ -1725,10 +1726,19 @@ int start_state_machine(int blocking, int file_des) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else { } else {
int times = 1; int times = 1;
// start of scan
if (scan) { if (scan) {
sharedMemory_setScanStop(0);
sharedMemory_setScanStatus(1);
times = numScanSteps; times = numScanSteps;
} }
for (int i = 0; i != times; ++i) { for (int i = 0; i != times; ++i) {
// if scanstop
if (scan && sharedMemory_getScanStop()) {
LOG(logINFORED, ("Scan stopped!\n"));
sharedMemory_setScanStatus(0);
break;
}
if (scanTrimbits) { if (scanTrimbits) {
LOG(logINFOBLUE, ("Trimbits scan %d/%d: [%d]\n", i, times, LOG(logINFOBLUE, ("Trimbits scan %d/%d: [%d]\n", i, times,
scanSteps[i])); scanSteps[i]));
@ -1744,15 +1754,27 @@ int start_state_machine(int blocking, int file_des) {
int retval = getDAC(scanDac, 0); int retval = getDAC(scanDac, 0);
if (abs(retval - scanSteps[i]) > 5) { if (abs(retval - scanSteps[i]) > 5) {
ret = FAIL; ret = FAIL;
sprintf(mess, "Setting dac %d : wrote %d but read %d\n", sprintf(mess,
"Could not scan. Setting dac %d : wrote %d but "
"read %d\n",
scanDac, scanSteps[i], scanSteps[i]); scanDac, scanSteps[i], scanSteps[i]);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
if (scan) {
sharedMemory_setScanStatus(0);
}
break; break;
} }
} else { } else {
LOG(logINFOBLUE, ("Normal Acquisition (not scan)\n")); LOG(logINFOBLUE, ("Normal Acquisition (not scan)\n"));
} }
// if scanstop
if (scan && sharedMemory_getScanStop()) {
LOG(logINFORED, ("Scan stopped!\n"));
sharedMemory_setScanStatus(0);
break;
}
ret = startStateMachine(); ret = startStateMachine();
LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret));
if (ret == FAIL) { if (ret == FAIL) {
#if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(VIRTUAL) #if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(VIRTUAL)
sprintf( sprintf(
@ -1763,6 +1785,9 @@ int start_state_machine(int blocking, int file_des) {
sprintf(mess, "Could not start acquisition\n"); sprintf(mess, "Could not start acquisition\n");
#endif #endif
LOG(logERROR, (mess)); LOG(logERROR, (mess));
if (scan) {
sharedMemory_setScanStatus(0);
}
break; break;
} }
// blocking or scan // blocking or scan
@ -1771,7 +1796,10 @@ int start_state_machine(int blocking, int file_des) {
} }
} }
} }
LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret)); // end of scan
if (scan) {
sharedMemory_setScanStatus(0);
}
} }
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
} }