nios temp (#557)

* fixed temp read nios

* divide for eiger and dont print
This commit is contained in:
Dhanya Thattil 2022-10-18 15:47:23 +02:00 committed by GitHub
parent 4a7cd051c1
commit 46bb9bc2d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 171 additions and 100 deletions

View File

@ -100,6 +100,7 @@ This document describes the differences between v7.0.0 and v6.x.x
- jungfrau reset core and usleep removed (fix for 6.1.1 is now fixed in firmware) - jungfrau reset core and usleep removed (fix for 6.1.1 is now fixed in firmware)
- g2 change clkdivs 2 3 4 to defaults for burst and cw mode. - g2 change clkdivs 2 3 4 to defaults for burst and cw mode.
- ctb and moench: allowing 1g non blocking acquire to send data - ctb and moench: allowing 1g non blocking acquire to send data
- m3 and g2 temp
- gain plot zooming fixed (disabled, acc. to main plot) - gain plot zooming fixed (disabled, acc. to main plot)
- ctb, moench, jungfrau (pll reset at start fixed, before no defines) - ctb, moench, jungfrau (pll reset at start fixed, before no defines)

View File

@ -395,35 +395,11 @@ int Feb_Control_ReceiveHighVoltage(unsigned int *value) {
// normal // normal
if (Feb_Control_normal) { if (Feb_Control_normal) {
// open file
FILE *fd = fopen(NORMAL_HIGHVOLTAGE_INPUTPORT, "r");
if (fd == NULL) {
LOG(logERROR,
("Could not open file for writing to get high voltage\n"));
return 0;
}
// read, assigning line to null and readbytes to 0 then getline if (readADCFromFile(NORMAL_HIGHVOLTAGE_INPUTPORT, value) == FAIL) {
// allocates initial buffer LOG(logERROR, ("Could not get high voltage\n"));
size_t readbytes = 0;
char *line = NULL;
if (getline(&line, &readbytes, fd) == -1) {
LOG(logERROR, ("could not read file to get high voltage\n"));
return 0; return 0;
} }
// read again to read the updated value
rewind(fd);
free(line);
readbytes = 0;
readbytes = getline(&line, &readbytes, fd);
if (readbytes == -1) {
LOG(logERROR, ("could not read file to get high voltage\n"));
return 0;
}
// Remove the trailing 0
*value = atoi(line) / 10;
free(line);
fclose(fd);
} }
// 9m // 9m

View File

@ -1506,6 +1506,15 @@ int getDAC(enum DACINDEX ind, int mV) {
int getMaxDacSteps() { return LTC2620_D_GetMaxNumSteps(); } int getMaxDacSteps() { return LTC2620_D_GetMaxNumSteps(); }
int getADC(enum ADCINDEX ind, int *value) {
LOG(logDEBUG1, ("Reading FPGA temperature...\n"));
if (readADCFromFile(TEMPERATURE_FILE_NAME, value) == FAIL) {
LOG(logERROR, ("Could not get temperature\n"));
return FAIL;
}
return OK;
}
int setHighVoltage(int val) { int setHighVoltage(int val) {
if (val > HV_SOFT_MAX_VOLTAGE) { if (val > HV_SOFT_MAX_VOLTAGE) {
val = HV_SOFT_MAX_VOLTAGE; val = HV_SOFT_MAX_VOLTAGE;

View File

@ -12,18 +12,23 @@
#define CTRL_SRVR_INIT_TIME_US (300 * 1000) #define CTRL_SRVR_INIT_TIME_US (300 * 1000)
/* Hardware Definitions */ /* Hardware Definitions */
#define NCHAN (128) #define NCHAN (128)
#define NCHIP (10) #define NCHIP (10)
#define NDAC (16) #define NDAC (16)
#define NADC (32) #define NADC (32)
#define ONCHIP_NDAC (7) #define ONCHIP_NDAC (7)
#define DYNAMIC_RANGE (16) #define DYNAMIC_RANGE (16)
#define HV_SOFT_MAX_VOLTAGE (500) #define HV_SOFT_MAX_VOLTAGE (500)
#define HV_HARD_MAX_VOLTAGE (530) #define HV_HARD_MAX_VOLTAGE (530)
#define HV_DRIVER_FILE_NAME ("/etc/devlinks/hvdac") #define HV_DRIVER_FILE_NAME ("/etc/devlinks/hvdac")
#define DAC_DRIVER_FILE_NAME ("/etc/devlinks/dac") #define DAC_DRIVER_FILE_NAME ("/etc/devlinks/dac")
#define ONCHIP_DAC_DRIVER_FILE_NAME ("/etc/devlinks/chipdac") #define ONCHIP_DAC_DRIVER_FILE_NAME ("/etc/devlinks/chipdac")
#define TYPE_FILE_NAME ("/etc/devlinks/type") #define TYPE_FILE_NAME ("/etc/devlinks/type")
#ifdef VIRTUAL
#define TEMPERATURE_FILE_NAME ("/tmp/temp.txt")
#else
#define TEMPERATURE_FILE_NAME ("/sys/class/hwmon/hwmon0/temp1_input")
#endif
#define CONFIG_FILE ("config_gotthard2.txt") #define CONFIG_FILE ("config_gotthard2.txt")
#define DAC_MAX_MV (2048) #define DAC_MAX_MV (2048)
#define ONCHIP_DAC_MAX_VAL (0x3FF) #define ONCHIP_DAC_MAX_VAL (0x3FF)
@ -157,6 +162,8 @@ enum CLKINDEX {
"READOUT_C0", "READOUT_C1", "SYSTEM_C0", "SYSTEM_C1", "SYSTEM_C2", \ "READOUT_C0", "READOUT_C1", "SYSTEM_C0", "SYSTEM_C1", "SYSTEM_C2", \
"SYSTEM_C3" "SYSTEM_C3"
enum ADCINDEX { TEMP_FPGA };
enum PLLINDEX { READOUT_PLL, SYSTEM_PLL }; enum PLLINDEX { READOUT_PLL, SYSTEM_PLL };
enum MASTERINDEX { MASTER_HARDWARE, OW_MASTER, OW_SLAVE }; enum MASTERINDEX { MASTER_HARDWARE, OW_MASTER, OW_SLAVE };

View File

@ -1647,6 +1647,15 @@ int getDAC(enum DACINDEX ind, int mV) {
int getMaxDacSteps() { return LTC2620_D_GetMaxNumSteps(); } int getMaxDacSteps() { return LTC2620_D_GetMaxNumSteps(); }
int getADC(enum ADCINDEX ind, int *value) {
LOG(logDEBUG1, ("Reading FPGA temperature...\n"));
if (readADCFromFile(TEMPERATURE_FILE_NAME, value) == FAIL) {
LOG(logERROR, ("Could not get temperature\n"));
return FAIL;
}
return OK;
}
int setHighVoltage(int val) { int setHighVoltage(int val) {
// limit values // limit values
if (val > HV_SOFT_MAX_VOLTAGE) { if (val > HV_SOFT_MAX_VOLTAGE) {

View File

@ -12,18 +12,23 @@
#define CTRL_SRVR_INIT_TIME_US (300 * 1000) #define CTRL_SRVR_INIT_TIME_US (300 * 1000)
/* Hardware Definitions */ /* Hardware Definitions */
#define NCOUNTERS (3) #define NCOUNTERS (3)
#define MAX_COUNTER_MSK (0x7) #define MAX_COUNTER_MSK (0x7)
#define NCHAN_1_COUNTER (128) #define NCHAN_1_COUNTER (128)
#define NCHAN (128 * NCOUNTERS) #define NCHAN (128 * NCOUNTERS)
#define NCHIP (10) #define NCHIP (10)
#define NCHAN_PER_MODULE (NCHAN * NCHIP) #define NCHAN_PER_MODULE (NCHAN * NCHIP)
#define NDAC (16) #define NDAC (16)
#define HV_SOFT_MAX_VOLTAGE (500) #define HV_SOFT_MAX_VOLTAGE (500)
#define HV_HARD_MAX_VOLTAGE (530) #define HV_HARD_MAX_VOLTAGE (530)
#define HV_DRIVER_FILE_NAME ("/etc/devlinks/hvdac") #define HV_DRIVER_FILE_NAME ("/etc/devlinks/hvdac")
#define DAC_DRIVER_FILE_NAME ("/etc/devlinks/dac") #define DAC_DRIVER_FILE_NAME ("/etc/devlinks/dac")
#define TYPE_FILE_NAME ("/etc/devlinks/type") #define TYPE_FILE_NAME ("/etc/devlinks/type")
#ifdef VIRTUAL
#define TEMPERATURE_FILE_NAME ("/tmp/temp.txt")
#else
#define TEMPERATURE_FILE_NAME ("/sys/class/hwmon/hwmon0/temp1_input")
#endif
#define DAC_MAX_MV (2048) #define DAC_MAX_MV (2048)
#define TYPE_MYTHEN3_MODULE_VAL (93) #define TYPE_MYTHEN3_MODULE_VAL (93)
#define TYPE_TOLERANCE (5) #define TYPE_TOLERANCE (5)
@ -117,6 +122,8 @@ enum DACINDEX {
800 /* VdcSh */ \ 800 /* VdcSh */ \
}; };
enum ADCINDEX { TEMP_FPGA };
#define NUMSETTINGS (3) #define NUMSETTINGS (3)
#define NSPECIALDACS (2) #define NSPECIALDACS (2)
#define SPECIALDACINDEX {M_VRPREAMP, M_VRSHAPER}; #define SPECIALDACINDEX {M_VRPREAMP, M_VRSHAPER};

View File

@ -68,3 +68,5 @@ int createEmptyFile(char *mess, char *fname, char *errorPrefix);
int deleteFile(char *mess, char *fname, char *errorPrefix); int deleteFile(char *mess, char *fname, char *errorPrefix);
int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix); int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix);
int readADCFromFile(char *fname, int *value);

View File

@ -378,7 +378,9 @@ void setPower(enum DACINDEX ind, int val);
void powerOff(); void powerOff();
#endif #endif
#if !defined(MOENCHD) && !defined(MYTHEN3D) && !defined(GOTTHARD2D) #if defined(MYTHEN3D) || defined(GOTTHARD2D)
int getADC(enum ADCINDEX ind, int *value);
#elif !defined(MOENCHD)
int getADC(enum ADCINDEX ind); int getADC(enum ADCINDEX ind);
#endif #endif

View File

@ -701,3 +701,38 @@ int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix) {
} }
return OK; return OK;
} }
int readADCFromFile(char *fname, int *value) {
LOG(logDEBUG1, ("fname:%s\n", fname));
// open file
FILE *fd = fopen(fname, "r");
if (fd == NULL) {
LOG(logERROR, ("Could not open file for reading [%s]\n", fname));
return FAIL;
}
const size_t LZ = 256;
char line[LZ];
memset(line, 0, LZ);
if (NULL == fgets(line, LZ, fd)) {
LOG(logERROR, ("Could not read from file %s\n", fname));
*value = -1;
return FAIL;
}
*value = -1;
if (sscanf(line, "%d", value) != 1) {
LOG(logERROR, ("Could not scan temperature from %s\n", line));
return FAIL;
}
#ifdef EIGERD
*value /= 10;
#else
LOG(logINFO, ("Temperature: %.2f °C\n", (double)(*value) / 1000.00));
#endif
fclose(fd);
return OK;
}

View File

@ -1375,13 +1375,18 @@ int get_adc(int file_des) {
if (receiveData(file_des, &ind, sizeof(ind), INT32) < 0) if (receiveData(file_des, &ind, sizeof(ind), INT32) < 0)
return printSocketReadError(); return printSocketReadError();
#if defined(MOENCHD) || defined(MYTHEN3D) || defined(GOTTHARD2D) #if defined(MOENCHD)
functionNotImplemented(); functionNotImplemented();
#else #else
enum ADCINDEX serverAdcIndex = 0; enum ADCINDEX serverAdcIndex = 0;
// get // get
switch (ind) { switch (ind) {
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
case TEMPERATURE_FPGA:
serverAdcIndex = TEMP_FPGA;
break;
#endif
#if defined(GOTTHARDD) || defined(JUNGFRAUD) #if defined(GOTTHARDD) || defined(JUNGFRAUD)
case TEMPERATURE_FPGA: case TEMPERATURE_FPGA:
serverAdcIndex = TEMP_FPGA; serverAdcIndex = TEMP_FPGA;
@ -1481,8 +1486,18 @@ int get_adc(int file_des) {
// valid index // valid index
if (ret == OK) { if (ret == OK) {
LOG(logDEBUG1, ("Getting ADC %d\n", serverAdcIndex)); LOG(logDEBUG1, ("Getting ADC %d\n", serverAdcIndex));
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
ret = getADC(serverAdcIndex, &retval);
if (ret == FAIL) {
strcpy(mess, "Could not get temperature\n");
LOG(logERROR, (mess));
} else {
LOG(logDEBUG1, ("ADC(%d): %d\n", serverAdcIndex, retval));
}
#else
retval = getADC(serverAdcIndex); retval = getADC(serverAdcIndex);
LOG(logDEBUG1, ("ADC(%d): %d\n", serverAdcIndex, retval)); LOG(logDEBUG1, ("ADC(%d): %d\n", serverAdcIndex, retval));
#endif
} }
#endif #endif
@ -1882,55 +1897,57 @@ int acquire(int blocking, int file_des) {
#ifdef EIGERD #ifdef EIGERD
// check for hardware mac and hardware ip // check for hardware mac and hardware ip
if (udpDetails[0].srcmac != getDetectorMAC()) { if (udpDetails[0].srcmac != getDetectorMAC()) {
ret = FAIL; ret = FAIL;
uint64_t sourcemac = getDetectorMAC(); uint64_t sourcemac = getDetectorMAC();
char src_mac[MAC_ADDRESS_SIZE]; char src_mac[MAC_ADDRESS_SIZE];
getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, sourcemac); getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, sourcemac);
sprintf(mess, sprintf(
mess,
"Invalid udp source mac address for this detector. Must be " "Invalid udp source mac address for this detector. Must be "
"same as hardware detector mac address %s\n", "same as hardware detector mac address %s\n",
src_mac); src_mac);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else if (!enableTenGigabitEthernet(GET_FLAG) && } else if (!enableTenGigabitEthernet(GET_FLAG) &&
(udpDetails[0].srcip != getDetectorIP())) { (udpDetails[0].srcip != getDetectorIP())) {
ret = FAIL;
uint32_t sourceip = getDetectorIP();
char src_ip[INET_ADDRSTRLEN];
getIpAddressinString(src_ip, sourceip);
sprintf(
mess,
"Invalid udp source ip address for this detector. Must be "
"same as hardware detector ip address %s in 1G readout mode \n",
src_ip);
LOG(logERROR, (mess));
} else
#endif
if (configured == FAIL) {
ret = FAIL;
strcpy(mess, "Could not start acquisition because ");
strcat(mess, configureMessage);
LOG(logERROR, (mess));
} else if (sharedMemory_getScanStatus() == RUNNING) {
ret = FAIL;
strcpy(mess, "Could not start acquisition because a scan is "
"already running!\n");
LOG(logERROR, (mess));
} else {
memset(scanErrMessage, 0, MAX_STR_LENGTH);
sharedMemory_setScanStop(0);
sharedMemory_setScanStatus(IDLE); // if it was error
if (pthread_create(&pthread_tid, NULL, &start_state_machine,
&blocking)) {
ret = FAIL; ret = FAIL;
strcpy(mess, "Could not start acquisition thread!\n"); uint32_t sourceip = getDetectorIP();
char src_ip[INET_ADDRSTRLEN];
getIpAddressinString(src_ip, sourceip);
sprintf(
mess,
"Invalid udp source ip address for this detector. Must be "
"same as hardware detector ip address %s in 1G readout "
"mode \n",
src_ip);
LOG(logERROR, (mess));
} else
#endif
if (configured == FAIL) {
ret = FAIL;
strcpy(mess, "Could not start acquisition because ");
strcat(mess, configureMessage);
LOG(logERROR, (mess));
} else if (sharedMemory_getScanStatus() == RUNNING) {
ret = FAIL;
strcpy(mess, "Could not start acquisition because a scan is "
"already running!\n");
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else { } else {
// only does not wait for non blocking and scan memset(scanErrMessage, 0, MAX_STR_LENGTH);
if (blocking || !scan) { sharedMemory_setScanStop(0);
pthread_join(pthread_tid, NULL); sharedMemory_setScanStatus(IDLE); // if it was error
if (pthread_create(&pthread_tid, NULL, &start_state_machine,
&blocking)) {
ret = FAIL;
strcpy(mess, "Could not start acquisition thread!\n");
LOG(logERROR, (mess));
} else {
// only does not wait for non blocking and scan
if (blocking || !scan) {
pthread_join(pthread_tid, NULL);
}
} }
} }
}
} }
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
} }
@ -2011,7 +2028,6 @@ void *start_state_machine(void *arg) {
break; break;
} }
#if defined(CHIPTESTBOARDD) || defined(MOENCHD) #if defined(CHIPTESTBOARDD) || defined(MOENCHD)
readFrames(&ret, mess); readFrames(&ret, mess);
if (ret == FAIL && scan) { if (ret == FAIL && scan) {
@ -2019,7 +2035,7 @@ void *start_state_machine(void *arg) {
strcat(scanErrMessage, mess); strcat(scanErrMessage, mess);
sharedMemory_setScanStatus(ERROR); sharedMemory_setScanStatus(ERROR);
break; break;
} }
#endif #endif
// blocking or scan // blocking or scan
if (*blocking || times > 1) { if (*blocking || times > 1) {

View File

@ -453,6 +453,7 @@ class Detector {
/** /**
* (Degrees) * (Degrees)
* [Mythen3][Gotthard2] Options: TEMPERATURE_FPGA
* [Gotthard] Options: TEMPERATURE_ADC, TEMPERATURE_FPGA \n * [Gotthard] Options: TEMPERATURE_ADC, TEMPERATURE_FPGA \n
* [Jungfrau] Options: TEMPERATURE_ADC, TEMPERATURE_FPGA \n * [Jungfrau] Options: TEMPERATURE_ADC, TEMPERATURE_FPGA \n
* [Eiger] Options: TEMPERATURE_FPGA, TEMPERATURE_FPGAEXT, TEMPERATURE_10GE, * [Eiger] Options: TEMPERATURE_FPGA, TEMPERATURE_FPGAEXT, TEMPERATURE_10GE,

View File

@ -1450,9 +1450,10 @@ class CmdProxy {
GET_IND_COMMAND(temp_adc, getTemperature, slsDetectorDefs::TEMPERATURE_ADC, GET_IND_COMMAND(temp_adc, getTemperature, slsDetectorDefs::TEMPERATURE_ADC,
" °C", "[n_value]\n\t[Jungfrau][Gotthard] ADC Temperature"); " °C", "[n_value]\n\t[Jungfrau][Gotthard] ADC Temperature");
GET_IND_COMMAND( GET_IND_COMMAND(temp_fpga, getTemperature,
temp_fpga, getTemperature, slsDetectorDefs::TEMPERATURE_FPGA, " °C", slsDetectorDefs::TEMPERATURE_FPGA, " °C",
"[n_value]\n\t[Eiger][Jungfrau][Gotthard] FPGA Temperature"); "[n_value]\n\t[Eiger][Jungfrau][Gotthard][Mythen3]["
"Gotthard2] FPGA Temperature");
GET_IND_COMMAND(temp_fpgaext, getTemperature, GET_IND_COMMAND(temp_fpgaext, getTemperature,
slsDetectorDefs::TEMPERATURE_FPGAEXT, " °C", slsDetectorDefs::TEMPERATURE_FPGAEXT, " °C",

View File

@ -605,6 +605,9 @@ std::vector<defs::dacIndex> Detector::getTemperatureList() const {
defs::TEMPERATURE_10GE, defs::TEMPERATURE_DCDC, defs::TEMPERATURE_10GE, defs::TEMPERATURE_DCDC,
defs::TEMPERATURE_SODL, defs::TEMPERATURE_SODR, defs::TEMPERATURE_SODL, defs::TEMPERATURE_SODR,
defs::TEMPERATURE_FPGA2, defs::TEMPERATURE_FPGA3}; defs::TEMPERATURE_FPGA2, defs::TEMPERATURE_FPGA3};
case defs::MYTHEN3:
case defs::GOTTHARD2:
return std::vector<defs::dacIndex>{defs::TEMPERATURE_FPGA};
default: default:
return std::vector<defs::dacIndex>{}; return std::vector<defs::dacIndex>{};
} }
@ -631,6 +634,8 @@ Result<int> Detector::getTemperature(defs::dacIndex index,
switch (getDetectorType().squash()) { switch (getDetectorType().squash()) {
case defs::EIGER: case defs::EIGER:
case defs::JUNGFRAU: case defs::JUNGFRAU:
case defs::MYTHEN3:
case defs::GOTTHARD2:
for (auto &it : res) { for (auto &it : res) {
it /= 1000; it /= 1000;
} }

View File

@ -1853,8 +1853,7 @@ TEST_CASE("temp_fpga", "[.cmd]") {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash(); auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::GOTTHARD || if (det_type != defs::MOENCH) {
det_type == defs::EIGER) {
REQUIRE_NOTHROW(proxy.Call("temp_fpga", {}, -1, GET)); REQUIRE_NOTHROW(proxy.Call("temp_fpga", {}, -1, GET));
std::ostringstream oss; std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("temp_fpga", {}, 0, GET, oss)); REQUIRE_NOTHROW(proxy.Call("temp_fpga", {}, 0, GET, oss));

View File

@ -12,3 +12,4 @@
#define APIMYTHEN3 0x221004 #define APIMYTHEN3 0x221004
#define APIMOENCH 0x221004 #define APIMOENCH 0x221004
#define APIEIGER 0x221004 #define APIEIGER 0x221004