configuing master from command lineg

This commit is contained in:
maliakal_d 2022-02-25 16:03:11 +01:00
parent 5869c25658
commit 5566cfd24f
12 changed files with 463 additions and 272 deletions

View File

@ -433,17 +433,22 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
if (mapCSP0() == FAIL) { if (mapCSP0() == FAIL) {
LOG(logERROR, initError = FAIL;
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); strcpy(initErrorMessage,
exit(EXIT_FAILURE); "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
} }
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
#endif #endif
} }
initCheckDone = 1;
}
/* set up detector */ /* set up detector */

View File

@ -18,7 +18,7 @@
const unsigned int Feb_Control_leftAddress = 0x100; const unsigned int Feb_Control_leftAddress = 0x100;
const unsigned int Feb_Control_rightAddress = 0x200; const unsigned int Feb_Control_rightAddress = 0x200;
int Feb_Control_master = 0; int Feb_Control_master = -1;
int Feb_Control_normal = 0; int Feb_Control_normal = 0;
int Feb_Control_activated = 1; int Feb_Control_activated = 1;
@ -50,17 +50,16 @@ double ratemax = -1;
// setup // setup
void Feb_Control_activate(int activate) { Feb_Control_activated = activate; } void Feb_Control_activate(int activate) { Feb_Control_activated = activate; }
void Feb_Control_FebControl() { int Feb_Control_FebControl(int normal) {
Feb_Control_staticBits = Feb_Control_acquireNReadoutMode = Feb_Control_staticBits = 0;
Feb_Control_triggerMode = Feb_Control_externalEnableMode = Feb_Control_acquireNReadoutMode = 0;
Feb_Control_triggerMode = 0;
Feb_Control_externalEnableMode = 0;
Feb_Control_subFrameMode = 0; Feb_Control_subFrameMode = 0;
Feb_Control_trimbit_size = 263680; Feb_Control_trimbit_size = 263680;
Feb_Control_last_downloaded_trimbits = Feb_Control_last_downloaded_trimbits =
malloc(Feb_Control_trimbit_size * sizeof(int)); malloc(Feb_Control_trimbit_size * sizeof(int));
}
int Feb_Control_Init(int master, int normal) {
Feb_Control_master = master;
Feb_Control_normal = normal; Feb_Control_normal = normal;
Feb_Interface_SetAddress(Feb_Control_rightAddress, Feb_Control_leftAddress); Feb_Interface_SetAddress(Feb_Control_rightAddress, Feb_Control_leftAddress);
if (Feb_Control_activated) { if (Feb_Control_activated) {
@ -1532,12 +1531,13 @@ int Feb_Control_SetMaster(enum MASTERINDEX ind) {
return 1; return 1;
} }
int Feb_Control_SetMasterEffects(int master) { int Feb_Control_SetMasterEffects(int master, int controlServer) {
int prevMaster = Feb_Control_master; int prevMaster = Feb_Control_master;
Feb_Control_master = master; Feb_Control_master = master;
// change in master for 9m // change in master for 9m
if (prevMaster != Feb_Control_master && !Feb_Control_normal) { if (controlServer && prevMaster != Feb_Control_master &&
!Feb_Control_normal) {
if (prevMaster) { if (prevMaster) {
Feb_Control_CloseSerialCommunication(); Feb_Control_CloseSerialCommunication();
} }

View File

@ -7,8 +7,7 @@
// setup // setup
void Feb_Control_activate(int activate); void Feb_Control_activate(int activate);
void Feb_Control_FebControl(); int Feb_Control_FebControl(int normal);
int Feb_Control_Init(int master, int normal);
int Feb_Control_OpenSerialCommunication(); int Feb_Control_OpenSerialCommunication();
void Feb_Control_CloseSerialCommunication(); void Feb_Control_CloseSerialCommunication();
int Feb_Control_CheckSetup(); int Feb_Control_CheckSetup();
@ -87,7 +86,7 @@ int Feb_Control_SetInterruptSubframe(int val);
int Feb_Control_GetInterruptSubframe(); int Feb_Control_GetInterruptSubframe();
int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right); int Feb_Control_SetTop(enum TOPINDEX ind, int left, int right);
int Feb_Control_SetMaster(enum MASTERINDEX ind); int Feb_Control_SetMaster(enum MASTERINDEX ind);
int Feb_Control_SetMasterEffects(int master); int Feb_Control_SetMasterEffects(int master, int controlServer);
int Feb_Control_SetQuad(int val); int Feb_Control_SetQuad(int val);
int Feb_Control_SetChipSignalsToTrimQuad(int enable); int Feb_Control_SetChipSignalsToTrimQuad(int enable);
int Feb_Control_SetReadNRows(int value); int Feb_Control_SetReadNRows(int value);

View File

@ -231,6 +231,23 @@ int getModuleId(int *ret, char *mess) {
return getModuleIdInFile(ret, mess, ID_FILE); return getModuleIdInFile(ret, mess, ID_FILE);
} }
int updateModuleId() {
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return FAIL;
}
#ifdef VIRTUAL
eiger_virtual_module_id = modid;
#else
if (Beb_SetModuleId(modid) == FAIL) {
initError = FAIL;
strcpy(initErrorMessage, ("Could not get module id from the file"));
return FAIL;
}
#endif
return OK;
}
u_int64_t getDetectorMAC() { u_int64_t getDetectorMAC() {
char mac[255] = ""; char mac[255] = "";
u_int64_t res = 0; u_int64_t res = 0;
@ -310,21 +327,14 @@ u_int32_t getDetectorIP() {
void initControlServer() { void initControlServer() {
LOG(logINFOBLUE, ("Configuring Control server\n")); LOG(logINFOBLUE, ("Configuring Control server\n"));
if (!updateFlag && initError == OK) { if (!updateFlag && initError == OK) {
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE); if (updateModuleConfiguration() == FAIL) {
#ifdef VIRTUAL initCheckDone = 1;
eiger_virtual_module_id = modid;
#endif
if (initError == FAIL) {
return; return;
} }
if (updateModuleConfiguration() == FAIL)
return;
#ifndef VIRTUAL #ifndef VIRTUAL
sharedMemory_lockLocalLink(); sharedMemory_lockLocalLink();
Feb_Interface_FebInterface(); Feb_Interface_FebInterface();
Feb_Control_FebControl(); if (!Feb_Control_FebControl(normal)) {
// same addresses for top and bottom
if (!Feb_Control_Init(master, normal)) {
initError = FAIL; initError = FAIL;
sprintf(initErrorMessage, "Could not intitalize feb control\n"); sprintf(initErrorMessage, "Could not intitalize feb control\n");
LOG(logERROR, (initErrorMessage)); LOG(logERROR, (initErrorMessage));
@ -332,24 +342,11 @@ void initControlServer() {
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
return; return;
} }
// master of 9M, check high voltage serial communication to blackfin Feb_Control_SetMasterEffects(master, isControlServer);
if (master && !normal) {
if (!Feb_Control_OpenSerialCommunication()) {
initError = FAIL;
sprintf(
initErrorMessage,
"Could not intitalize feb control serial communication\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
sharedMemory_unlockLocalLink();
return;
}
}
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
LOG(logDEBUG1, ("Control server: FEB Initialization done\n")); LOG(logDEBUG1, ("Control server: FEB Initialization done\n"));
Beb_SetTopVariable(top); Beb_SetTopVariable(top);
Beb_Beb(); Beb_Beb();
Beb_SetModuleId(modid);
LOG(logDEBUG1, ("Control server: BEB Initialization done\n")); LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
#endif #endif
// also reads config file and deactivates // also reads config file and deactivates
@ -359,33 +356,55 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
// wait a few s (control server is setting top/master from config file) if (!updateFlag && initError == OK) {
// wait a few s (control server is setting top/master from config file/
// command line)
usleep(WAIT_STOP_SERVER_START); usleep(WAIT_STOP_SERVER_START);
LOG(logINFOBLUE, ("Configuring Stop server\n")); LOG(logINFOBLUE, ("Configuring Stop server\n"));
if (updateModuleConfiguration() == FAIL) if (updateModuleConfiguration() == FAIL) {
initCheckDone = 1;
return; return;
}
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
// get top/master in virtual // force top or master if in config file
if (readConfigFile() == FAIL) { if (readConfigFile() == FAIL) {
initCheckDone = 1;
return;
}
// force top or master if in command line
if (checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return; return;
} }
#else #else
// control server read config file and already set up master/top // control server read config file and already set up master/top
sharedMemory_lockLocalLink(); sharedMemory_lockLocalLink();
Feb_Interface_FebInterface(); Feb_Interface_FebInterface();
Feb_Control_FebControl(); if (!Feb_Control_FebControl(normal)) {
// same addresses for top and bottom initError = FAIL;
Feb_Control_Init(master, normal); sprintf(initErrorMessage, "Could not intitalize feb control\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
sharedMemory_unlockLocalLink();
return;
}
Feb_Control_SetMasterEffects(master, isControlServer);
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
LOG(logDEBUG1, ("Stop server: FEB Initialization done\n")); LOG(logDEBUG1, ("Stop server: FEB Initialization done\n"));
Beb_SetTopVariable(top);
Beb_Beb();
LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
#endif #endif
// client first connect (from shm) will activate // client first connect (from shm) will activate
if (setActivate(0) == FAIL) { if (setActivate(0) == FAIL) {
LOG(logERROR, ("Could not deactivate in stop server\n")); initError = FAIL;
strcpy(initErrorMessage, "Could not deactivate\n");
LOG(logERROR, (initErrorMessage));
} }
} }
initCheckDone = 1;
}
void checkVirtual9MFlag() { void checkVirtual9MFlag() {
LOG(logINFORED, ("updating virtual\n")); LOG(logINFORED, ("updating virtual\n"));
@ -495,52 +514,28 @@ int readConfigFile() {
// top command // top command
if (!strncmp(line, "top", strlen("top"))) { if (!strncmp(line, "top", strlen("top"))) {
int t = -1;
// cannot scan values // cannot scan values
if (sscanf(line, "%s %d", command, &top) != 2) { if (sscanf(line, "%s %d", command, &t) != 2) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not scan top commands from on-board server " "Could not scan top commands from on-board server "
"config file. Line:[%s].\n", "config file. Line:[%s].\n",
line); line);
break; break;
} }
#ifndef VIRTUAL if (t != 0 && t != 1) {
enum TOPINDEX ind = (top == 1 ? OW_TOP : OW_BOTTOM);
if (!Beb_SetTop(ind)) {
sprintf(
initErrorMessage,
"Could not overwrite top to %d in Beb from on-board server "
"config file. Line:[%s].\n",
top, line);
break;
}
sharedMemory_lockLocalLink();
if (!Feb_Control_SetTop(ind, 1, 1)) {
sprintf(
initErrorMessage,
"Could not overwrite top to %d in Feb from on-board server "
"config file. Line:[%s].\n",
top, line);
sharedMemory_unlockLocalLink();
break;
}
sharedMemory_unlockLocalLink();
// validate change
int actual_top = -1, temp = -1, temp2 = -1;
if (Beb_GetModuleConfiguration(&temp, &actual_top, &temp2) ==
FAIL) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not get module configuration. Failed to load " "Invalid top argument from on-board server "
"config file in server. Line:[%s].\n", "config file. Line:[%s].\n",
line); line);
break; break;
} }
if (actual_top != top) { if (setTop(t == 1 ? OW_TOP : OW_BOTTOM) == FAIL) {
sprintf(initErrorMessage, "Could not set top to %d. Read %d\n", sprintf(initErrorMessage,
top, actual_top); "Could not set top from config file. Line:[%s].\n",
line);
break; break;
} }
Beb_SetTopVariable(top);
#endif
} }
// master command // master command
@ -561,7 +556,7 @@ int readConfigFile() {
line); line);
break; break;
} }
if (setMaster(m) == FAIL) { if (setMaster(m == 1 ? OW_MASTER : OW_SLAVE) == FAIL) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not set master from config file. Line:[%s].\n", "Could not set master from config file. Line:[%s].\n",
line); line);
@ -603,59 +598,21 @@ void resetToHardwareSettings() {
// top not set in config file // top not set in config file
if (top == -1) { if (top == -1) {
LOG(logINFO, ("Resetting Top to hardware settings\n")); LOG(logINFO, ("Resetting Top to hardware settings\n"));
if (!Beb_SetTop(TOP_HARDWARE)) { if (setTop(TOP_HARDWARE) == FAIL) {
initError = FAIL; initError = FAIL;
strcpy(initErrorMessage, strcpy(initErrorMessage,
"Could not reset Top flag to Beb hardware settings.\n"); "Could not reset Top flag to hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage)); LOG(logERROR, ("%s\n\n", initErrorMessage));
return; return;
} }
sharedMemory_lockLocalLink();
if (!Feb_Control_SetTop(TOP_HARDWARE, 1, 1)) {
initError = FAIL;
strcpy(initErrorMessage,
"Could not reset Top flag to Feb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
sharedMemory_unlockLocalLink();
return;
}
sharedMemory_unlockLocalLink();
int temp = -1, temp2 = -1;
if (Beb_GetModuleConfiguration(&temp, &top, &temp2) == FAIL) {
initError = FAIL;
strcpy(initErrorMessage, "Could not get module configuration after "
"resetting top to hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
return;
}
Beb_SetTopVariable(top);
} }
// master not set in config file // master not set in config file
if (master == -1) { if (master == -1) {
LOG(logINFO, ("Resetting Master to hardware settings\n")); LOG(logINFO, ("Resetting Master to hardware settings\n"));
if (!Beb_SetMaster(MASTER_HARDWARE)) { if (setMaster(MASTER_HARDWARE) == FAIL) {
initError = FAIL; initError = FAIL;
strcpy(initErrorMessage, strcpy(initErrorMessage,
"Could not reset Master flag to Beb hardware settings.\n"); "Could not reset Master flag to hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
return;
}
sharedMemory_lockLocalLink();
if (!Feb_Control_SetMaster(MASTER_HARDWARE)) {
initError = FAIL;
strcpy(initErrorMessage,
"Could not reset Master flag to Feb hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage));
sharedMemory_unlockLocalLink();
return;
}
sharedMemory_unlockLocalLink();
int temp = -1, temp2 = -1;
if (Beb_GetModuleConfiguration(&temp, &top, &temp2) == FAIL) {
initError = FAIL;
strcpy(initErrorMessage,
"Could not get module configuration after "
"resetting master to hardware settings.\n");
LOG(logERROR, ("%s\n\n", initErrorMessage)); LOG(logERROR, ("%s\n\n", initErrorMessage));
return; return;
} }
@ -663,7 +620,35 @@ void resetToHardwareSettings() {
#endif #endif
} }
int checkCommandLineConfiguration() {} int checkCommandLineConfiguration() {
int masterCommandLine = -1;
int topCommandLine = -1;
if (masterCommandLine != -1) {
LOG(logINFO, ("Setting %s from Command Line\n",
(masterCommandLine == 1 ? "Master" : "Slave")));
if (setMaster(masterCommandLine == 1 ? OW_MASTER : OW_SLAVE) == FAIL) {
initError = FAIL;
sprintf(initErrorMessage, "Could not set %s from command line.\n",
(masterCommandLine == 1 ? "Master" : "Slave"));
LOG(logERROR, (initErrorMessage));
return FAIL;
}
}
if (topCommandLine != -1) {
LOG(logINFO, ("Setting %s from Command Line\n",
(topCommandLine == 1 ? "Top" : "Bottom")));
if (setTop(topCommandLine == 1 ? OW_TOP : OW_BOTTOM) == FAIL) {
initError = FAIL;
sprintf(initErrorMessage, "Could not set %s from command line.\n",
(topCommandLine == 1 ? "Top" : "Bottom"));
LOG(logERROR, (initErrorMessage));
return FAIL;
}
}
return OK;
}
/* set up detector */ /* set up detector */
@ -698,15 +683,29 @@ void allocateDetectorStructureMemory() {
} }
void setupDetector() { void setupDetector() {
allocateDetectorStructureMemory(); allocateDetectorStructureMemory();
// force top or master if in config file
if (readConfigFile() == FAIL)
return;
// force top or master if in command line
if (checkCommandLineConfiguration() == FAIL)
return;
LOG(logINFOBLUE,
("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"),
(master ? "MASTER" : "SLAVE"), (normal ? "NORMAL" : "SPECIAL")));
if (updateModuleId() == FAIL)
return;
LOG(logINFOBLUE, ("Setting Default Parameters\n"));
resetToDefaultDacs(0); resetToDefaultDacs(0);
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStatus(IDLE); sharedMemory_setStatus(IDLE);
setupUDPCommParameters(); setupUDPCommParameters();
#endif #endif
LOG(logINFOBLUE, ("Setting Default Parameters\n"));
// setting default measurement parameters // setting default measurement parameters
setNumFrames(DEFAULT_NUM_FRAMES); setNumFrames(DEFAULT_NUM_FRAMES);
setExpTime(DEFAULT_EXPTIME); setExpTime(DEFAULT_EXPTIME);
@ -746,14 +745,6 @@ void setupDetector() {
} }
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
#endif #endif
// force top or master if in config file
if (readConfigFile() == FAIL) {
return;
}
LOG(logINFOBLUE,
("Module: %s %s %s\n", (top ? "TOP" : "BOTTOM"),
(master ? "MASTER" : "SLAVE"), (normal ? "NORMAL" : "SPECIAL")));
if (setNumberofDestinations(numUdpDestinations) == FAIL) { if (setNumberofDestinations(numUdpDestinations) == FAIL) {
initError = FAIL; initError = FAIL;
strcpy(initErrorMessage, "Could not set number of udp destinations\n"); strcpy(initErrorMessage, "Could not set number of udp destinations\n");
@ -1477,30 +1468,41 @@ int setHighVoltage(int val) {
/* parameters - timing, extsig */ /* parameters - timing, extsig */
int setMaster(int m) { int setMaster(enum MASTERINDEX m) {
LOG(logINFOBLUE, ("Setting up as %s\n", (m == 1 ? "Master" : "Slave"))); char *master_names[] = {MASTER_NAMES};
LOG(logINFOBLUE, ("Setting up as %s\n", master_names[m]));
#ifdef VIRTUAL #ifdef VIRTUAL
master = m; switch (m) {
case OW_MASTER:
master = 1;
break;
case OW_SLAVE:
master = 0;
break;
default:
// hardware settings (do nothing)
break;
}
#else #else
if(!Beb_SetMaster((m == 1 ? OW_MASTER : OW_SLAVE)) { if (!Beb_SetMaster(m)) {
return FAIL; return FAIL;
} }
sharedMemory_lockLocalLink(); sharedMemory_lockLocalLink();
if (!Feb_Control_SetMaster((m == 1 ? OW_MASTER : OW_SLAVE))) { if (!Feb_Control_SetMaster(m)) {
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
// set master variable // get and update master variable
if (isMaster(master) == FAIL) { if (isMaster(master) == FAIL) {
return FAIL; return FAIL;
} }
// feb variable and hv comms (9m) // feb variable and hv comms (9m)
sharedMemory_lockLocalLink(); sharedMemory_lockLocalLink();
if (Feb_Control_SetMasterEffects(master) == FAIL) { if (Feb_Control_SetMasterEffects(master, isControlServer) == FAIL) {
return FAIL; return FAIL;
} }
sharedMemory_unlockLocalLink(); sharedMemory_unlockLocalLink();
@ -1523,6 +1525,58 @@ int isMaster(int *retval) {
return OK; return OK;
} }
int setTop(int t) {
char *top_names[] = {TOP_NAMES};
LOG(logINFOBLUE, ("Setting up as %s\n", top_names[t]));
#ifdef VIRTUAL
switch (t) {
case OW_TOP:
top = 1;
break;
case OW_BOTTOM:
top = 0;
break;
default:
// hardware settings (do nothing)
break;
}
#else
if (!Beb_SetTop(t)) {
return FAIL;
}
sharedMemory_lockLocalLink();
if (!Feb_Control_SetTop(t)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
// get and update top variable
if (isTop(top) == FAIL) {
return FAIL;
}
Beb_SetTopVariable(top);
#endif
return OK;
}
int isTop(int *retval) {
int m = -1, t = -1, n = -1;
if (getModuleConfiguration(&m, &t, &n) == FAIL) {
return FAIL;
}
if (t != top) {
LOG(logERROR,
("top value retrieved %d and local value %d do not match\n", top,
t));
return FAIL;
}
*retval = t;
return OK;
}
void setTiming(enum timingMode arg) { void setTiming(enum timingMode arg) {
int ret = 0; int ret = 0;
switch (arg) { switch (arg) {

View File

@ -35,6 +35,9 @@ extern int isControlServer;
extern void getMacAddressinString(char *cmac, int size, uint64_t mac); extern void getMacAddressinString(char *cmac, int size, uint64_t mac);
extern void getIpAddressinString(char *cip, uint32_t ip); extern void getIpAddressinString(char *cip, uint32_t ip);
// Variables that will be exported
int masterCommandLine = -1;
int initError = OK; int initError = OK;
int initCheckDone = 0; int initCheckDone = 0;
char initErrorMessage[MAX_STR_LENGTH]; char initErrorMessage[MAX_STR_LENGTH];
@ -297,6 +300,18 @@ void setModuleId(int modid) {
bus_r(MOD_ID_REG) | ((modid << MOD_ID_OFST) & MOD_ID_MSK)); bus_r(MOD_ID_REG) | ((modid << MOD_ID_OFST) & MOD_ID_MSK));
} }
int updateModuleId() {
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return FAIL;
}
#ifdef VIRTUAL
virtual_moduleid = modid;
#endif
setModuleId(modid);
return OK;
}
u_int64_t getDetectorMAC() { u_int64_t getDetectorMAC() {
#ifdef VIRTUAL #ifdef VIRTUAL
return 0; return 0;
@ -360,17 +375,27 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
if (mapCSP0() == FAIL) { if (mapCSP0() == FAIL) {
LOG(logERROR, initError = FAIL;
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); strcpy(initErrorMessage,
exit(EXIT_FAILURE); "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
} }
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
if (checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
#endif #endif
} }
initCheckDone = 1;
}
/* set up detector */ /* set up detector */
@ -477,20 +502,18 @@ void setupDetector() {
setPhase(READOUT_C1, DEFAULT_CLK1_PHASE_DEG, 1); setPhase(READOUT_C1, DEFAULT_CLK1_PHASE_DEG, 1);
setDBITPipeline(DEFAULT_DBIT_PIPELINE); setDBITPipeline(DEFAULT_DBIT_PIPELINE);
// master for virtual
if (checkCommandLineConfiguration() == FAIL)
return;
// also sets default dac and on chip dac values // also sets default dac and on chip dac values
if (readConfigFile() == FAIL) { if (readConfigFile() == FAIL) {
return; return;
} }
// set module id in register if (updateModuleId() == FAIL) {
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
#ifdef VIRTUAL
virtual_moduleid = modid;
#endif
if (initError == FAIL) {
return; return;
} }
setModuleId(modid);
setBurstMode(DEFAULT_BURST_MODE); setBurstMode(DEFAULT_BURST_MODE);
setFilterResistor(DEFAULT_FILTER_RESISTOR); setFilterResistor(DEFAULT_FILTER_RESISTOR);
@ -930,6 +953,21 @@ int readConfigFile() {
return initError; return initError;
} }
int checkCommandLineConfiguration() {
if (masterCommandLine != -1) {
#ifdef VIRTUAL
master = masterCommandLine;
#else
initError = FAIL;
strcpy(initErrorMessage,
"Cannot set Master from command line for this detector. "
"Should have been caught before!\n");
return FAIL;
#endif
}
return OK;
}
/* firmware functions (resets) */ /* firmware functions (resets) */
void cleanFifos() { void cleanFifos() {

View File

@ -29,6 +29,7 @@ extern int ignoreConfigFileFlag;
// Variables that will be exported // Variables that will be exported
int phaseShift = DEFAULT_PHASE_SHIFT; int phaseShift = DEFAULT_PHASE_SHIFT;
int masterCommandLine = -1;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
extern int isControlServer; extern int isControlServer;
@ -360,16 +361,28 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
if (mapCSP0() == FAIL) { if (mapCSP0() == FAIL) {
LOG(logERROR, initError = FAIL;
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); strcpy(initErrorMessage,
exit(EXIT_FAILURE); "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
} }
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
#endif #endif
// to get master from file // to get master from file
readConfigFile(); if (readConfigFile() == FAIL ||
checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
}
initCheckDone = 1;
} }
/* set up detector */ /* set up detector */
@ -422,6 +435,13 @@ void setupDetector() {
setROI(rois); // set adcsyncreg, daqreg, chipofinterestreg, cleanfifos, setROI(rois); // set adcsyncreg, daqreg, chipofinterestreg, cleanfifos,
setGbitReadout(); setGbitReadout();
// no config file or not first time server
if (readConfigFile() == FAIL)
return;
if (checkCommandLineConfiguration() == FAIL)
return;
// master, slave (25um) // master, slave (25um)
setMasterSlaveConfiguration(); setMasterSlaveConfiguration();
@ -626,6 +646,10 @@ void setGbitReadout() {
int readConfigFile() { int readConfigFile() {
if (initError == FAIL) {
return initError;
}
if (ignoreConfigFileFlag) { if (ignoreConfigFileFlag) {
return OK; return OK;
} }
@ -653,7 +677,6 @@ int readConfigFile() {
memset(key, 0, keySize); memset(key, 0, keySize);
char value[keySize]; char value[keySize];
memset(value, 0, keySize); memset(value, 0, keySize);
int scan = OK;
// keep reading a line // keep reading a line
while (fgets(line, lineSize, fd)) { while (fgets(line, lineSize, fd)) {
@ -673,19 +696,22 @@ int readConfigFile() {
master = 0; master = 0;
LOG(logINFOBLUE, ("\tSlave or No Master\n")); LOG(logINFOBLUE, ("\tSlave or No Master\n"));
} else { } else {
LOG(logERROR, initError = FAIL;
("\tCould not scan masterflags %s value from config file\n", sprintf(
value)); initErrorMessage,
scan = FAIL; "Could not scan masterflags %s value from config file\n",
break; value);
LOG(logERROR, (initErrorMessage))
fclose(fd);
return FAIL;
} }
// not first server since detector power on // not first server since detector power on
if (!detectorFirstServer) { if (!detectorFirstServer) {
LOG(logINFOBLUE, ("\tServer has been started up before. " LOG(logWARNING, ("\tServer has been started up before. "
"Ignoring rest of config file\n")); "Ignoring rest of config file\n"));
fclose(fd); fclose(fd);
return FAIL; return OK;
} }
} }
@ -694,11 +720,14 @@ int readConfigFile() {
// convert value to int // convert value to int
int ival = 0; int ival = 0;
if (sscanf(value, "%d", &ival) <= 0) { if (sscanf(value, "%d", &ival) <= 0) {
LOG(logERROR, ("\tCould not scan parameter %s value %s from " initError = FAIL;
sprintf(initErrorMessage,
"Could not scan parameter %s value %s from "
"config file\n", "config file\n",
key, value)); key, value);
scan = FAIL; LOG(logERROR, (initErrorMessage))
break; fclose(fd);
return FAIL;
} }
// set value // set value
if (!strcasecmp(key, "masterdefaultdelay")) if (!strcasecmp(key, "masterdefaultdelay"))
@ -716,16 +745,16 @@ int readConfigFile() {
else if (!strcasecmp(key, "startacqdelay")) else if (!strcasecmp(key, "startacqdelay"))
startacqdelay = ival; startacqdelay = ival;
else { else {
LOG(logERROR, initError = FAIL;
("\tCould not scan parameter %s from config file\n", key)); sprintf(initErrorMessage,
scan = FAIL; "Could not scan parameter %s from config file\n", key);
break; LOG(logERROR, (initErrorMessage))
fclose(fd);
return FAIL;
} }
} }
} }
fclose(fd); fclose(fd);
if (scan == FAIL)
exit(EXIT_FAILURE);
LOG(logINFOBLUE, LOG(logINFOBLUE,
("\tmasterdefaultdelay:%d\n" ("\tmasterdefaultdelay:%d\n"
@ -740,13 +769,24 @@ int readConfigFile() {
return OK; return OK;
} }
int checkCommandLineConfiguration() {
if (masterCommandLine != -1) {
#ifdef VIRTUAL
master = masterCommandLine;
#else
initError = FAIL;
strcpy(initErrorMessage,
"Cannot set Master from command line for this detector. "
"Should have been caught before!\n");
return FAIL;
#endif
}
return OK;
}
void setMasterSlaveConfiguration() { void setMasterSlaveConfiguration() {
LOG(logINFO, ("Reading Master Slave Configuration\n")); LOG(logINFO, ("Reading Master Slave Configuration\n"));
// no config file or not first time server
if (readConfigFile() == FAIL)
return;
// master configuration // master configuration
if (master) { if (master) {
// master default delay set, so reset delay // master default delay set, so reset delay

View File

@ -393,12 +393,16 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
if (mapCSP0() == FAIL) { if (mapCSP0() == FAIL) {
LOG(logERROR, initError = FAIL;
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); strcpy(initErrorMessage,
exit(EXIT_FAILURE); "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
} }
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
@ -407,6 +411,8 @@ void initStopServer() {
setTemperatureEvent(0); setTemperatureEvent(0);
#endif #endif
} }
initCheckDone = 1;
}
/* set up detector */ /* set up detector */

View File

@ -436,17 +436,23 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
if (mapCSP0() == FAIL) { if (mapCSP0() == FAIL) {
LOG(logERROR, initError = FAIL;
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); strcpy(initErrorMessage,
exit(EXIT_FAILURE); "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
} }
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
#endif #endif
} }
initCheckDone = 1;
}
/* set up detector */ /* set up detector */

View File

@ -35,6 +35,9 @@ extern int isControlServer;
extern void getMacAddressinString(char *cmac, int size, uint64_t mac); extern void getMacAddressinString(char *cmac, int size, uint64_t mac);
extern void getIpAddressinString(char *cip, uint32_t ip); extern void getIpAddressinString(char *cip, uint32_t ip);
// Variables that will be exported
int masterCommandLine = -1;
int initError = OK; int initError = OK;
int initCheckDone = 0; int initCheckDone = 0;
char initErrorMessage[MAX_STR_LENGTH]; char initErrorMessage[MAX_STR_LENGTH];
@ -289,6 +292,18 @@ void setModuleId(int modid) {
bus_r(MOD_ID_REG) | ((modid << MOD_ID_OFST) & MOD_ID_MSK)); bus_r(MOD_ID_REG) | ((modid << MOD_ID_OFST) & MOD_ID_MSK));
} }
int updateModuleId() {
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return FAIL;
}
#ifdef VIRTUAL
virtual_moduleid = modid;
#endif
setModuleId(modid);
return OK;
}
u_int64_t getDetectorMAC() { u_int64_t getDetectorMAC() {
#ifdef VIRTUAL #ifdef VIRTUAL
return 0; return 0;
@ -352,17 +367,27 @@ void initControlServer() {
} }
void initStopServer() { void initStopServer() {
if (!updateFlag && initError == OK) {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
LOG(logINFOBLUE, ("Configuring Stop server\n"));
if (mapCSP0() == FAIL) { if (mapCSP0() == FAIL) {
LOG(logERROR, initError = FAIL;
("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); strcpy(initErrorMessage,
exit(EXIT_FAILURE); "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
} }
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStop(0); sharedMemory_setStop(0);
if (checkCommandLineConfiguration() == FAIL) {
initCheckDone = 1;
return;
}
#endif #endif
} }
initCheckDone = 1;
}
/* set up detector */ /* set up detector */
@ -407,6 +432,12 @@ void setupDetector() {
allocateDetectorStructureMemory(); allocateDetectorStructureMemory();
if (checkCommandLineConfiguration() == FAIL)
return;
if (updateModuleId() == FAIL)
return;
clkDivider[READOUT_C0] = DEFAULT_READOUT_C0; clkDivider[READOUT_C0] = DEFAULT_READOUT_C0;
clkDivider[READOUT_C1] = DEFAULT_READOUT_C1; clkDivider[READOUT_C1] = DEFAULT_READOUT_C1;
clkDivider[SYSTEM_C0] = DEFAULT_SYSTEM_C0; clkDivider[SYSTEM_C0] = DEFAULT_SYSTEM_C0;
@ -447,16 +478,6 @@ void setupDetector() {
setASICDefaults(); setASICDefaults();
setADIFDefaults(); setADIFDefaults();
// set module id in register
int modid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
#ifdef VIRTUAL
virtual_moduleid = modid;
#endif
if (initError == FAIL) {
return;
}
setModuleId(modid);
// set trigger flow for m3 (for all timing modes) // set trigger flow for m3 (for all timing modes)
bus_w(FLOW_TRIGGER_REG, bus_r(FLOW_TRIGGER_REG) | FLOW_TRIGGER_MSK); bus_w(FLOW_TRIGGER_REG, bus_r(FLOW_TRIGGER_REG) | FLOW_TRIGGER_MSK);
@ -480,10 +501,6 @@ void setupDetector() {
setInitialExtSignals(); setInitialExtSignals();
// 10G UDP // 10G UDP
enableTenGigabitEthernet(1); enableTenGigabitEthernet(1);
getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return;
}
setSettings(DEFAULT_SETTINGS); setSettings(DEFAULT_SETTINGS);
// check module type attached if not in debug mode // check module type attached if not in debug mode
@ -700,6 +717,22 @@ void setADIFDefaults() {
ADIF_ADDTNL_OFST_MSK))); ADIF_ADDTNL_OFST_MSK)));
} }
int checkCommandLineConfiguration() {
if (masterCommandLine != -1) {
#ifdef VIRTUAL
bus_w(SYSTEM_STATUS_REG,
bus_r(SYSTEM_STATUS_REG) & ~SYSTEM_STATUS_SLV_BRD_DTCT_MSK);
#else
initError = FAIL;
strcpy(initErrorMessage,
"Cannot set Master from command line for this detector. "
"Should have been caught before!\n");
return FAIL;
#endif
}
return OK;
}
/* firmware functions (resets) */ /* firmware functions (resets) */
void cleanFifos() { void cleanFifos() {

View File

@ -97,6 +97,9 @@ u_int32_t getDetectorNumber();
#if defined(GOTTHARD2D) || defined(EIGERD) || defined(MYTHEN3D) #if defined(GOTTHARD2D) || defined(EIGERD) || defined(MYTHEN3D)
int getModuleId(int *ret, char *mess); int getModuleId(int *ret, char *mess);
#endif #endif
#if defined(EIGERD) || defined(MYTHEN3D) || defined(GOTTHARD2D)
int updateModuleId();
#endif
#if defined(GOTTHARD2D) || defined(MYTHEN3D) #if defined(GOTTHARD2D) || defined(MYTHEN3D)
void setModuleId(int modid); void setModuleId(int modid);
#endif #endif
@ -141,6 +144,10 @@ void setADIFDefaults();
#if defined(GOTTHARD2D) || defined(EIGERD) || defined(JUNGFRAUD) #if defined(GOTTHARD2D) || defined(EIGERD) || defined(JUNGFRAUD)
int readConfigFile(); int readConfigFile();
#endif #endif
#if defined(GOTTHARDD) || defined(GOTTHARD2D) || defined(EIGERD) || \
defined(MYTHEN3D)
int checkCommandLineConfiguration();
#endif
#ifdef EIGERD #ifdef EIGERD
void resetToHardwareSettings(); void resetToHardwareSettings();
#endif #endif
@ -367,7 +374,9 @@ int setHighVoltage(int val);
// parameters - timing, extsig // parameters - timing, extsig
#ifdef EIGERD #ifdef EIGERD
int setMaster(int m); int setMaster(enum MASTERINDEX m);
int setTop(int t);
int isTop(int *retval);
#endif #endif
#if defined(MYTHEN3D) || defined(EIGERD) || defined(GOTTHARDD) || \ #if defined(MYTHEN3D) || defined(EIGERD) || defined(GOTTHARDD) || \
defined(GOTTHARD2D) defined(GOTTHARD2D)

View File

@ -199,7 +199,11 @@ int main(int argc, char *argv[]) {
break; break;
case 'm': case 'm':
#if defined(GOTTHARDD) || defined(GOTTHARD2D) || defined(EIGERD) || \ #if (defined(MYTHEN3D) || defined(GOTTHARD2D)) && !defined(VIRTUAL)
LOG(logERROR, ("Cannot set master via the detector server for this "
"detector\n"));
exit(EXIT_FAILURE);
#elif defined(GOTTHARDD) || defined(GOTTHARD2D) || defined(EIGERD) || \
defined(MYTHEN3D) defined(MYTHEN3D)
if (sscanf(optarg, "%d", &masterCommandLine) != 1) { if (sscanf(optarg, "%d", &masterCommandLine) != 1) {
LOG(logERROR, ("Cannot scan master argument\n%s", helpMessage)); LOG(logERROR, ("Cannot scan master argument\n%s", helpMessage));

View File

@ -3979,7 +3979,6 @@ int check_version(int file_des) {
return printSocketReadError(); return printSocketReadError();
// check software- firmware compatibility and basic tests // check software- firmware compatibility and basic tests
if (isControlServer) {
LOG(logDEBUG1, ("Checking software-firmware compatibility and basic " LOG(logDEBUG1, ("Checking software-firmware compatibility and basic "
"test result\n")); "test result\n"));
@ -3988,12 +3987,11 @@ int check_version(int file_des) {
usleep(3 * 1000 * 1000); usleep(3 * 1000 * 1000);
if (!isInitCheckDone()) { if (!isInitCheckDone()) {
ret = FAIL; ret = FAIL;
strcpy(mess, "Firmware Software Compatibility Check (Server " strcpy(mess, "Server Initialization still not done done in server. Unexpected.\n");
"Initialization) "
"still not done done in server. Unexpected.\n");
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} }
} }
// check firmware check result // check firmware check result
if (ret == OK) { if (ret == OK) {
char *firmware_message = NULL; char *firmware_message = NULL;
@ -4003,7 +4001,6 @@ int check_version(int file_des) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} }
} }
}
if (ret == OK) { if (ret == OK) {
LOG(logDEBUG1, LOG(logDEBUG1,
@ -8228,7 +8225,7 @@ int set_master(int file_des) {
sprintf(mess, "Could not set master. Invalid argument %d.\n", arg); sprintf(mess, "Could not set master. Invalid argument %d.\n", arg);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else { } else {
ret = setMaster(arg); ret = setMaster(arg == 1 ? OW_MASTER : OW_SLAVE);
if (ret == FAIL) { if (ret == FAIL) {
strcpy(mess, "Could not set master\n"); strcpy(mess, "Could not set master\n");
LOG(logERROR, (mess)); LOG(logERROR, (mess));