G2: reconfigure chip (#927)

* changed common.c readADCFromFile to make it more general and move temperature calculation for Eiger out of this function and inside whereever it is called.
* g2 and m2: gethighvoltage was just a variable set in server, it is now moved to a get inside DAC5671 implementation (but not reading a measured value, instead what is set from a file), high voltage variable used inside DAC5671 for virtual servers
* g2: switching off hv (ifrom non zero to zero value) will wait for 10s; powering on chip reconfigures chip; powering off chip unconfigures chip; powering off chip also includes check if hv = 0, if not throw exception; chip configuration checked before acquring; at start up: hv switched off and chip powered on, so does not wait 10s to switch off hv;
* included test to check powering off chip when hv is on should throw an exception
* g2:  check if chip configured before acquiring

* nios: read hv value set from file and virtual still goes into DAC5671 for conversions to and fro dac to V, change common readadc to readparameter to generalize, make sethighvoltage into a get and set to catch errors in get as well, g2: if not at startup, remmeber hv value before setting it and after check if value was being switched off (from a non zero value) and wait 10s if it was (10s wait only for switching off from non zero and not at startup)
This commit is contained in:
2024-08-02 12:46:39 +02:00
committed by GitHub
parent ce7f01bdc4
commit c13049f144
21 changed files with 300 additions and 86 deletions

View File

@ -4,16 +4,6 @@
#include <inttypes.h>
/**
* Set Defines
* @param hardMaxV maximum hardware limit
* @param driverfname driver file name
*/
void DAC6571_SetDefines(int hardMaxV, char *driverfname);
/**
* Set value
* @param val value to set
* @return OK or FAIL
*/
int DAC6571_Set(int val);
int DAC6571_Get(int *retval);

View File

@ -69,4 +69,4 @@ int deleteFile(char *mess, char *fname, char *errorPrefix);
int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix);
int readADCFromFile(char *fname, int *value);
int readParameterFromFile(char *fname, char *parameterName, int *value);

View File

@ -442,6 +442,9 @@ int getSlowADC(int ichan, int *retval);
int getTemperature(int *retval);
#else
int setHighVoltage(int val);
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
int getHighVoltage(int *retval);
#endif
#endif
// parameters - timing, extsig
@ -650,7 +653,10 @@ int getClockDivider(enum CLKINDEX ind);
#elif GOTTHARD2D
int checkDetectorType(char *mess);
int powerChip(int on);
int powerChip(int on, char *mess);
int getPowerChip();
int isChipConfigured();
int configureChip(char *mess);
void setDBITPipeline(int val);
int getDBITPipeline();
int setPhase(enum CLKINDEX ind, int val, int degrees);

View File

