xilinx: wip: dac to voltage needs to be separated and a default value needed or return a -1 for not defined
All checks were successful
Build on RHEL9 / build (push) Successful in 3m17s
Build on RHEL8 / build (push) Successful in 4m45s

This commit is contained in:
2026-01-14 17:01:10 +01:00
parent ae793af7b9
commit 0aab505645
10 changed files with 101 additions and 44 deletions

View File

@@ -401,6 +401,7 @@ void setPower(enum DACINDEX ind, int val);
void powerOff();
#elif XILINX_CHIPTESTBOARDD
int getBitOffsetFromDACIndex(enum DACINDEX ind);
int getMinPowerValue(enum DACINDEX ind);
int isPowerValid(enum DACINDEX ind, int val);
int getPower();
int setPower(enum DACINDEX ind, int val);

View File

@@ -112,7 +112,7 @@ int LTC2620_D_WriteDACValue(int dacnum, int dacvalue, char *dacname) {
dacnum, DAC_POWERDOWN_DRIVER_FILE_SUFFIX);
}
#endif
LOG(logDEBUG1, ("fname %s\n", fname));
LOG(logINFORED, ("fname %s\n", fname));
// open file
FILE *fd = fopen(fname, "w");

View File

@@ -1317,8 +1317,15 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
}
if (ret == OK) {
retval = getPower(serverDacIndex);
LOG(logDEBUG1, ("Power regulator(%d): %d\n", ind, retval));
validate(&ret, mess, val, retval, "set power regulator", DEC);
LOG(logDEBUG1,
("Power regulator(%d): %d\n", serverDacIndex, retval));
if (retval == -1) {
ret = FAIL;
sprintf(mess, "Could not get power regulator %d.\n",
serverDacIndex);
LOG(logERROR, (mess));
}
validate(&ret, mess, val, retval, "set/get power regulator", DEC);
}
break;
#endif
@@ -1400,10 +1407,7 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
LOG(logERROR, (mess));
} else
#endif
#ifdef MYTHEN3D
// ignore counter enable to force vth dac values
setDAC(serverDacIndex, val, mV, 0);
#elif defined(XILINX_CHIPTESTBOARDD)
#if defined(XILINX_CHIPTESTBOARDD)
{
if (val != GET_FLAG) {
ret = setDAC(serverDacIndex, val, mV);
@@ -1413,11 +1417,28 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
LOG(logERROR, (mess));
}
}
if (ret == OK) {
retval = getDAC(serverDacIndex, mV);
LOG(logDEBUG1, ("Dac (%d): %d %s\n", serverDacIndex, retval,
(mV ? "mV" : "dac units")));
if (retval == -1) {
ret = FAIL;
sprintf(mess, "Could not get dac %d.\n",
serverDacIndex);
LOG(logERROR, (mess));
}
}
}
#elif MYTHEN3D
// ignore counter enable to force vth dac values
setDAC(serverDacIndex, val, mV, 0);
#else
setDAC(serverDacIndex, val, mV);
#endif
retval = getDAC(serverDacIndex, mV);
LOG(logDEBUG1, ("Dac (%d): %d %s\n", serverDacIndex, retval,
(mV ? "mV" : "dac units")));
#endif
}
#ifdef EIGERD
if (val != GET_FLAG && getSettings() != UNDEFINED) {

View File

@@ -416,8 +416,10 @@ void setupDetector() {
for (int idac = 0; idac < NDAC_ONLY; ++idac) {
setDAC(idac, LTC2620_D_GetPowerDownValue(), 0);
}
LOG(logINFOBLUE, ("Defaulting all power regulators to 0 mV.\n"));
LOG(logINFOBLUE, ("Defaulting all power regulators to minimum.\n"));
for (int idac = NDAC_ONLY; idac < NDAC; ++idac) {
if (idac == D_PWR_EMPTY)
continue;
setPower(idac, 0);
}
@@ -1154,8 +1156,6 @@ int setDAC(enum DACINDEX ind, int val, int mV) {
char dacName[MAX_STR_LENGTH] = {0};
memset(dacName, 0, MAX_STR_LENGTH);
sprintf(dacName, "dac%d", (int)ind);
LOG(logDEBUG1, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dacName, val,
(mV ? "mV" : "dac units")));
// invalid index (only dacs, no power regulators)
if (ind >= NDAC_ONLY) {
@@ -1164,7 +1164,7 @@ int setDAC(enum DACINDEX ind, int val, int mV) {
}
// ensure vlimit compliance
{
if (val != LTC2620_D_GetPowerDownValue()) {
int dacmV = val;
if (!mV) {
// convert dac units to mV
@@ -1183,6 +1183,8 @@ int setDAC(enum DACINDEX ind, int val, int mV) {
}
// set dac
LOG(logINFO, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dacName, val,
(mV ? "mV" : "dac units")));
int dacval = -1;
if (LTC2620_D_SetDACValue((int)ind, val, mV, dacName, &dacval) == FAIL)
return FAIL;
@@ -1192,12 +1194,23 @@ int setDAC(enum DACINDEX ind, int val, int mV) {
}
int getDAC(enum DACINDEX ind, int mV) {
// invalid index (only dacs, no power regulators)
if (ind >= NDAC_ONLY) {
LOG(logERROR, ("Invalid DAC index: %d\n", ind));
return -1;
}
// get dac in dac units
if (!mV) {
LOG(logDEBUG1, ("Getting DAC %d : %d dac\n", ind, dacValues[ind]));
return dacValues[ind];
}
int voltage = -1;
LTC2620_D_DacToVoltage(dacValues[ind], &voltage);
// convert dac units to mV
int voltage = dacToVoltage(dacValues[ind]);
if (voltage == -1) {
LOG(logERROR, ("Could not convert %d dac units to mV for dac %d\n",
dacValues[ind], ind));
return -1;
}
LOG(logDEBUG1,
("Getting DAC %d : %d dac (%d mV)\n", ind, dacValues[ind], voltage));
return voltage;
@@ -1258,19 +1271,31 @@ int getBitOffsetFromDACIndex(enum DACINDEX ind) {
}
}
int getMinPowerValue(enum DACINDEX ind) {
if (ind < D_PWR_D || ind > D_PWR_C || ind == D_PWR_EMPTY) {
LOG(logERROR, ("Invalid Power DAC index: %d\n", ind));
return -1;
}
if (ind == D_PWR_IO) {
return VIO_MIN_MV;
}
return POWER_RGLTR_MIN;
}
int isPowerValid(enum DACINDEX ind, int val) {
if (ind < D_PWR_D || ind > D_PWR_C || ind == D_PWR_EMPTY) {
LOG(logERROR, ("Invalid Power DAC index: %d\n", ind));
return -1;
}
char *powerNames[] = {PWR_NAMES};
int pwrIndex = (int)(ind - D_PWR_D);
int min = POWER_RGLTR_MIN;
if (!strcmp(powerNames[pwrIndex], "IO")) {
min = VIO_MIN_MV;
}
int min = getMinPowerValue(ind);
// check vlimit (already checked at funcs.c)
if (checkVLimitCompliant(val) == FAIL) {
LOG(logERROR,
("Invalid value of %d mV for Power V%s. Exceeds vLimit of %d mV\n",
("Invalid value of %d mV for Power %s. Exceeds vLimit of %d mV\n",
val, powerNames[pwrIndex], vLimit));
return 0;
}
@@ -1278,7 +1303,7 @@ int isPowerValid(enum DACINDEX ind, int val) {
// not power_rgltr_max because it is allowed only upto vchip max - 200
if ((val != 0 && val < min) || val > POWER_RGLTR_MAX) {
LOG(logERROR,
("Invalid value of %d mV for Power V%s. Is not between %d and "
("Invalid value of %d mV for Power %s. Is not between %d and "
"%d mV\n",
val, powerNames[pwrIndex], min, POWER_RGLTR_MAX));
return 0;
@@ -1287,6 +1312,10 @@ int isPowerValid(enum DACINDEX ind, int val) {
}
int getPower(enum DACINDEX ind) {
if (ind < D_PWR_D || ind > D_PWR_C || ind == D_PWR_EMPTY) {
LOG(logERROR, ("Invalid Power DAC index: %d\n", ind));
return -1;
}
// get bit offset in ctrl register
int bitOffset = getBitOffsetFromDACIndex(ind);
if (bitOffset == -1) {
@@ -1303,31 +1332,28 @@ int getPower(enum DACINDEX ind) {
char *powerNames[] = {PWR_NAMES};
int pwrIndex = (int)(ind - D_PWR_D);
int min = getMinPowerValue(ind);
// not set yet
if (dacValues[ind] == -1) {
LOG(logERROR,
("Unknown dac value for Power V%s!\n", powerNames[pwrIndex]));
("Unknown dac value for Power %s!\n", powerNames[pwrIndex]));
return -1;
}
// dac powered off
if (dacValues[ind] == LTC2620_D_GetPowerDownValue()) {
LOG(logWARNING, ("Power V%s enabled, but voltage is at minimum or 0.\n",
powerNames[pwrIndex]));
return LTC2620_D_GetPowerDownValue();
}
// get dac in mV
int retval = -1;
ConvertToDifferentRange(LTC2620_D_GetMaxInput(), LTC2620_D_GetMinInput(),
POWER_RGLTR_MIN, POWER_RGLTR_MAX, dacValues[ind],
&retval);
min, POWER_RGLTR_MAX, dacValues[ind], &retval);
return retval;
}
int setPower(enum DACINDEX ind, int val) {
if (ind < D_PWR_D || ind > D_PWR_C || ind == D_PWR_EMPTY) {
LOG(logERROR, ("Invalid Power DAC index: %d\n", ind));
return FAIL;
}
if (!isPowerValid(ind, val)) {
return FAIL;
}
@@ -1342,33 +1368,29 @@ int setPower(enum DACINDEX ind, int val) {
char *powerNames[] = {PWR_NAMES};
int pwrIndex = (int)(ind - D_PWR_D);
LOG(logINFO, ("Setting Power V%s to %d mV\n", powerNames[pwrIndex], val));
int min = getMinPowerValue(ind);
LOG(logINFO, ("Setting Power %s to %d mV\n", powerNames[pwrIndex], val));
// Switch off power enable
LOG(logDEBUG1, ("\tSwitching off power enable\n"));
bus_w(addr, bus_r(addr) & ~(mask));
// set dac value to 0
if (LTC2620_D_WriteDACValue((int)ind, 0, powerNames[pwrIndex]) == FAIL)
return FAIL;
dacValues[ind] = 0;
if (val > 0) {
// convert voltage to dac
int dacval = -1;
if (ConvertToDifferentRange(
POWER_RGLTR_MIN, POWER_RGLTR_MAX, LTC2620_D_GetMaxInput(),
min, POWER_RGLTR_MAX, LTC2620_D_GetMaxInput(),
LTC2620_D_GetMinInput(), val, &dacval) == FAIL) {
LOG(logERROR,
("\tCannot convert Power V%s to dac value. Invalid value of %d "
("\tCannot convert Power %s to dac value. Invalid value of %d "
"mV. Is not between "
"%d and %d mV\n",
powerNames[pwrIndex], val, POWER_RGLTR_MIN, POWER_RGLTR_MAX));
powerNames[pwrIndex], val, min, POWER_RGLTR_MAX));
return FAIL;
}
// set dac value
LOG(logINFO, ("\tSetting DAC V%s: %d mV (%d dac)\n",
LOG(logINFO, ("\tSetting DAC %s: %d mV (%d dac)\n",
powerNames[pwrIndex], val, dacval));
if (LTC2620_D_WriteDACValue((int)ind, dacval, powerNames[pwrIndex]) ==
FAIL)
@@ -1376,7 +1398,7 @@ int setPower(enum DACINDEX ind, int val) {
dacValues[ind] = dacval;
// Switch on power enable
LOG(logDEBUG1, ("\tSwitching on power enable for Power V%s\n",
LOG(logDEBUG1, ("\tSwitching on power enable for Power %s\n",
powerNames[pwrIndex]));
bus_w(addr, bus_r(addr) | mask);
}

View File

@@ -119,7 +119,7 @@ enum DACINDEX {
D_PWR_C
};
#define PWR_NAMES "D", "_unknown", "IO", "A", "B", "C"
#define PWR_NAMES "VD", "_unknown", "VIO", "VA", "VB", "VC"
/* Struct Definitions */
// For arm has to be multiple of 16

View File

@@ -753,10 +753,12 @@ TEST_CASE("v_limit", "[.cmdcall]") {
if (det_type == defs::CHIPTESTBOARD ||
det_type == defs::XILINX_CHIPTESTBOARD) {
auto prev_val = det.getPower(defs::V_LIMIT);
auto prev_va = det.getPower(defs::V_POWER_A);
{
std::ostringstream oss;
caller.call("v_limit", {"1500"}, -1, PUT, oss);
REQUIRE(oss.str() == "v_limit 1500\n");
REQUIRE_THROWS(caller.call("v_a", {"1600"}, -1, PUT, oss));
}
{
std::ostringstream oss;
@@ -778,6 +780,7 @@ TEST_CASE("v_limit", "[.cmdcall]") {
prev_val[i] = 0;
}
det.setPower(defs::V_LIMIT, prev_val[i], {i});
det.setPower(defs::V_POWER_A, prev_va[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("v_limit", {}, -1, GET));
@@ -1053,6 +1056,16 @@ TEST_CASE("v_abcd", "[.cmdcall]") {
caller.call(cmds[i], {}, -1, GET, oss2);
REQUIRE(oss2.str() == cmds[i] + " 1200\n");
}
if (det_type == defs::XILINX_CHIPTESTBOARD &&
det.isVirtualDetectorServer().tsquash(
"inconsistent virtual values")) {
// prev value for power regulators should have been 0
// as they are only touched in this test
REQUIRE(prev_val.squash(-1) == 0);
REQUIRE_THROWS(caller.call(cmds[i], {"-100"}, -1, PUT));
}
for (int i = 0; i != det.size(); ++i) {
if (det_type == defs::XILINX_CHIPTESTBOARD &&
prev_val[i] == -100) {

View File

@@ -9,4 +9,4 @@
#define APIEIGER "0.0.0 0x250909"
#define APIXILINXCTB "0.0.0 0x260114"
#define APIJUNGFRAU "0.0.0 0x250909"
#define APIMYTHEN3 "0.0.0 0x260113"
#define APIMYTHEN3 "0.0.0 0x260114"