moduleid for eiger m3 and g2, but set only for g2

This commit is contained in:
maliakal_d 2021-09-01 17:06:34 +02:00
parent 25d03f949e
commit a51deda2a4
22 changed files with 180 additions and 95 deletions

View File

@ -73,7 +73,8 @@ vetoalg
vetostream
serialnumber (put)
dbitpipeline
readnlines->partialread
readnlines->readnrows
serialnumber->moduleid
setting number of udp interfaces from 1 to 2, didnt get image in gui

View File

@ -1022,18 +1022,19 @@ int Beb_GetBebFPGATemp() {
return temperature;
}
void Beb_SetDetectorNumber(uint32_t detid) {
int Beb_SetModuleId(uint32_t detid) {
if (!Beb_activated)
return;
return OK;
uint32_t swapid = Beb_swap_uint16(detid);
// LOG(logINFO, "detector id %d swapped %d\n", detid, swapid));
u_int32_t *csp0base = 0;
int fd = Beb_open(&csp0base, XPAR_PLB_GPIO_TEST_BASEADDR);
if (fd < 0) {
LOG(logERROR, ("Set Detector ID FAIL\n"));
return;
LOG(logERROR, ("Set module id FAIL\n"));
return FAIL;
} else {
// left
uint32_t value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
value &= UDP_HEADER_X_MSK; // to keep previous x value
Beb_Write32(csp0base, UDP_HEADER_A_LEFT_OFST,
@ -1042,8 +1043,11 @@ void Beb_SetDetectorNumber(uint32_t detid) {
value = Beb_Read32(csp0base, UDP_HEADER_A_LEFT_OFST);
if ((value & UDP_HEADER_ID_MSK) !=
((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)) {
LOG(logERROR, ("Set Detector ID FAIL\n"));
LOG(logERROR, ("Set module id FAIL\n"));
Beb_close(fd, csp0base);
return FAIL;
}
// right
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
value &= UDP_HEADER_X_MSK; // to keep previous x value
Beb_Write32(csp0base, UDP_HEADER_A_RIGHT_OFST,
@ -1052,11 +1056,13 @@ void Beb_SetDetectorNumber(uint32_t detid) {
value = Beb_Read32(csp0base, UDP_HEADER_A_RIGHT_OFST);
if ((value & UDP_HEADER_ID_MSK) !=
((swapid << UDP_HEADER_ID_OFST) & UDP_HEADER_ID_MSK)) {
LOG(logERROR, ("Set Detector ID FAIL\n"));
LOG(logERROR, ("Set module id FAIL\n"));
Beb_close(fd, csp0base);
return FAIL;
}
Beb_close(fd, csp0base);
}
LOG(logINFO, ("Detector id %d set in UDP Header\n\n", detid));
LOG(logINFO, ("Module id %d set in UDP Header\n\n", detid));
}
int Beb_SetQuad(int value) {

View File

@ -42,7 +42,7 @@ int Beb_StopAcquisition();
int Beb_RequestNImages(int ten_gig, unsigned int nimages,
int test_just_send_out_packets_no_wait);
int Beb_GetBebFPGATemp();
void Beb_SetDetectorNumber(uint32_t detid);
int Beb_SetModuleId(uint32_t detid);
int Beb_SetQuad(int value);
int Beb_GetQuad();
int *Beb_GetDetectorPosition();

View File

@ -100,3 +100,4 @@ install(TARGETS eigerDetectorServerSlaveBottom_virtual
configure_file(config_eiger.txt ${CMAKE_BINARY_DIR}/bin/config_eiger.txt COPYONLY)
configure_file(detid_eiger.txt ${CMAKE_BINARY_DIR}/bin/detid_eiger.txt COPYONLY)

View File

@ -34,6 +34,7 @@ $(PROGS): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
cp config_eiger.txt $(DESTDIR)
cp detid.txt $(DESTDIR)
hv9m_blackfin_server:9mhvserial_bf.c

View File

@ -46,9 +46,6 @@ unsigned int nimages_per_request = 1;
int top = 0;
int master = 0;
int normal = 0;
#ifndef VIRTUAL
uint32_t detid = 0;
#endif
int eiger_highvoltage = 0;
int eiger_theo_highvoltage = 0;
@ -222,25 +219,8 @@ u_int64_t getFirmwareAPIVersion() {
#endif
}
void readDetectorNumber() {
#ifndef VIRTUAL
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));
}
#endif
}
u_int32_t getDetectorNumber() {
#ifdef VIRTUAL
return 0;
#else
return detid;
#endif
int getModuleId(int *ret, char *mess) {
return getModuleIdInFile(ret, mess, ID_FILE);
}
u_int64_t getDetectorMAC() {
@ -322,7 +302,14 @@ u_int32_t getDetectorIP() {
void initControlServer() {
LOG(logINFOBLUE, ("Configuring Control server\n"));
if (!updateFlag && initError == OK) {
readDetectorNumber();
#ifndef VIRTUAL
int detid = getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
#else
getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
#endif
if (initError == FAIL) {
return;
}
getModuleConfiguration();
#ifndef VIRTUAL
sharedMemory_lockLocalLink();
@ -355,7 +342,7 @@ void initControlServer() {
LOG(logDEBUG1, ("Control server: FEB Initialization done\n"));
Beb_SetTopVariable(top);
Beb_Beb();
Beb_SetDetectorNumber(getDetectorNumber());
Beb_SetModuleId(detid);
LOG(logDEBUG1, ("Control server: BEB Initialization done\n"));
#endif
// also reads config file and deactivates

View File

@ -2,7 +2,11 @@
#include "sls/sls_detector_defs.h"
#define REQUIRED_FIRMWARE_VERSION (27)
#define IDFILECOMMAND "more /home/root/executables/detid.txt"
#ifdef VIRTUAL
#define ID_FILE "detid_eiger.txt"
#else
#define ID_FILE "detid.txt"
#endif
#define CONFIG_FILE ("config_eiger.txt")
#define WAIT_STOP_SERVER_START (1 * 1000 * 1000)

View File

@ -40,3 +40,4 @@ install(TARGETS gotthard2DetectorServer_virtual
)
configure_file(config_gotthard2.txt ${CMAKE_BINARY_DIR}/bin/config_gotthard2.txt COPYONLY)
configure_file(detid_gotthard2.txt ${CMAKE_BINARY_DIR}/bin/detid_gotthard2.txt COPYONLY)

View File

@ -33,6 +33,7 @@ $(PROGS): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
cp config_gotthard2.txt $(DESTDIR)
cp detid_gotthard2.txt $s(DESTDIR)
rm $(main_src)*.o
clean:

View File

@ -127,7 +127,6 @@
#define MOD_ID_OFST (0)
#define MOD_ID_MSK (0x0000FFFF << MOD_ID_OFST)
#define MOD_MAX_VAL (0xFFFF)
/* ASIC registers --------------------------------------------------*/

View File

@ -287,16 +287,19 @@ u_int32_t getDetectorNumber() {
return bus_r(MCB_SERIAL_NO_REG);
}
int getModuleId() { return ((bus_r(MOD_ID_REG) & MOD_ID_MSK) >> MOD_ID_OFST); }
int getModuleId(int *ret, char *mess) {
return getModuleIdInFile(ret, mess, ID_FILE);
}
void setModuleId(int arg) {
LOG(logINFOBLUE, ("Setting Module Id to 0x%x\n", arg));
void setModuleId(int *ret, char *mess, int arg) {
*ret = setModuleIdInFile(mess, arg, ID_FILE);
if (*ret == FAIL) {
return;
}
bus_w(MOD_ID_REG, bus_r(MOD_ID_REG) & ~MOD_ID_MSK);
bus_w(MOD_ID_REG, bus_r(MOD_ID_REG) | ((arg << MOD_ID_OFST) & MOD_ID_MSK));
}
int getMaxModuleId() { return MOD_MAX_VAL; }
u_int64_t getDetectorMAC() {
#ifdef VIRTUAL
return 0;
@ -419,7 +422,10 @@ void setupDetector() {
sharedMemory_setStatus(IDLE);
setupUDPCommParameters();
#endif
getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return;
}
// pll defines
ALTERA_PLL_C10_SetDefines(REG_OFFSET, BASE_READOUT_PLL, BASE_SYSTEM_PLL,
PLL_RESET_REG, PLL_RESET_READOUT_MSK,

View File

@ -3,6 +3,7 @@
#define REQRD_FRMWRE_VRSN (0x210527)
#define KERNEL_DATE_VRSN "Wed May 20 13:58:38 CEST 2020"
#define ID_FILE "detid_gotthard2.txt"
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)

View File

@ -41,4 +41,5 @@ install(TARGETS mythen3DetectorServer_virtual
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
configure_file(DefaultPattern_mythen3.txt ${CMAKE_BINARY_DIR}/bin/DefaultPattern_mythen3.txt COPYONLY)
configure_file(DefaultPattern_mythen3.txt ${CMAKE_BINARY_DIR}/bin/DefaultPattern_mythen3.txt COPYONLY)
configure_file(detid_mythen3.txt ${CMAKE_BINARY_DIR}/bin/detid_mythen3.txt COPYONLY)

View File

@ -34,6 +34,7 @@ $(PROGS): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LDLIBS)
mv $(PROGS) $(DESTDIR)
cp DefaultPattern_mythen3.txt $(DESTDIR)
cp detid_mythen3.txt $(DESTDIR)
rm $(main_src)*.o
clean:

View File

@ -274,28 +274,17 @@ u_int16_t getHardwareVersionNumber() {
MCB_SERIAL_NO_VRSN_OFST);
}
void readDetectorNumber() {
#ifndef VIRTUAL
if (initError == FAIL) {
return;
}
FILE *fd = fopen(ID_FILE, "r");
if (fd == NULL) {
sprintf(initErrorMessage, "No %s file found.\n", ID_FILE);
LOG(logERROR, ("%s\n\n", initErrorMessage));
initError = FAIL;
return;
}
char output[255];
fgets(output, sizeof(output), fd);
sscanf(output, "%u", &detID);
if (isControlServer) {
LOG(logINFOBLUE, ("Detector ID: %u\n", detID));
}
u_int32_t getDetectorNumber() {
#ifdef VIRTUAL
return 0;
#endif
return bus_r(MCB_SERIAL_NO_REG);
}
u_int32_t getDetectorNumber() { return detID; }
int getModuleId(int *ret, char *mess) {
return getModuleIdInFile(ret, mess, ID_FILE);
}
u_int64_t getDetectorMAC() {
#ifdef VIRTUAL
@ -481,7 +470,7 @@ void setupDetector() {
#ifdef VIRTUAL
enableTenGigabitEthernet(0);
#endif
readDetectorNumber();
getModuleIdInFile(&initError, initErrorMessage, ID_FILE);
if (initError == FAIL) {
return;
}

View File

@ -28,3 +28,6 @@ void validate(int *ret, char *mess, int arg, int retval, char *modename,
enum numberMode nummode);
void validate64(int *ret, char *mess, int64_t arg, int64_t retval,
char *modename, enum numberMode nummode);
int getModuleIdInFile(int *ret, char *mess, char *fileName);
int setModuleIdInFile(char *mess, int arg, char *fileName);

View File

@ -89,14 +89,14 @@ u_int16_t getHardwareSerialNumber();
int isHardwareVersion2();
int getChipVersion();
#endif
#if defined(EIGERD) || defined(MYTHEN3D)
void readDetectorNumber();
#endif
#ifndef EIGERD
u_int32_t getDetectorNumber();
#endif
#if defined(GOTTHARD2D) || defined(EIGERD) || defined(MYTHEN3D)
int getModuleId(int *ret, char *mess);
#endif
#ifdef GOTTHARD2D
int getModuleId();
void setModuleId(int arg);
int getMaxModuleId();
void setModuleId(int *ret, char *mess, int arg);
#endif
u_int64_t getDetectorMAC();
u_int32_t getDetectorIP();

View File

@ -7,9 +7,6 @@
#include <string.h>
#include <unistd.h> // readlink
extern int ret;
extern char mess[MAX_STR_LENGTH];
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
int outputMax, int inputValue, int *outputValue) {
LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",
@ -102,4 +99,82 @@ void validate64(int *ret, char *mess, int64_t arg, int64_t retval,
(long long unsigned int)retval);
LOG(logERROR, (mess));
}
}
}
int getModuleIdInFile(int *ret, char *mess, char *fileName) {
const int fileNameSize = 128;
char fname[fileNameSize];
if (getAbsPath(fname, fileNameSize, fileName) == FAIL) {
*ret = FAIL;
strcpy(mess, "Could not find detid file\n");
LOG(logERROR, ("%s\n\n", mess));
return -1;
}
// open id file
FILE *fd = fopen(fname, "r");
if (fd == NULL) {
*ret = FAIL;
strcpy(mess, "Could not find detid file\n");
LOG(logERROR, ("%s\n\n", mess));
return -1;
}
LOG(logDEBUG1, ("Reading det id file %s\n", fileName));
// read line
const size_t len = 256;
char line[len];
memset(line, 0, len);
if (NULL == fgets(line, len, fd)) {
*ret = FAIL;
strcpy(mess, "Could not find detid file\n");
LOG(logERROR, ("%s\n\n", mess));
return -1;
}
// read id
int retval = 0;
if (sscanf(line, "%x", &retval) != 1) {
*ret = FAIL;
sprintf(mess,
"Could not scan det id from on-board server "
"id file. Line:[%s].\n",
line);
LOG(logERROR, ("%s\n\n", mess));
return -1;
}
LOG(logINFOBLUE, ("Module Id: 0x%x (File)\n", retval));
return retval;
}
int setModuleIdInFile(char *mess, int arg, char *fileName) {
LOG(logINFOBLUE, ("Setting Module Id: 0x%x (File)\n", arg));
const int fileNameSize = 128;
char fname[fileNameSize];
if (getAbsPath(fname, fileNameSize, fileName) == FAIL) {
strcpy(mess, "Could not find detid file\n");
LOG(logERROR, (mess));
return FAIL;
}
// open id file
FILE *fd = fopen(fname, "r");
if (fd == NULL) {
strcpy(mess, "Could not find detid file\n");
LOG(logERROR, (mess));
return FAIL;
}
LOG(logDEBUG1, ("Writing det id to file %s\n", fileName));
// write id
const size_t len = 256;
char line[len];
memset(line, 0, len);
sprintf(line, "%x", arg);
if (EOF == fputs(line, fd)) {
strcpy(mess, "Could not write to detid file\n");
LOG(logERROR, (mess));
return FAIL;
}
return OK;
}

View File

@ -684,8 +684,12 @@ int get_serial_number(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int64_t retval = -1;
#ifdef EIGERD
functionNotImplemented();
#else
retval = getDetectorNumber();
LOG(logDEBUG1, ("detector number retval: 0x%llx\n", (long long int)retval));
#endif
return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
}
@ -9016,12 +9020,12 @@ int get_module_id(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int retval = -1;
#ifndef GOTTHARD2D
#if !(defined(GOTTHARD2D) || defined(EIGERD) || defined(MYTHEN3D))
functionNotImplemented();
#else
retval = getModuleId();
#endif
retval = getModuleId(&ret, mess);
LOG(logDEBUG1, ("module id retval: 0x%x\n", retval));
#endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}
@ -9037,16 +9041,17 @@ int set_module_id(int file_des) {
#ifndef GOTTHARD2D
functionNotImplemented();
#else
if (arg > getMaxModuleId()) {
if (arg > 0xFFFF) {
ret = FAIL;
sprintf(mess, "Could not set module id. Max value: 0x%x\n",
getMaxModuleId());
sprintf(mess, "Could not set module id. Max value: 0x%x\n", 0xFFFF);
LOG(logERROR, (mess));
} else {
setModuleId(arg);
int retval = getModuleId();
LOG(logDEBUG1, ("retval module id: %d\n", retval));
validate(&ret, mess, arg, retval, "set module id", DEC);
setModuleId(&ret, mess, arg);
if (ret != FAIL) {
int retval = getModuleId(&ret, mess);
LOG(logDEBUG1, ("retval module id: %d\n", retval));
validate(&ret, mess, arg, retval, "set module id", DEC);
}
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);

View File

@ -78,13 +78,14 @@ class Detector {
Result<int64_t> getDetectorServerVersion(Positions pos = {}) const;
/* [Jungfrau][Gotthard][Mythen3][Gotthard2][CTB][Moench] */
Result<int64_t> getSerialNumber(Positions pos = {}) const;
/** [Gotthard2] */
/** [Eiger][Gotthard2][Mythen3] */
Result<int> getModuleId(Positions pos = {}) const;
/** [Gotthard2] 6 bit value (ideally unique) that is "
"streamed out1 in the UDP header of the detector. Default is 0. */
"streamed out1 in the UDP header of the detector. */
void setModuleId(const int value, Positions pos = {});
Result<int64_t> getReceiverVersion(Positions pos = {}) const;

View File

@ -1200,12 +1200,14 @@ class CmdProxy {
"\n\tReceiver version in format [0xYYMMDD].");
GET_COMMAND_HEX(serialnumber, getSerialNumber,
"\n\tSerial number of detector.");
"\n\t[Jungfrau][Gotthard][Mythen3][Gotthard2][CTB][Moench]"
"Serial number of detector.");
INTEGER_COMMAND_HEX(
moduleid, getModuleId, setModuleId, StringTo<int>,
"[value]\n\t[Gotthard2] 16 bit value (ideally unique) that is "
"streamed out in the UDP header of the detector. Default is 0.");
"[value]\n\t[Gotthard2][Eiger][Mythen3] 16 bit value (ideally unique) "
"that is streamed out in the UDP header of the detector. "
"\n\t[Gotthard2] Can set it too.");
GET_COMMAND(type, getDetectorType,
"\n\tReturns detector type. Can be Eiger, Jungfrau, Gotthard, "

View File

@ -416,14 +416,14 @@ void Module::loadSettingsFile(const std::string &fname) {
if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) {
std::ostringstream ostfn;
ostfn << fname;
int serialNumberWidth = 3;
int moduleIdWidth = 3;
if (shm()->myDetectorType == MYTHEN3) {
serialNumberWidth = 4;
moduleIdWidth = 4;
}
if ((fname.find(".sn") == std::string::npos) &&
(fname.find(".trim") == std::string::npos)) {
ostfn << ".sn" << std::setfill('0') << std::setw(serialNumberWidth)
<< std::dec << getSerialNumber();
ostfn << ".sn" << std::setfill('0') << std::setw(moduleIdWidth)
<< std::dec << getModuleId();
}
auto myMod = readSettingsFile(ostfn.str());
setModule(myMod);
@ -3326,12 +3326,12 @@ std::string Module::getTrimbitFilename(detectorSettings s, int e_eV) {
throw RuntimeError(
"Settings or trimbit files not defined for this detector.");
}
int serialNumberWidth = 3;
int moduleIdWidth = 3;
if (shm()->myDetectorType == MYTHEN3) {
serialNumberWidth = 4;
moduleIdWidth = 4;
}
ostfn << std::setfill('0') << std::setw(serialNumberWidth) << std::dec
<< getSerialNumber() << std::setbase(10);
ostfn << std::setfill('0') << std::setw(moduleIdWidth) << std::dec
<< getModuleId() << std::setbase(10);
return ostfn.str();
}