@ -15,12 +15,19 @@
int DAC6571_HardMaxVoltage = 0;
char DAC6571_DriverFileName[MAX_STR_LENGTH];
#ifdef VIRTUAL
int highvoltage = 0;
#endif
void DAC6571_SetDefines(int hardMaxV, char *driverfname) {
LOG(logINFOBLUE, ("Configuring High Voltage to %s (hard max: %dV)\n",
driverfname, hardMaxV));
DAC6571_HardMaxVoltage = hardMaxV;
memset(DAC6571_DriverFileName, 0, MAX_STR_LENGTH);
strcpy(DAC6571_DriverFileName, driverfname);
#ifdef VIRTUAL
highvoltage = 0;
#endif
}
int DAC6571_Set(int val) {
@ -31,11 +38,58 @@ int DAC6571_Set(int val) {
int dacvalue = 0;
// convert value
ConvertToDifferentRange(0, DAC6571_HardMaxVoltage, DAC6571_MIN_DAC_VAL,
DAC6571_MAX_DAC_VAL, val, &dacvalue);
if (ConvertToDifferentRange(0, DAC6571_HardMaxVoltage, DAC6571_MIN_DAC_VAL,
DAC6571_MAX_DAC_VAL, val, &dacvalue) == FAIL) {
LOG(logERROR,
("Could not convert %d high voltage to a valid dac value\n", val));
return FAIL;
}
LOG(logINFO, ("\t%dV (dacval %d)\n", val, dacvalue));
#ifdef VIRTUAL
highvoltage = dacvalue;
#else
// open file
FILE *fd = fopen(DAC6571_DriverFileName, "w");
if (fd == NULL) {
LOG(logERROR,
("Could not open file %s for writing to set high voltage\n",
DAC6571_DriverFileName));
return FAIL;
}
// convert to string, add 0 and write to file
fprintf(fd, "%d\n", dacvalue);
fclose(fd);
#endif
return OK;
}
int DAC6571_Get(int *retval) {
LOG(logDEBUG1, ("Getting high voltage\n"));
int dacvalue = 0;
#ifdef VIRTUAL
dacvalue = highvoltage;
#else
if (readParameterFromFile(DAC6571_DriverFileName, "high voltage",
&dacvalue) == FAIL) {
LOG(logERROR, ("Could not get high voltage\n"));
return FAIL;
}
#endif
// convert value
if (ConvertToDifferentRange(DAC6571_MIN_DAC_VAL, DAC6571_MAX_DAC_VAL, 0,
DAC6571_HardMaxVoltage, dacvalue,
retval) == FAIL) {
LOG(logERROR,
("Could not convert %d dac value to a valid high voltage\n",
dacvalue));
return FAIL;
}
LOG(logINFO, ("\t%dV (dacval %d)\n", (*retval), dacvalue));
#ifndef VIRTUAL
// open file
FILE *fd = fopen(DAC6571_DriverFileName, "w");

View File

@ -727,8 +727,8 @@ int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix) {
return OK;
}
int readADCFromFile(char *fname, int *value) {
LOG(logDEBUG1, ("fname:%s\n", fname));
int readParameterFromFile(char *fname, char *parameterName, int *value) {
LOG(logDEBUG1, ("fname:%s parameter:%s\n", fname, parameterName));
// open file
FILE *fd = fopen(fname, "r");
if (fd == NULL) {
@ -752,20 +752,10 @@ int readADCFromFile(char *fname, int *value) {
*value = -1;
if (sscanf(line, "%d", value) != 1) {
#ifdef XILINX_CHIPTESTBOARDD
LOG(logERROR, ("Could not scan adc from %s\n", line));
#else
LOG(logERROR, ("Could not scan temperature from %s\n", line));
#endif
LOG(logERROR, ("Could not scan %s from %s\n", parameterName, line));
return FAIL;
}
#ifdef EIGERD
*value /= 10;
#elif !defined(XILINX_CHIPTESTBOARDD)
LOG(logINFO, ("Temperature: %.2f °C\n", (double)(*value) / 1000.00));
#endif
fclose(fd);
return OK;
}

View File

@ -1214,12 +1214,39 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
// high voltage
#ifndef XILINX_CHIPTESTBOARDD
case HIGH_VOLTAGE:
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
if ((val != -1 && val < 0) || (val > HV_SOFT_MAX_VOLTAGE)) {
ret = FAIL;
sprintf(mess, "Invalid Voltage. Valid range (0 - %d)\n",
HV_SOFT_MAX_VOLTAGE);
LOG(logERROR, (mess));
} else {
if (val >= 0) {
ret = setHighVoltage(val);
if (ret == FAIL) {
strcpy(mess, "Could not set high voltage.\n");
LOG(logERROR, (mess));
}
}
if (ret == OK) {
ret = getHighVoltage(&retval);
if (ret == FAIL) {
strcpy(mess, "Could not get high voltage.\n");
LOG(logERROR, (mess));
}
LOG(logDEBUG1, ("High Voltage: %d\n", retval));
validate(&ret, mess, val, retval, "set high voltage", DEC);
}
}
#else
retval = setHighVoltage(val);
LOG(logDEBUG1, ("High Voltage: %d\n", retval));
#if defined(JUNGFRAUD) || defined(MOENCHD) || defined(CHIPTESTBOARDD) || \
defined(GOTTHARD2D) || defined(MYTHEN3D)
#if defined(JUNGFRAUD) || defined(MOENCHD) || defined(CHIPTESTBOARDD)
validate(&ret, mess, val, retval, "set high voltage", DEC);
#endif
#endif
#ifdef GOTTHARDD
if (retval == -1) {
ret = FAIL;
@ -1973,20 +2000,24 @@ int acquire(int blocking, int file_des) {
}
// only set
if (Server_VerifyLock() == OK) {
#if defined(XILINX_CHIPTESTBOARDD)
#if defined(XILINX_CHIPTESTBOARDD) || defined(GOTTHARD2D)
if (!isChipConfigured()) {
ret = FAIL;
strcpy(mess, "Could not start acquisition. Chip is not configured. "
"Power it on to configure it.\n");
LOG(logERROR, (mess));
} else if ((getReadoutMode() == TRANSCEIVER_ONLY ||
getReadoutMode() == DIGITAL_AND_TRANSCEIVER) &&
(isTransceiverAligned() == 0)) {
}
#if defined(XILINX_CHIPTESTBOARDD)
else if ((getReadoutMode() == TRANSCEIVER_ONLY ||
getReadoutMode() == DIGITAL_AND_TRANSCEIVER) &&
(isTransceiverAligned() == 0)) {
ret = FAIL;
strcpy(mess, "Could not start acquisition. Transceiver not "
"aligned. Use configtransceiver command.\n");
LOG(logERROR, (mess));
} else
}
#endif
else
#endif
#if defined(JUNGFRAUD)
// chipv1.1 has to be configured before acquisition
@ -4111,7 +4142,7 @@ int power_chip(int file_des) {
}
}
#endif
#ifdef XILINX_CHIPTESTBOARDD
#if defined(XILINX_CHIPTESTBOARDD) || defined(GOTTHARD2D)
if (ret == OK) {
if (arg != -1) {
if (arg != 0 && arg != 1) {