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

View File

@ -2219,7 +2219,11 @@ void *start_timer(void *arg) {
#endif
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
if (!isControlServer) {
virtual_stop = 1;
@ -2289,19 +2293,19 @@ int startReadOut() {
}
enum runStatus getRunStatus() {
LOG(logDEBUG1, ("Getting status\n"));
#ifdef VIRTUAL
if (!isControlServer) {
virtual_status = sharedMemory_getStatus();
}
if (virtual_status == 0) {
LOG(logINFO, ("Status: IDLE\n"));
return IDLE;
} else {
LOG(logINFO, ("Status: RUNNING...\n"));
if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) {
LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING;
}
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#else
if (sharedMemory_getScanStatus()) {
LOG(logINFOBLUE, ("Status: Scan RUNNING\n"));
return RUNNING;
}
int i = Feb_Control_AcquisitionInProgress();
if (i == STATUS_ERROR) {
LOG(logERROR, ("Status: ERROR reading status register\n"));

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,8 +12,13 @@ int sharedMemory_detach();
int sharedMemory_remove();
void sharedMemory_lock();
void sharedMemory_unlock();
#ifdef VIRTUAL
void sharedMemory_setStatus(int s);
int sharedMemory_getStatus();
void sharedMemory_setStop(int s);
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 {
int version;
sem_t sem;
int scanStatus;
int scanStop;
#ifdef VIRTUAL
int status;
int stop;
@ -139,6 +141,7 @@ void sharedMemory_lock() { sem_wait(&(shm->sem)); }
void sharedMemory_unlock() { sem_post(&(shm->sem)); }
#ifdef VIRTUAL
void sharedMemory_setStatus(int s) {
sharedMemory_lock();
shm->status = s;
@ -166,3 +169,32 @@ int sharedMemory_getStop() {
sharedMemory_unlock();
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 "clogger.h"
#include "communication_funcs.h"
#include "sharedMemory.h"
#include "slsDetectorFunctionList.h"
#include "sls_detector_funcs.h"
@ -1725,10 +1726,19 @@ int start_state_machine(int blocking, int file_des) {
LOG(logERROR, (mess));
} else {
int times = 1;
// start of scan
if (scan) {
sharedMemory_setScanStop(0);
sharedMemory_setScanStatus(1);
times = numScanSteps;
}
for (int i = 0; i != times; ++i) {
// if scanstop
if (scan && sharedMemory_getScanStop()) {
LOG(logINFORED, ("Scan stopped!\n"));
sharedMemory_setScanStatus(0);
break;
}
if (scanTrimbits) {
LOG(logINFOBLUE, ("Trimbits scan %d/%d: [%d]\n", i, times,
scanSteps[i]));
@ -1744,15 +1754,27 @@ int start_state_machine(int blocking, int file_des) {
int retval = getDAC(scanDac, 0);
if (abs(retval - scanSteps[i]) > 5) {
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]);
LOG(logERROR, (mess));
if (scan) {
sharedMemory_setScanStatus(0);
}
break;
}
} else {
LOG(logINFOBLUE, ("Normal Acquisition (not scan)\n"));
}
// if scanstop
if (scan && sharedMemory_getScanStop()) {
LOG(logINFORED, ("Scan stopped!\n"));
sharedMemory_setScanStatus(0);
break;
}
ret = startStateMachine();
LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret));
if (ret == FAIL) {
#if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(VIRTUAL)
sprintf(
@ -1763,6 +1785,9 @@ int start_state_machine(int blocking, int file_des) {
sprintf(mess, "Could not start acquisition\n");
#endif
LOG(logERROR, (mess));
if (scan) {
sharedMemory_setScanStatus(0);
}
break;
}
// 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);
}