fix using real detectors, moving readconfig to end (due to initialization)

This commit is contained in:
maliakal_d 2020-05-11 19:26:22 +02:00
parent 6620027439
commit 5aaefc8e00
10 changed files with 1396 additions and 1335 deletions

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,7 @@ unsigned int Beb_GetBebInfoIndex(unsigned int beb_numb);
void Beb_GetModuleConfiguration(int *master, int *top, int *normal);
int Beb_IsTransmitting(int *retval, int tengiga, int waitForDelay);
void Beb_SetTopVariable(int val);
int Beb_SetTop(enum TOPINDEX ind);
int Beb_SetMaster(enum MASTERINDEX ind);
int Beb_Activate(int enable);

View File

@ -2463,10 +2463,10 @@ int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right) {
uint32_t offset = DAQ_REG_HRDWRE;
unsigned int addr[2] = {0, 0};
if (left) {
addr[0] = Module_GetTopLeftAddress(&modules[0]);
addr[0] = Module_GetTopLeftAddress(&modules[1]);
}
if (right) {
addr[1] = Module_GetTopRightAddress(&modules[0]);
addr[1] = Module_GetTopRightAddress(&modules[1]);
}
char *top_names[] = {TOP_NAMES};
int i = 0;
@ -2497,8 +2497,7 @@ int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right) {
return 0;
}
if (!Feb_Interface_WriteRegister(addr[i], offset, value, 0, 0)) {
LOG(logERROR, ("Could not set Top flag to %s in %s Feb\n", val,
top_names[ind], (i == 0 ? "left" : "right")));
LOG(logERROR, ("Could not set Top flag to %s in %s Feb\n", top_names[ind], (i == 0 ? "left" : "right")));
return 0;
}
}
@ -2510,11 +2509,13 @@ int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right) {
return 1;
}
void Feb_Control_SetMasterVariable(int val) {Feb_control_master = val;}
int Feb_Control_SetMaster(enum MASTERINDEX ind) {
uint32_t offset = DAQ_REG_HRDWRE;
unsigned int addr[2] = {0, 0};
addr[0] = Module_GetTopLeftAddress(&modules[0]);
addr[1] = Module_GetTopRightAddress(&modules[0]);
addr[0] = Module_GetTopLeftAddress(&modules[1]);
addr[1] = Module_GetTopRightAddress(&modules[1]);
char *master_names[] = {MASTER_NAMES};
int i = 0;
for (i = 0; i < 2; ++i) {
@ -2538,12 +2539,11 @@ int Feb_Control_SetMaster(enum MASTERINDEX ind) {
break;
default:
LOG(logERROR, ("Unknown master index in Feb: %d\n", ind));
Beb_close(fd, csp0base);
return 0;
}
if (!Feb_Interface_WriteRegister(addr[i], offset, value, 0, 0)) {
LOG(logERROR, ("Could not set Master flag to %s in %s Feb\n", val,
LOG(logERROR, ("Could not set Master flag to %s in %s Feb\n",
master_names[ind], (i == 0 ? "left" : "right")));
return 0;
}
@ -2560,7 +2560,8 @@ int Feb_Control_SetQuad(int val) {
return 1;
}
LOG(logINFO, ("Setting Quad to %d in Feb\n", val));
return Feb_Control_SetTop(val, 0, 1);
// only setting on the right feb if quad
return Feb_Control_SetTop(val == 0 ? TOP_HARDWARE : OW_TOP, 0, 1);
}
int Feb_Control_SetReadNLines(int value) {
@ -2644,6 +2645,7 @@ int Feb_Control_ReadRegister(uint32_t offset, uint32_t *retval) {
addr[1] = Module_TopAddressIsValid(&modules[1])
? Module_GetTopLeftAddress(&modules[1])
: Module_GetBottomLeftAddress(&modules[1]);
uint32_t value[2] = {0, 0};
int run[2] = {0, 0};

View File

@ -1,5 +1,6 @@
#pragma once
#include "FebInterface.h"
#include "slsDetectorServer_defs.h"
#include <netinet/in.h>
struct Module {
@ -176,6 +177,7 @@ int Feb_Control_SetInterruptSubframe(int val);
int Feb_Control_GetInterruptSubframe();
int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right);
void Feb_Control_SetMasterVariable(int val);
int Feb_Control_SetMaster(enum MASTERINDEX ind);
int Feb_Control_SetQuad(int val);
int Feb_Control_SetReadNLines(int value);

View File

@ -226,6 +226,20 @@ u_int64_t getFirmwareAPIVersion() {
#endif
}
void readDetectorNumber() {
#ifdef VIRTUAL
return;
#endif
char output[255];
FILE *sysFile = popen(IDFILECOMMAND, "r");
fgets(output, sizeof(output), sysFile);
pclose(sysFile);
sscanf(output, "%u", &detid);
if (isControlServer) {
LOG(logINFOBLUE, ("Detector ID: %u\n", detid));
}
}
u_int32_t getDetectorNumber() {
#ifdef VIRTUAL
return 0;
@ -309,97 +323,67 @@ u_int32_t getDetectorIP() {
/* initialization */
void initControlServer() {
master = -1;
top = -1;
// force top or master if in config file
if (readConfigFile() == FAIL) {
return;
}
#ifdef VIRTUAL
LOG(logINFOBLUE, ("Configuring Control server\n"));
if (initError == OK) {
readDetectorNumber();
getModuleConfiguration();
setupDetector();
}
eiger_virtual_activate = 0;
LOG(logINFORED, ("Deactivated!\n"));
initCheckDone = 1;
return;
#else
if (initError == OK) {
// Feb and Beb Initializations
getModuleConfiguration();
#ifndef VIRTUAL
Feb_Control_SetMasterVariable(master);
Feb_Interface_FebInterface();
Feb_Control_FebControl();
// different addresses for top and bottom
if (getFirmwareVersion() < FIRMWARE_VERSION_SAME_TOP_BOT_ADDR) {
Feb_Control_Init(master, top, normal, getDetectorNumber());
}
// same addresses for top and bottom
else {
Feb_Control_Init(master, 1, normal, getDetectorNumber());
}
Feb_Control_Init(master, 1, normal, getDetectorNumber());
// master of 9M, check high voltage serial communication to blackfin
if (master && !normal) {
if (Feb_Control_OpenSerialCommunication())
; // Feb_Control_CloseSerialCommunication();
}
LOG(logDEBUG1, ("Control server: FEB Initialization done\n"));
Beb_SetTopVariable(top);
Beb_Beb(detid);
Beb_SetDetectorNumber(getDetectorNumber());
LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
#endif
// also reads config file and deactivates
setupDetector();
// client first connect (from shm) will activate
Beb_Activate(0);
Feb_Control_activate(0);
}
initCheckDone = 1;
#endif
}
void initStopServer() {
master = -1;
top = -1;
#ifdef VIRTUAL
// force top or master if in config file
if (readConfigFile() == FAIL) {
return;
}
LOG(logINFOBLUE, ("Configuring Stop server\n"));
getModuleConfiguration();
virtual_stop = 0;
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
eiger_virtual_activate = 0;
LOG(logINFORED, ("Deactivated!\n"));
return;
// get top/master in virtual
readConfigFile();
#else
// wait till control server has configured top/master
usleep(2 * 1000 * 1000);
// wait a few s (control server is setting top/master from config file)
usleep(WAIT_STOP_SERVER_START);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
//exit(-1);
readDetectorNumber();
getModuleConfiguration();
Feb_Control_SetMasterVariable(master);
Feb_Interface_FebInterface();
Feb_Control_FebControl();
// different addresses for top and bottom
if (getFirmwareVersion() < FIRMWARE_VERSION_SAME_TOP_BOT_ADDR) {
Feb_Control_Init(master, top, normal, getDetectorNumber());
}
// same addresses for top and bottom
else {
Feb_Control_Init(master, 1, normal, getDetectorNumber());
}
Feb_Control_Init(master, 1, normal, getDetectorNumber());
LOG(logDEBUG1, ("Stop server: FEB Initialization done\n"));
// client first connect (from shm) will activate
Beb_Activate(0);
Feb_Control_activate(0);
#endif
// client first connect (from shm) will activate
if (setActivate(0) == FAIL) {
LOG(logERROR, ("Could not deactivate in stop server\n"));
}
}
void getModuleConfiguration() {
if (initError == FAIL) {
return;
}
#ifdef VIRTUAL
// if master not modified by config file
if (master == -1) {
@ -429,16 +413,6 @@ void getModuleConfiguration() {
#endif
#else
// read detector id
char output[255];
FILE *sysFile = popen(IDFILECOMMAND, "r");
fgets(output, sizeof(output), sysFile);
pclose(sysFile);
sscanf(output, "%u", &detid);
if (isControlServer) {
LOG(logINFOBLUE, ("Detector ID: %u\n\n", detid));
}
Beb_GetModuleConfiguration(&master, &top, &normal);
#endif
if (isControlServer) {
@ -453,12 +427,14 @@ int readConfigFile() {
if (initError == FAIL) {
return initError;
}
master = -1;
top = -1;
FILE *fd = fopen(CONFIG_FILE, "r");
if (fd == NULL) {
LOG(logINFO, ("No config file found. Resetting to hardware settings (Top/Master)\n"));
// reset to hardware settings if not in config file (if overwritten)
resetToHardwareSettings();
return OK;
return initError;
}
LOG(logINFO, ("Reading config file %s\n", CONFIG_FILE));
@ -470,7 +446,6 @@ int readConfigFile() {
// keep reading a line
while (fgets(line, LZ, fd)) {
// ignore comments
if (line[0] == '#') {
LOG(logDEBUG1, ("Ignoring Comment\n"));
@ -521,6 +496,15 @@ int readConfigFile() {
top, line);
break;
}
// validate change
int actual_top = -1, temp = -1, temp2 = -1;
Beb_GetModuleConfiguration(&temp, &actual_top, &temp2);
if (actual_top != top) {
sprintf(initErrorMessage,
"Could not set top to %d. Read %d\n", top, actual_top);
break;
}
Beb_SetTopVariable(top);
#endif
}
@ -552,6 +536,15 @@ int readConfigFile() {
master, line);
break;
}
// validate change
int actual_master = -1, temp = -1, temp2 = -1;
Beb_GetModuleConfiguration(&actual_master, &temp, &temp2);
if (actual_master != master) {
sprintf(initErrorMessage,
"Could not set master to %d. Read %d\n", master, actual_master);
break;
}
Feb_Control_SetMasterVariable(master);
#endif
}
@ -566,51 +559,66 @@ int readConfigFile() {
}
fclose(fd);
// reset to hardware settings if not in config file (if overwritten)
resetToHardwareSettings();
if (strlen(initErrorMessage)) {
initError = FAIL;
LOG(logERROR, ("%s\n\n", initErrorMessage));
} else {
LOG(logINFO, ("Successfully read config file\n"));
}
// reset to hardware settings if not in config file (if overwritten)
resetToHardwareSettings();
return initError;
}
int resetToHardwareSettings() {
void resetToHardwareSettings() {
#ifndef VIRTUAL
if (initError == FAIL) {
return;
}
// top not set in config file
if (top == -1) {
if (!Beb_SetTop(TOP_HARDWARE)) {
initError = FAIL;
sprintf(initErrorMessage,
strcpy(initErrorMessage,
"Could not reset Top flag to Beb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
return;
}
if (!Feb_Control_SetTop(TOP_HARDWARE, 1, 1)) {
initError = FAIL;
sprintf(initErrorMessage,
strcpy(initErrorMessage,
"Could not reset Top flag to Feb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
return;
}
getModuleConfiguration();
Beb_SetTopVariable(top);
}
// master not set in config file
if (master == -1) {
if (!Beb_SetMaster(TOP_HARDWARE)) {
initError = FAIL;
sprintf(initErrorMessage,
strcpy(initErrorMessage,
"Could not reset Master flag to Beb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
return;
}
if (!Feb_Control_SetMaster(TOP_HARDWARE)) {
initError = FAIL;
sprintf(initErrorMessage,
strcpy(initErrorMessage,
"Could not reset Master flag to Feb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
return;
}
getModuleConfiguration();
Feb_Control_SetMasterVariable(master);
}
#endif
}
/* set up detector */
void allocateDetectorStructureMemory() {
@ -696,6 +704,17 @@ void setupDetector() {
#ifndef VIRTUAL
Feb_Control_CheckSetup();
#endif
// force top or master if in config file
if (readConfigFile() == FAIL) {
return;
}
// client first connect (from shm) will activate
if (setActivate(0) == FAIL) {
initError = FAIL;
sprintf(initErrorMessage, "Could not deactivate\n");
LOG(logERROR, (initErrorMessage));
}
LOG(logDEBUG1, ("Setup detector done\n\n"));
}
@ -1860,21 +1879,37 @@ int getBebFPGATemp() {
#endif
}
int activate(int enable) {
#ifdef VIRTUAL
if (enable >= 0)
eiger_virtual_activate = enable;
if (eiger_virtual_activate == 0) {
LOG(logINFORED, ("Deactivated!\n"));
} else {
LOG(logINFOGREEN, ("Activated!\n"));
int setActivate(int enable) {
if (enable < 0) {
LOG(logERROR, ("Invalid activate argument: %d\n", enable));
return FAIL;
}
return eiger_virtual_activate;
enable = enable == 0 ? 0 : 1;
#ifdef VIRTUAL
eiger_virtual_activate = enable;
#else
int ret = Beb_Activate(enable);
Feb_Control_activate(ret);
return ret;
if (!Beb_SetActivate(enable)) {
return FAIL;
}
Feb_Control_activate(enable);
#endif
if (enable == 0) {
LOG(logINFORED, ("Deactivated in %s Server!\n", isControlServer ? " Control" : "Stop"));
} else {
LOG(logINFOGREEN, ("Activated in %s Server!\n", isControlServer ? " Control" : "Stop"));
}
return OK;
}
int getActivate(int* retval) {
#ifdef VIRTUAL
*retval = eiger_virtual_activate;
#else
if (!Beb_GetActivate(retval)) {
return FAIL;
}
#endif
return OK;
}
int getTenGigaFlowControl() {
@ -2310,7 +2345,7 @@ enum runStatus getRunStatus() {
return ERROR;
}
if (isTransmitting) {
printf("Status: TRANSMITTING\n");
LOG(logINFOBLUE, ("Status: TRANSMITTING\n"));
return TRANSMITTING;
}
LOG(logINFOBLUE, ("Status: IDLE\n"));
@ -2360,7 +2395,7 @@ void readFrame(int *ret, char *mess) {
printf("Transmitting...\n");
}
}
printf("Detector has sent all data\n");
LOG(logINFO, ("Detector has sent all data\n"));
LOG(logINFOGREEN, ("Acquisition successfully finished\n"));
#endif
}

View File

@ -4,7 +4,7 @@
#define REQUIRED_FIRMWARE_VERSION (26)
#define IDFILECOMMAND "more /home/root/executables/detid.txt"
#define CONFIG_FILE ("config.txt")
#define FIRMWARE_VERSION_SAME_TOP_BOT_ADDR (26)
#define WAIT_STOP_SERVER_START (1 * 1000 * 1000)
#define STATUS_IDLE 0
#define STATUS_RUNNING 1

View File

@ -84,6 +84,9 @@ u_int16_t getHardwareSerialNumber();
#ifdef JUNGFRAUD
int isHardwareVersion2();
#endif
#ifdef EIGERD
void readDetectorNumber();
#endif
u_int32_t getDetectorNumber();
u_int64_t getDetectorMAC();
u_int32_t getDetectorIP();
@ -116,7 +119,7 @@ int setDefaultDacs();
int readConfigFile();
#endif
#ifdef EIGERD
int resetToHardwareSettings();
void resetToHardwareSettings();
#endif
// advanced read/write reg
@ -435,7 +438,8 @@ void setExternalGating(int enable[]);
int setAllTrimbits(int val);
int getAllTrimbits();
int getBebFPGATemp();
int activate(int enable);
int setActivate(int enable);
int getActivate(int* retval);
// gotthard specific - adc phase
#elif GOTTHARDD

View File

@ -4119,9 +4119,23 @@ int set_activate(int file_des) {
#else
// set & get
if ((arg == -1) || (Server_VerifyLock() == OK)) {
retval = activate(arg);
LOG(logDEBUG1, ("Activate: %d\n", retval));
validate(arg, retval, "set activate", DEC);
if (arg >= 0) {
if (setActivate(arg) == FAIL) {
ret = FAIL;
sprintf(mess, "Could not %s\n", (arg == 0 ? "deactivate" : "activate"));
LOG(logERROR, (mess));
}
}
if (ret == OK) {
if (getActivate(&retval) == FAIL) {
ret = FAIL;
sprintf(mess, "Could not get activate flag\n");
LOG(logERROR, (mess));
} else {
LOG(logDEBUG1, ("Activate: %d\n", retval));
validate(arg, retval, "set/get activate", DEC);
}
}
}
#endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
@ -7264,7 +7278,8 @@ int get_receiver_parameters(int file_des) {
// activate
#ifdef EIGERD
i32 = activate(-1);
i32 = 0;
getActivate(&i32);
#else
i32 = 0;
#endif

View File

@ -10,4 +10,4 @@
#define APIJUNGFRAU 0x200508
#define APIMYTHEN3 0x200508
#define APIMOENCH 0x200508
#define APIEIGER 0x200508
#define APIEIGER 0x200511