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)
- g2 change clkdivs 2 3 4 to defaults for burst and cw mode.
- ctb and moench: allowing 1g non blocking acquire to send data
- m3 and g2 temp
- gain plot zooming fixed (disabled, acc. to main plot)
- 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
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
// allocates initial buffer
size_t readbytes = 0;
char *line = NULL;
if (getline(&line, &readbytes, fd) == -1) {
LOG(logERROR, ("could not read file to get high voltage\n"));
if (readADCFromFile(NORMAL_HIGHVOLTAGE_INPUTPORT, value) == FAIL) {
LOG(logERROR, ("Could not get high voltage\n"));
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

View File

@ -1506,6 +1506,15 @@ int getDAC(enum DACINDEX ind, int mV) {
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) {
if (val > HV_SOFT_MAX_VOLTAGE) {
val = HV_SOFT_MAX_VOLTAGE;

View File

@ -24,6 +24,11 @@
#define DAC_DRIVER_FILE_NAME ("/etc/devlinks/dac")
#define ONCHIP_DAC_DRIVER_FILE_NAME ("/etc/devlinks/chipdac")
#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 DAC_MAX_MV (2048)
#define ONCHIP_DAC_MAX_VAL (0x3FF)
@ -157,6 +162,8 @@ enum CLKINDEX {
"READOUT_C0", "READOUT_C1", "SYSTEM_C0", "SYSTEM_C1", "SYSTEM_C2", \
"SYSTEM_C3"
enum ADCINDEX { TEMP_FPGA };
enum PLLINDEX { READOUT_PLL, SYSTEM_PLL };
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 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) {
// limit values
if (val > HV_SOFT_MAX_VOLTAGE) {

View File

@ -24,6 +24,11 @@
#define HV_DRIVER_FILE_NAME ("/etc/devlinks/hvdac")
#define DAC_DRIVER_FILE_NAME ("/etc/devlinks/dac")
#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 TYPE_MYTHEN3_MODULE_VAL (93)
#define TYPE_TOLERANCE (5)
@ -117,6 +122,8 @@ enum DACINDEX {
800 /* VdcSh */ \
};
enum ADCINDEX { TEMP_FPGA };
#define NUMSETTINGS (3)
#define NSPECIALDACS (2)
#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 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();
#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);
#endif

View File

@ -701,3 +701,38 @@ int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix) {
}
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)
return printSocketReadError();
#if defined(MOENCHD) || defined(MYTHEN3D) || defined(GOTTHARD2D)
#if defined(MOENCHD)
functionNotImplemented();
#else
enum ADCINDEX serverAdcIndex = 0;
// get
switch (ind) {
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
case TEMPERATURE_FPGA:
serverAdcIndex = TEMP_FPGA;
break;
#endif
#if defined(GOTTHARDD) || defined(JUNGFRAUD)
case TEMPERATURE_FPGA:
serverAdcIndex = TEMP_FPGA;
@ -1481,8 +1486,18 @@ int get_adc(int file_des) {
// valid index
if (ret == OK) {
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);
LOG(logDEBUG1, ("ADC(%d): %d\n", serverAdcIndex, retval));
#endif
}
#endif
@ -1886,7 +1901,8 @@ int acquire(int blocking, int file_des) {
uint64_t sourcemac = getDetectorMAC();
char src_mac[MAC_ADDRESS_SIZE];
getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, sourcemac);
sprintf(mess,
sprintf(
mess,
"Invalid udp source mac address for this detector. Must be "
"same as hardware detector mac address %s\n",
src_mac);
@ -1900,7 +1916,8 @@ int acquire(int blocking, int file_des) {
sprintf(
mess,
"Invalid udp source ip address for this detector. Must be "
"same as hardware detector ip address %s in 1G readout mode \n",
"same as hardware detector ip address %s in 1G readout "
"mode \n",
src_ip);
LOG(logERROR, (mess));
} else
@ -2011,7 +2028,6 @@ void *start_state_machine(void *arg) {
break;
}
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
readFrames(&ret, mess);
if (ret == FAIL && scan) {

View File

@ -453,6 +453,7 @@ class Detector {
/**
* (Degrees)
* [Mythen3][Gotthard2] Options: TEMPERATURE_FPGA
* [Gotthard] Options: TEMPERATURE_ADC, TEMPERATURE_FPGA \n
* [Jungfrau] Options: TEMPERATURE_ADC, TEMPERATURE_FPGA \n
* [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,
" °C", "[n_value]\n\t[Jungfrau][Gotthard] ADC Temperature");
GET_IND_COMMAND(
temp_fpga, getTemperature, slsDetectorDefs::TEMPERATURE_FPGA, " °C",
"[n_value]\n\t[Eiger][Jungfrau][Gotthard] FPGA Temperature");
GET_IND_COMMAND(temp_fpga, getTemperature,
slsDetectorDefs::TEMPERATURE_FPGA, " °C",
"[n_value]\n\t[Eiger][Jungfrau][Gotthard][Mythen3]["
"Gotthard2] FPGA Temperature");
GET_IND_COMMAND(temp_fpgaext, getTemperature,
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_SODL, defs::TEMPERATURE_SODR,
defs::TEMPERATURE_FPGA2, defs::TEMPERATURE_FPGA3};
case defs::MYTHEN3:
case defs::GOTTHARD2:
return std::vector<defs::dacIndex>{defs::TEMPERATURE_FPGA};
default:
return std::vector<defs::dacIndex>{};
}
@ -631,6 +634,8 @@ Result<int> Detector::getTemperature(defs::dacIndex index,
switch (getDetectorType().squash()) {
case defs::EIGER:
case defs::JUNGFRAU:
case defs::MYTHEN3:
case defs::GOTTHARD2:
for (auto &it : res) {
it /= 1000;
}

View File

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

View File

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