mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-06-04 16:38:41 +02:00
wip. compiles
This commit is contained in:
@@ -593,7 +593,8 @@ void setupDetector() {
|
||||
// dacs only
|
||||
LOG(logINFOBLUE, ("Powering down all dacs\n"));
|
||||
for (int idac = 0; idac < NDAC_ONLY; ++idac) {
|
||||
initError = setDAC(idac, LTC2620_GetPowerDownValue(), 0, initErrorMessage);
|
||||
initError =
|
||||
setDAC(idac, LTC2620_GetPowerDownValue(), 0, initErrorMessage);
|
||||
if (initError == FAIL)
|
||||
return;
|
||||
}
|
||||
@@ -606,7 +607,6 @@ void setupDetector() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// I2C
|
||||
INA226_ConfigureI2CCore(I2C_SHUNT_RESISTER_OHMS, I2C_CONTROL_REG,
|
||||
I2C_STATUS_REG, I2C_RX_DATA_FIFO_REG,
|
||||
@@ -622,8 +622,6 @@ void setupDetector() {
|
||||
if (initError == FAIL)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
setADCInvertRegister(0); // depends on chip
|
||||
|
||||
LOG(logINFOBLUE, ("Setting Default parameters\n"));
|
||||
@@ -1238,28 +1236,28 @@ int64_t getMeasurementTime() {
|
||||
enum detectorSettings getSettings() { return UNDEFINED; }
|
||||
|
||||
/* parameters - dac, adc, hv */
|
||||
int setADCVpp(int val, int mV, char* mess) {
|
||||
int setADCVpp(int val, int mV, char *mess) {
|
||||
if (AD9257_SetVrefVoltage(val, mV) == FAIL) {
|
||||
sprintf(mess, "Could not set Adc Vpp. Please set a proper value\n");
|
||||
LOG(logERROR, (mess));
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// cannot validate (just a variable and mv gives different values
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getADCVpp(int mV, int* retval, char* mess) {
|
||||
int getADCVpp(int mV, int *retval, char *mess) {
|
||||
*retval = AD9257_GetVrefVoltage(mV);
|
||||
if (*retval == -1) {
|
||||
sprintf(mess, "Could not get Adc Vpp.\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logDEBUG1, ("Adc Vpp retval: %d %s\n", *retval, (mV ? "mV" : "mode")));
|
||||
return OK;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
// validate index
|
||||
if (ind < 0 || ind >= NDAC) {
|
||||
sprintf(mess, "Could not set DAC %d. Invalid index.\n", ind);
|
||||
@@ -1269,13 +1267,20 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
// validate mV
|
||||
if (mV) {
|
||||
if (val == LTC2620_GetPowerDownValue()) {
|
||||
sprintf(mess, "Could not set DAC %d. Cannot use power down value and use 'mV'\n", ind);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %d. Cannot use power down value and use "
|
||||
"'mV'\n",
|
||||
ind);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// power regulators are converted to dacs at setPower with diff conv.
|
||||
if (ind >= NDAC_ONLY) {
|
||||
sprintf(mess, "Could not set DAC %d. Cannot convert to dac units for power regulator at this stage. Should have been earlier.\n", ind);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %d. Cannot convert to dac units for power "
|
||||
"regulator at this stage. Should have been earlier.\n",
|
||||
ind);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1290,13 +1295,16 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
// validate max value
|
||||
if (val != LTC2620_GetPowerDownValue()) {
|
||||
if (!mV) {
|
||||
// dacs and power regs
|
||||
if (val > LTC2620_GetMaxInput()) {
|
||||
sprintf(mess, "Could not set DAC %d. Input %d exceeds max dac value %d\n", (int)ind, val, LTC2620_GetMaxInput());
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %d. Input %d exceeds max dac value %d\n",
|
||||
(int)ind, val, LTC2620_GetMaxInput());
|
||||
LOG(logERROR, (mess))
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1304,26 +1312,38 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
if (vLimit > 0 && ind < NDAC_ONLY) {
|
||||
int dacmV = 0;
|
||||
if (LTC2620_DacToVoltage(val, &dacmV) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %d. Could not convert input %d to mV\n", ind, val);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %d. Could not convert input %d "
|
||||
"to mV\n",
|
||||
ind, val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
if (dacmV > vLimit) {
|
||||
sprintf(mess, "Could not set DAC %d. Input %d (%d mV) exceeds vLimit value %d\n", ind, val, dacmV, vLimit);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %d. Input %d (%d mV) exceeds "
|
||||
"vLimit value %d\n",
|
||||
ind, val, dacmV, vLimit);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// only dacs in mV here
|
||||
else {
|
||||
if (val > DAC_MAX_MV) {
|
||||
sprintf("Could not set DAC %d. Input %d mV exceeds max dac value %d mV\n", ind, val, DAC_MAX_MV);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %d. Input %d mV exceeds max dac "
|
||||
"value %d mV\n",
|
||||
ind, val, DAC_MAX_MV);
|
||||
LOG(logERROR, (mess))
|
||||
return FAIL;
|
||||
}
|
||||
if (vLimit > 0 && val > vLimit) {
|
||||
sprintf("Could not set DAC %d. Input %d mV exceeds vLimit %d mV\n", (int)ind, val, vLimit);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %d. Input %d mV exceeds vLimit %d mV\n",
|
||||
(int)ind, val, vLimit);
|
||||
LOG(logERROR, (mess))
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1332,17 +1352,21 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
if (validateDAC(ind, val, mV, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
LOG(logINFO, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
|
||||
LOG(logINFO, ("Setting dac[%d]: %d %s \n", (int)ind, val,
|
||||
(mV ? "mV" : "dac units")));
|
||||
|
||||
// dacs only, mV, convert to dac value
|
||||
int dacval = val;
|
||||
if (mV && ind < NDAC) {
|
||||
if (LTC2620_VoltageToDac(val, &dacval) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %d. Could not convert %d mV to dac units.\n", ind, val);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %d. Could not convert %d mV to dac units.\n",
|
||||
ind, val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1353,12 +1377,12 @@ int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
dacValues[ind] = dacval;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
|
||||
// validate index
|
||||
if (ind < 0 || ind > NDAC) {
|
||||
sprintf(mess, "Could not get DAC %d. Invalid index.\n", ind);
|
||||
@@ -1367,7 +1391,10 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
}
|
||||
// validate mV
|
||||
if (mV && ind >= NDAC_ONLY) {
|
||||
sprintf(mess, "Could not get DAC %d. Cannot convert to dac units for power regulator at this stage. Should have been earlier.\n", ind);
|
||||
sprintf(mess,
|
||||
"Could not get DAC %d. Cannot convert to dac units for power "
|
||||
"regulator at this stage. Should have been earlier.\n",
|
||||
ind);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1380,7 +1407,9 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
// convert to mV
|
||||
*retval = -1;
|
||||
if (LTC2620_DacToVoltage(dacValues[ind], retval) == FAIL) {
|
||||
sprintf(mess, "Could not get DAC %d. Could not convert %d dac units to mV\n", ind, dacValues[ind]);
|
||||
sprintf(mess,
|
||||
"Could not get DAC %d. Could not convert %d dac units to mV\n",
|
||||
ind, dacValues[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1389,32 +1418,34 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int getVLimit() { return vLimit; }
|
||||
|
||||
int setVLimit(int val, char* mess) {
|
||||
int setVLimit(int val, char *mess) {
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set vlimit. Invalid value %d\n", val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
vLimit = val;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int getVchip(int* retval, char* mess) {
|
||||
int getVchip(int *retval, char *mess) {
|
||||
*retval = -1;
|
||||
// not set yet
|
||||
if (dacValues[D_PWR_CHIP] == -1) {
|
||||
LOG(logWARNING, ("Retrieving Vchip that has not been set yet.\n"));
|
||||
return dacValues[D_PWR_CHIP];
|
||||
}
|
||||
}
|
||||
if (dacValues[D_PWR_CHIP] == LTC2620_GetPowerDownValue()) {
|
||||
return dacValues[D_PWR_CHIP];
|
||||
}
|
||||
// dac to voltage
|
||||
if (ConvertToDifferentRange(LTC2620_GetMaxInput(), LTC2620_GetMinInput(), VCHIP_MIN_MV, VCHIP_MAX_MV, dacValues[D_PWR_CHIP], retval) == FAIL) {
|
||||
sprintf(mess, "Could not convert to voltage. Input value for vchip outside bounds.\n");
|
||||
if (ConvertToDifferentRange(LTC2620_GetMaxInput(), LTC2620_GetMinInput(),
|
||||
VCHIP_MIN_MV, VCHIP_MAX_MV,
|
||||
dacValues[D_PWR_CHIP], retval) == FAIL) {
|
||||
sprintf(mess, "Could not convert to voltage. Input value for vchip "
|
||||
"outside bounds.\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1422,7 +1453,7 @@ int getVchip(int* retval, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setVchip(int val, char* mess) {
|
||||
int setVchip(int val, char *mess) {
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set vchip. Invalid value: %d\n", val);
|
||||
LOG(logERROR, (mess));
|
||||
@@ -1434,34 +1465,37 @@ int setVchip(int val, char* mess) {
|
||||
int dacval = LTC2620_GetPowerDownValue();
|
||||
if (val != LTC2620_GetPowerDownValue()) {
|
||||
// convert voltage to dac
|
||||
if (ConvertToDifferentRange(
|
||||
VCHIP_MIN_MV, VCHIP_MAX_MV, LTC2620_GetMaxInput(),
|
||||
LTC2620_GetMinInput(), // min val is max V
|
||||
val, &dacval) == FAIL) {
|
||||
sprintf(mess, "\tVChip %d mV invalid. Is not between %d and %d mV\n", val, VCHIP_MIN_MV, VCHIP_MAX_MV);
|
||||
if (ConvertToDifferentRange(VCHIP_MIN_MV, VCHIP_MAX_MV,
|
||||
LTC2620_GetMaxInput(),
|
||||
LTC2620_GetMinInput(), // min val is max V
|
||||
val, &dacval) == FAIL) {
|
||||
sprintf(mess,
|
||||
"\tVChip %d mV invalid. Is not between %d and %d mV\n", val,
|
||||
VCHIP_MIN_MV, VCHIP_MAX_MV);
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
LOG(logINFO, ("Setting Vchip (DAC %d): %d dac (%d mV)\n", D_PWR_CHIP,
|
||||
dacval, val));
|
||||
LOG(logINFO,
|
||||
("Setting Vchip (DAC %d): %d dac (%d mV)\n", D_PWR_CHIP, dacval, val));
|
||||
if (setDAC(D_PWR_CHIP, dacval, 0, mess) == FAIL)
|
||||
return FAIL;
|
||||
if (dacValues[D_PWR_CHIP] != dacval) {
|
||||
sprintf(mess, "Could not set vchip. Set %d, got %d\n", val, dacValues[D_PWR_CHIP]);
|
||||
sprintf(mess, "Could not set vchip. Set %d, got %d\n", val,
|
||||
dacValues[D_PWR_CHIP]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getVChipToSet(enum DACINDEX ind, int val, int* vchip, char* mess) {
|
||||
int getVChipToSet(enum DACINDEX ind, int val, int *vchip, char *mess) {
|
||||
LOG(logDEBUG1, ("Calculating vchip to set\n"));
|
||||
enum PWRINDEX pwrIndex = 0;
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
|
||||
// validate index
|
||||
if (getPowerIndex(ind, &pwrIndex, mess) == FAIL)
|
||||
return FAIL;
|
||||
return FAIL;
|
||||
|
||||
// get the max of all the power regulators
|
||||
int max = 0;
|
||||
@@ -1488,7 +1522,10 @@ int getVChipToSet(enum DACINDEX ind, int val, int* vchip, char* mess) {
|
||||
*vchip = VCHIP_MIN_MV;
|
||||
// this shouldnt happen as isPowerValid should have already given error
|
||||
if (*vchip > VCHIP_MAX_MV) {
|
||||
sprintf(mess, " Could not set %s. Vchip value to set %d is beyond its maximum %d\n", powerNames[pwrIndex], *vchip, VCHIP_MAX_MV);
|
||||
sprintf(mess,
|
||||
" Could not set %s. Vchip value to set %d is beyond its "
|
||||
"maximum %d\n",
|
||||
powerNames[pwrIndex], *vchip, VCHIP_MAX_MV);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1498,7 +1535,7 @@ int getVChipToSet(enum DACINDEX ind, int val, int* vchip, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int isPowerValid(enum PWRINDEX ind, int val, char* mess) {
|
||||
int isPowerValid(enum PWRINDEX ind, int val, char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
|
||||
int min = (ind == PWR_IO) ? VIO_MIN_MV : POWER_RGLTR_MIN;
|
||||
@@ -1507,16 +1544,19 @@ int isPowerValid(enum PWRINDEX ind, int val, char* mess) {
|
||||
// also checking vlimit if set
|
||||
if (vLimit > 0 && vLimit < max)
|
||||
max = vLimit;
|
||||
|
||||
|
||||
if (val != 0 && (val < min || val > max)) {
|
||||
sprintf(mess, "Could not set %s. Invalid value. Must be between %d and %d mV\n", powerNames[ind], min, max);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set %s. Invalid value. Must be between %d and %d mV\n",
|
||||
powerNames[ind], min, max);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getPowerRailMask(enum PWRINDEX ind, uint32_t* mask, char* mess) {
|
||||
int getPowerRailMask(enum PWRINDEX ind, uint32_t *mask, char *mess) {
|
||||
mask = 0;
|
||||
switch (ind) {
|
||||
case PWR_IO:
|
||||
@@ -1542,7 +1582,7 @@ int getPowerRailMask(enum PWRINDEX ind, uint32_t* mask, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int EnablePowerRail(enum PWRINDEX ind, char* mess) {
|
||||
int EnablePowerRail(enum PWRINDEX ind, char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
uint32_t addr = POWER_REG;
|
||||
uint32_t mask = 0;
|
||||
@@ -1555,7 +1595,7 @@ int EnablePowerRail(enum PWRINDEX ind, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int DisablePowerRail(enum PWRINDEX ind, char* mess) {
|
||||
int DisablePowerRail(enum PWRINDEX ind, char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
uint32_t addr = POWER_REG;
|
||||
uint32_t mask = 0;
|
||||
@@ -1568,7 +1608,7 @@ int DisablePowerRail(enum PWRINDEX ind, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getPowerRail(enum PWRINDEX ind, int* retval, char* mess) {
|
||||
int getPowerRail(enum PWRINDEX ind, int *retval, char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
uint32_t addr = POWER_REG;
|
||||
uint32_t mask = 0;
|
||||
@@ -1577,13 +1617,14 @@ int getPowerRail(enum PWRINDEX ind, int* retval, char* mess) {
|
||||
return FAIL;
|
||||
|
||||
*retval = (bus_r(addr) & mask);
|
||||
LOG(logDEBUG1, ("Power rail retval for %s: %s\n", powerNames[ind], ((*retval > 0) ? "Enabled" : "Disabled")));
|
||||
LOG(logDEBUG1, ("Power rail retval for %s: %s\n", powerNames[ind],
|
||||
((*retval > 0) ? "Enabled" : "Disabled")));
|
||||
|
||||
return OK;
|
||||
return OK;
|
||||
}
|
||||
|
||||
// for power rail index and name debugging
|
||||
int getPowerIndex(enum DACINDEX ind, enum PWRINDEX* pwrIndex, char* mess) {
|
||||
int getPowerIndex(enum DACINDEX ind, enum PWRINDEX *pwrIndex, char *mess) {
|
||||
pwrIndex = 0;
|
||||
switch (ind) {
|
||||
case D_PWR_IO:
|
||||
@@ -1609,31 +1650,38 @@ int getPowerIndex(enum DACINDEX ind, enum PWRINDEX* pwrIndex, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int convertPowerRegDACtoVoltage(enum PWRINDEX ind, int val, int* retval, char* mess) {
|
||||
int convertPowerRegDACtoVoltage(enum PWRINDEX ind, int val, int *retval,
|
||||
char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
if (ConvertToDifferentRange(LTC2620_GetMaxInput(), LTC2620_GetMinInput(), POWER_RGLTR_MIN, POWER_RGLTR_MAX, val, retval) == FAIL) {
|
||||
sprintf(mess, "Could not get %s. Could not convert %d dac to mV\n", powerNames[ind], val);
|
||||
if (ConvertToDifferentRange(LTC2620_GetMaxInput(), LTC2620_GetMinInput(),
|
||||
POWER_RGLTR_MIN, POWER_RGLTR_MAX, val,
|
||||
retval) == FAIL) {
|
||||
sprintf(mess, "Could not get %s. Could not convert %d dac to mV\n",
|
||||
powerNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int convertPowerRegVoltagetoDAC(enum PWRINDEX ind, int val, int* retval, char* mess) {
|
||||
int convertPowerRegVoltagetoDAC(enum PWRINDEX ind, int val, int *retval,
|
||||
char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
if (ConvertToDifferentRange(POWER_RGLTR_MIN, POWER_RGLTR_MAX, LTC2620_GetMaxInput(), LTC2620_GetMinInput(), val, retval) == FAIL) {
|
||||
sprintf(mess, "Could not set %s. Invalid value %d mV to convert to dac units.\n", powerNames[ind], val);
|
||||
if (ConvertToDifferentRange(POWER_RGLTR_MIN, POWER_RGLTR_MAX,
|
||||
LTC2620_GetMaxInput(), LTC2620_GetMinInput(),
|
||||
val, retval) == FAIL) {
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set %s. Invalid value %d mV to convert to dac units.\n",
|
||||
powerNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getPower(enum DACINDEX ind, int* retval, char* mess) {
|
||||
int getPower(enum DACINDEX ind, int *retval, char *mess) {
|
||||
enum PWRINDEX pwrIndex = 0;
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
*retval = -1;
|
||||
|
||||
// validate index
|
||||
@@ -1650,13 +1698,14 @@ int getPower(enum DACINDEX ind, int* retval, char* mess) {
|
||||
}
|
||||
|
||||
// to mV
|
||||
if (convertPowerRegDACtoVoltage(pwrIndex, dacValues[ind], retval, mess) == FAIL)
|
||||
if (convertPowerRegDACtoVoltage(pwrIndex, dacValues[ind], retval, mess) ==
|
||||
FAIL)
|
||||
return FAIL;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setPower(enum DACINDEX ind, int val, char* mess) {
|
||||
int setPower(enum DACINDEX ind, int val, char *mess) {
|
||||
enum PWRINDEX pwrIndex = 0;
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
|
||||
@@ -1665,15 +1714,15 @@ int setPower(enum DACINDEX ind, int val, char* mess) {
|
||||
return FAIL;
|
||||
|
||||
// validate values (invalidate power down)
|
||||
if (!isPowerValid(pwrIndex, val, mess) == FAIL)
|
||||
if (isPowerValid(pwrIndex, val, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
|
||||
LOG(logINFOBLUE, ("Setting %s to %d mV\n", val));
|
||||
|
||||
// get vchip to set vchip before setting power regulator
|
||||
// calculate now before power off
|
||||
int vchip = 0;
|
||||
if (getVChipToSet(ind, val, vchip, mess) == FAIL)
|
||||
if (getVChipToSet(ind, val, &vchip, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
if (DisablePowerRail(pwrIndex, mess) == FAIL)
|
||||
@@ -1689,7 +1738,8 @@ int setPower(enum DACINDEX ind, int val, char* mess) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
LOG(logINFO, ("Setting %s (DAC %d): %d dac (%d mV)\n", powerNames[pwrIndex], dacval, val));
|
||||
LOG(logINFO, ("Setting %s (DAC %d): %d dac (%d mV)\n", powerNames[pwrIndex],
|
||||
dacval, val));
|
||||
if (setDAC(ind, dacval, 0, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
@@ -1701,7 +1751,7 @@ int setPower(enum DACINDEX ind, int val, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int initPower(enum DACINDEX ind, char* mess) {
|
||||
int initPower(enum DACINDEX ind, char *mess) {
|
||||
if (ind == D_PWR_CHIP)
|
||||
return OK;
|
||||
|
||||
@@ -1711,12 +1761,13 @@ int initPower(enum DACINDEX ind, char* mess) {
|
||||
|
||||
int dacval = 0;
|
||||
int min = (ind == D_PWR_IO) ? VIO_MIN_MV : POWER_RGLTR_MIN;
|
||||
if (convertPowerRegVoltagetoDAC(pwrIndex, min, &dacval, initErrorMessage) == FAIL)
|
||||
if (convertPowerRegVoltagetoDAC(pwrIndex, min, &dacval, initErrorMessage) ==
|
||||
FAIL)
|
||||
return FAIL;
|
||||
|
||||
if (setDAC(ind, dacval, 0, initErrorMessage) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -1883,7 +1934,7 @@ int getSlowADCTemperature() {
|
||||
return tempValue;
|
||||
}
|
||||
|
||||
int setHighVoltage(int val, char* mess) {
|
||||
int setHighVoltage(int val, char *mess) {
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set high voltage. Invalid value:%d\n", val);
|
||||
LOG(logERROR, (mess));
|
||||
@@ -1905,12 +1956,11 @@ int setHighVoltage(int val, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getHighVoltage(int *retval, char* mess) {
|
||||
int getHighVoltage(int *retval, char *mess) {
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", retval));
|
||||
return highvoltage;
|
||||
}
|
||||
|
||||
|
||||
/* parameters - timing, extsig */
|
||||
|
||||
void setTiming(enum timingMode arg) {
|
||||
|
||||
@@ -123,39 +123,41 @@ enum detectorSettings getSettings();
|
||||
|
||||
// parameters - threshold
|
||||
// parameters - dac, adc, hv
|
||||
int setADCVpp(int val, int mV, char* mess);
|
||||
int getADCVpp(int mV, int* retval, char* mess);
|
||||
int setADCVpp(int val, int mV, char *mess);
|
||||
int getADCVpp(int mV, int *retval, char *mess);
|
||||
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess);
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess);
|
||||
int getVLimit();
|
||||
int setVLimit(int val, char* mess);
|
||||
int setVLimit(int val, char *mess);
|
||||
|
||||
int getVchip(int* retval, char* mess);
|
||||
int setVchip(int val, char* mess);
|
||||
int getVChipToSet(enum DACINDEX ind, int val, int* vchip, char* mess);
|
||||
int getVchip(int *retval, char *mess);
|
||||
int setVchip(int val, char *mess);
|
||||
int getVChipToSet(enum DACINDEX ind, int val, int *vchip, char *mess);
|
||||
|
||||
int getPowerRailMask(enum PWRINDEX ind, uint32_t* mask, char* mess);
|
||||
int EnablePowerRail(enum PWRINDEX ind, char* mess);
|
||||
int DisablePowerRail(enum PWRINDEX ind, char* mess);
|
||||
int getPowerRail(enum PWRINDEX ind, int* retval, char* mess);
|
||||
int getPowerRailMask(enum PWRINDEX ind, uint32_t *mask, char *mess);
|
||||
int EnablePowerRail(enum PWRINDEX ind, char *mess);
|
||||
int DisablePowerRail(enum PWRINDEX ind, char *mess);
|
||||
int getPowerRail(enum PWRINDEX ind, int *retval, char *mess);
|
||||
|
||||
int isPowerValid(enum PWRINDEX ind, int val, char* mess);
|
||||
int getPowerIndex(enum DACINDEX ind, enum PWRINDEX* pwrIndex, char* mess);
|
||||
int isPowerValid(enum PWRINDEX ind, int val, char *mess);
|
||||
int getPowerIndex(enum DACINDEX ind, enum PWRINDEX *pwrIndex, char *mess);
|
||||
|
||||
int convertPowerRegDACtoVoltage(enum PWRINDEX ind, int val, int* retval, char* mess);
|
||||
int convertPowerRegVoltagetoDAC(enum PWRINDEX ind, int val, int* retval, char* mess);
|
||||
int getPower(enum DACINDEX ind, int* retval, char* mess);
|
||||
int setPower(enum DACINDEX ind, int val, char* mess);
|
||||
int initPower(enum DACINDEX ind, char* mess);
|
||||
int convertPowerRegDACtoVoltage(enum PWRINDEX ind, int val, int *retval,
|
||||
char *mess);
|
||||
int convertPowerRegVoltagetoDAC(enum PWRINDEX ind, int val, int *retval,
|
||||
char *mess);
|
||||
int getPower(enum DACINDEX ind, int *retval, char *mess);
|
||||
int setPower(enum DACINDEX ind, int val, char *mess);
|
||||
int initPower(enum DACINDEX ind, char *mess);
|
||||
void powerOff();
|
||||
|
||||
int getADC(enum ADCINDEX ind);
|
||||
int getSlowADC(int ichan);
|
||||
int getSlowADCTemperature();
|
||||
int setHighVoltage(int val, char* mess);
|
||||
int getHighVoltage(int *retval, char* mess);
|
||||
int setHighVoltage(int val, char *mess);
|
||||
int getHighVoltage(int *retval, char *mess);
|
||||
|
||||
// parameters - timing, extsig
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ enum DACINDEX {
|
||||
D_PWR_IO
|
||||
};
|
||||
|
||||
enum PWRINDEX { PWR_IO, PWR_A, PWR_B, PWR_C, PWR_D};
|
||||
enum PWRINDEX { PWR_IO, PWR_A, PWR_B, PWR_C, PWR_D };
|
||||
#define PWR_NAMES "VIO", "VA", "VB", "VC", "VD"
|
||||
|
||||
enum CLKINDEX { RUN_CLK, ADC_CLK, SYNC_CLK, DBIT_CLK, NUM_CLOCKS };
|
||||
|
||||
@@ -868,7 +868,7 @@ void setupDetector() {
|
||||
LOG(logDEBUG1, ("Setup detector done\n\n"));
|
||||
}
|
||||
|
||||
int resetToDefaultDacs(int hardReset, char* mess) {
|
||||
int resetToDefaultDacs(int hardReset, char *mess) {
|
||||
// reset defaults to hardcoded defaults
|
||||
if (hardReset) {
|
||||
const int vals[] = DEFAULT_DAC_VALS;
|
||||
@@ -1403,7 +1403,7 @@ int setModule(sls_detector_module myMod, char *mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setSettings(enum detectorSettings sett, char* mess) {
|
||||
int setSettings(enum detectorSettings sett, char *mess) {
|
||||
if (sett == UNINITIALIZED) {
|
||||
sprintf(mess, "Cannot set settings to uninitialized\n");
|
||||
LOG(logERROR, (mess));
|
||||
@@ -1433,7 +1433,7 @@ int setThresholdEnergy(int ev) {
|
||||
}
|
||||
|
||||
/* parameters - dac, adc, hv */
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
|
||||
// validate index (including E_VTHRESHOLD)
|
||||
@@ -1444,32 +1444,37 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
}
|
||||
// validate min value
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d cannot be negative\n", dacNames[ind], val);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d cannot be negative\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate max value
|
||||
if (mV && val > DAC_MAX_MV) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d exceed maximum %d mV\n", dacNames[ind], val, DAC_MAX_MV);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d mV\n",
|
||||
dacNames[ind], val, DAC_MAX_MV);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
else if (!mV && val > LTC2620_MAX_VAL) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d exceed maximum %d \n", dacNames[ind], val, LTC2620_MAX_VAL);
|
||||
} else if (!mV && val > LTC2620_MAX_VAL) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d \n",
|
||||
dacNames[ind], val, LTC2620_MAX_VAL);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
// uses LTC2620 with 2.048V (implementation different to others not bit banging)
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
if (validateDAC(ind, val, mV, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val, (mV ? "mV" : "dac units")));
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val,
|
||||
(mV ? "mV" : "dac units")));
|
||||
|
||||
if (ind == E_VTHRESHOLD) {
|
||||
if (setDAC(E_VCMP_LL, val, mV, mess) == FAIL)
|
||||
@@ -1488,8 +1493,12 @@ int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
// mV: convert to dac value
|
||||
int dacval = val;
|
||||
if (mV) {
|
||||
if (ConvertToDifferentRange(DAC_MIN_MV, DAC_MAX_MV, LTC2620_MIN_VAL, LTC2620_MAX_VAL, val, &dacval) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %s. Could not convert %d mV to dac units.\n", dacNames[ind], val);
|
||||
if (ConvertToDifferentRange(DAC_MIN_MV, DAC_MAX_MV, LTC2620_MIN_VAL,
|
||||
LTC2620_MAX_VAL, val, &dacval) == FAIL) {
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1507,7 +1516,7 @@ int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
|
||||
// validate index (including E_VTHRESHOLD)
|
||||
if (ind < 0 || ind >= NDAC + 1) {
|
||||
sprintf(mess, "Could not set DAC. Invalid index %d\n", ind);
|
||||
@@ -1515,8 +1524,6 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (ind == E_VTHRESHOLD) {
|
||||
int retval[5] = {0};
|
||||
if (getDAC(E_VCMP_LL, mV, &retval[0], mess) == FAIL)
|
||||
@@ -1530,35 +1537,43 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
if (getDAC(E_VCP, mV, &retval[4], mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
if ((retval[0] != retval[1]) || (retval[1] != retval[2]) || (retval[2] != retval[3]) || (retval[3] != retval[4])) {
|
||||
sprintf(mess, "Vthreshold mismatch. vcmp_ll:%d vcmp_lr:%d vcmp_rl:%d vcmp_rr:%d vcp:%d\n", retval[0], retval[1], retval[2], retval[3], retval[4]);
|
||||
if ((retval[0] != retval[1]) || (retval[1] != retval[2]) ||
|
||||
(retval[2] != retval[3]) || (retval[3] != retval[4])) {
|
||||
sprintf(mess,
|
||||
"Vthreshold mismatch. vcmp_ll:%d vcmp_lr:%d vcmp_rl:%d "
|
||||
"vcmp_rr:%d vcp:%d\n",
|
||||
retval[0], retval[1], retval[2], retval[3], retval[4]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("\tvthreshold match\n"));
|
||||
*retval = retval[0];
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
if (!mV) {
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac\n", dacNames[ind], (detectorModules)->dacs[ind]));
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac\n", dacNames[ind],
|
||||
(detectorModules)->dacs[ind]));
|
||||
*retval = (detectorModules)->dacs[ind];
|
||||
return OK;
|
||||
}
|
||||
// convert to mV
|
||||
*retval = -1;
|
||||
if (ConvertToDifferentRange(LTC2620_MIN_VAL, LTC2620_MAX_VAL, DAC_MIN_MV, DAC_MAX_MV, (detectorModules)->dacs[ind], retval) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %s. Could not convert %d mV to dac units.\n", dacNames[ind], (detectorModules)->dacs[ind]);
|
||||
if (ConvertToDifferentRange(LTC2620_MIN_VAL, LTC2620_MAX_VAL, DAC_MIN_MV,
|
||||
DAC_MAX_MV, (detectorModules)->dacs[ind],
|
||||
retval) == FAIL) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
|
||||
dacNames[ind], (detectorModules)->dacs[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logDEBUG1,
|
||||
("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind], (detectorModules)->dacs[ind], *retval));
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind],
|
||||
(detectorModules)->dacs[ind], *retval));
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int getADC(enum ADCINDEX ind) {
|
||||
#ifdef VIRTUAL
|
||||
return 0;
|
||||
@@ -1605,7 +1620,7 @@ int getADC(enum ADCINDEX ind) {
|
||||
#endif
|
||||
}
|
||||
|
||||
int getHighVoltage(int* retval, char* mess) {
|
||||
int getHighVoltage(int *retval, char *mess) {
|
||||
if (!master) {
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", SLAVE_HIGH_VOLTAGE_READ_VAL));
|
||||
*retval = SLAVE_HIGH_VOLTAGE_READ_VAL;
|
||||
@@ -1623,7 +1638,9 @@ int getHighVoltage(int* retval, char* mess) {
|
||||
if (!Feb_Control_GetHighVoltage(&eiger_highvoltage)) {
|
||||
LOG(logERROR, ("Could not read high voltage\n"));
|
||||
sharedMemory_unlockLocalLink();
|
||||
strcpy(mess, "Getting high voltage failed. Serial/i2c communication failed.\n");
|
||||
strcpy(
|
||||
mess,
|
||||
"Getting high voltage failed. Serial/i2c communication failed.\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1631,7 +1648,9 @@ int getHighVoltage(int* retval, char* mess) {
|
||||
if (!Feb_Control_GetHighVoltage(&eiger_highvoltage)) {
|
||||
LOG(logERROR, ("Could not read high voltage\n"));
|
||||
sharedMemory_unlockLocalLink();
|
||||
strcpy(mess, "Getting high voltage failed. Serial/i2c communication failed.\n");
|
||||
strcpy(
|
||||
mess,
|
||||
"Getting high voltage failed. Serial/i2c communication failed.\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1640,8 +1659,7 @@ int getHighVoltage(int* retval, char* mess) {
|
||||
// tolerance of 5
|
||||
if (abs(eiger_theo_highvoltage - eiger_highvoltage) >
|
||||
HIGH_VOLTAGE_TOLERANCE) {
|
||||
LOG(logINFO,
|
||||
("High voltage still ramping: %d\n", eiger_highvoltage));
|
||||
LOG(logINFO, ("High voltage still ramping: %d\n", eiger_highvoltage));
|
||||
*retval = eiger_highvoltage;
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", eiger_highvoltage));
|
||||
return OK;
|
||||
@@ -1650,10 +1668,9 @@ int getHighVoltage(int* retval, char* mess) {
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", eiger_theo_highvoltage));
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int setHighVoltage(int val, char* mess) {
|
||||
int setHighVoltage(int val, char *mess) {
|
||||
#ifdef VIRTUAL
|
||||
LOG(logINFO, ("Setting High voltage: %d V\n", val));
|
||||
eiger_theo_highvoltage = val;
|
||||
@@ -1664,12 +1681,17 @@ int setHighVoltage(int val, char* mess) {
|
||||
sharedMemory_unlockLocalLink();
|
||||
|
||||
if (ret == 0) {
|
||||
strcpy(mess, "Setting high voltage failed. Serial/i2c communication failed.\n");
|
||||
strcpy(
|
||||
mess,
|
||||
"Setting high voltage failed. Serial/i2c communication failed.\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
if (ret == -1) {
|
||||
sprintf(mess, "Setting high voltage failed. Invalid input %d. The range is from 0 to 200 V.\n", val);
|
||||
sprintf(mess,
|
||||
"Setting high voltage failed. Invalid input %d. The range is "
|
||||
"from 0 to 200 V.\n",
|
||||
val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ void setupFebBeb();
|
||||
int allocateDetectorStructureMemory();
|
||||
void setupDetector();
|
||||
|
||||
int resetToDefaultDacs(int hardReset, char* mess);
|
||||
int resetToDefaultDacs(int hardReset, char *mess);
|
||||
int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, int *retval);
|
||||
int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value);
|
||||
int readConfigFile();
|
||||
@@ -115,7 +115,7 @@ int64_t getMeasuredSubPeriod();
|
||||
void getModule(sls_detector_module *myMod);
|
||||
int setModule(sls_detector_module myMod, char *mess);
|
||||
int setTrimbits(int *chanregs, char *mess);
|
||||
int setSettings(enum detectorSettings sett, char* mess);
|
||||
int setSettings(enum detectorSettings sett, char *mess);
|
||||
enum detectorSettings getSettings();
|
||||
|
||||
// parameters - threshold
|
||||
@@ -123,13 +123,13 @@ int getThresholdEnergy();
|
||||
int setThresholdEnergy(int ev);
|
||||
|
||||
// parameters - dac, adc, hv
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess);
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess);
|
||||
|
||||
int getADC(enum ADCINDEX ind);
|
||||
int setHighVoltage(int val, char* mess);
|
||||
int getHighVoltage(int* retval, char* mess);
|
||||
int setHighVoltage(int val, char *mess);
|
||||
int getHighVoltage(int *retval, char *mess);
|
||||
|
||||
// parameters - timing, extsig
|
||||
int setMaster(enum MASTERINDEX m);
|
||||
|
||||
@@ -560,7 +560,7 @@ void setASICDefaults() {
|
||||
LOG(logINFO, ("Setting ASIC Defaults (0x%x)\n", bus_r(addr)));
|
||||
}
|
||||
|
||||
int resetToDefaultDacs(int hardReset, char* mess) {
|
||||
int resetToDefaultDacs(int hardReset, char *mess) {
|
||||
// reset defaults to hardcoded defaults
|
||||
if (hardReset) {
|
||||
for (int i = 0; i < NDAC; ++i) {
|
||||
@@ -583,10 +583,11 @@ int resetToDefaultDacs(int hardReset, char* mess) {
|
||||
defaultOnChipdacValues[idac][ichip]);
|
||||
if (onChipdacValues[idac][ichip] !=
|
||||
defaultOnChipdacValues[idac][ichip]) {
|
||||
sprintf(mess, "Setting on-chip dac %d (ichip:%d) failed, "
|
||||
"wrote %d, read %d\n",
|
||||
idac, ichip, defaultOnChipdacValues[idac][ichip],
|
||||
onChipdacValues[idac][ichip]);
|
||||
sprintf(mess,
|
||||
"Setting on-chip dac %d (ichip:%d) failed, "
|
||||
"wrote %d, read %d\n",
|
||||
idac, ichip, defaultOnChipdacValues[idac][ichip],
|
||||
onChipdacValues[idac][ichip]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -947,7 +948,8 @@ int readConfigFile() {
|
||||
hardCodedDefaultDacValues[idac] = value;
|
||||
|
||||
// set dac
|
||||
if (setDAC(idac, value, 0, initErrorMessage) == FAIL) {;
|
||||
if (setDAC(idac, value, 0, initErrorMessage) == FAIL) {
|
||||
;
|
||||
sprintf(initErrorMessage,
|
||||
"Set dac %s failed from on-board server config file. "
|
||||
"Could not set %d.\n",
|
||||
@@ -1394,7 +1396,7 @@ int64_t getMeasurementTime() {
|
||||
}
|
||||
|
||||
/* parameters - module, settings */
|
||||
int setSettings(enum detectorSettings sett, char* mess) {
|
||||
int setSettings(enum detectorSettings sett, char *mess) {
|
||||
if (sett == UNINITIALIZED) {
|
||||
sprintf(mess, "Cannot set settings to uninitialized\n");
|
||||
LOG(logERROR, (mess));
|
||||
@@ -1518,7 +1520,7 @@ int getOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex) {
|
||||
// specific chip
|
||||
return onChipdacValues[ind][chipIndex];
|
||||
}
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
|
||||
// validate index
|
||||
@@ -1529,70 +1531,81 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
}
|
||||
// validate min value
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d cannot be negative\n", dacNames[ind], val);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d cannot be negative\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate max value
|
||||
if (mV && val > DAC_MAX_MV) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d exceed maximum %d mV\n", dacNames[ind], val, DAC_MAX_MV);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d mV\n",
|
||||
dacNames[ind], val, DAC_MAX_MV);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
else if (!mV && val > LTC2620_D_GetMaxInput()) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d exceed maximum %d \n", dacNames[ind], val, LTC2620_D_GetMaxInput());
|
||||
} else if (!mV && val > LTC2620_D_GetMaxInput()) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d \n",
|
||||
dacNames[ind], val, LTC2620_D_GetMaxInput());
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
if (validateDAC(ind, val, mV, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val, (mV ? "mV" : "dac units")));
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val,
|
||||
(mV ? "mV" : "dac units")));
|
||||
|
||||
// mV: convert to dac value
|
||||
int dacval = val;
|
||||
if (mV) {
|
||||
if (LTC2620_D_VoltageToDac(val, &dacval) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %s. Could not convert %d mV to dac units.\n", dacNames[ind], val);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (LTC2620_D_SetDACValue((int)ind, val) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %s.\n", dacNames[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
dacValues[ind] = dacval;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
if (!mV) {
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac\n", dacNames[ind], dacValues[ind]));
|
||||
LOG(logDEBUG1,
|
||||
("Getting DAC %s : %d dac\n", dacNames[ind], dacValues[ind]));
|
||||
*retval = dacValues[ind];
|
||||
return OK;
|
||||
}
|
||||
// convert to mV
|
||||
*retval = -1;
|
||||
if (LTC2620_D_DacToVoltage(dacValues[ind], retval) == FAIL) {
|
||||
sprintf(mess, "Could not get DAC %s. Could not convert %d dac units to mV\n", dacNames[ind], dacValues[ind]);
|
||||
sprintf(mess,
|
||||
"Could not get DAC %s. Could not convert %d dac units to mV\n",
|
||||
dacNames[ind], dacValues[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logDEBUG1,
|
||||
("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind], dacValues[ind], *retval));
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind],
|
||||
dacValues[ind], *retval));
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int getADC(enum ADCINDEX ind, int *value) {
|
||||
LOG(logDEBUG1, ("Reading FPGA temperature...\n"));
|
||||
if (readParameterFromFile(TEMPERATURE_FILE_NAME, "temperature", value) ==
|
||||
@@ -1604,12 +1617,12 @@ int getADC(enum ADCINDEX ind, int *value) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setHighVoltage(int val, char* mess) {
|
||||
int setHighVoltage(int val, char *mess) {
|
||||
// validate input value
|
||||
if (val < 0 || val > HV_SOFT_MAX_VOLTAGE) {
|
||||
sprintf(mess, "Invalid Voltage. Valid range (0 - %d)\n",
|
||||
HV_SOFT_MAX_VOLTAGE);
|
||||
LOG(logERROR, (mess));
|
||||
HV_SOFT_MAX_VOLTAGE);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
@@ -1629,10 +1642,9 @@ int setHighVoltage(int val, char* mess) {
|
||||
}
|
||||
}
|
||||
|
||||
if (DAC6571_Set(val, mess) == FAIL)
|
||||
if (DAC6571_Set(val, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
|
||||
// only when powering off (from non zero value), wait 10s
|
||||
if (prevHighVoltage > 0 && val == 0) {
|
||||
LOG(logINFO,
|
||||
@@ -1646,7 +1658,8 @@ int setHighVoltage(int val, char* mess) {
|
||||
if (getHighVoltage(&retval, mess) == FAIL)
|
||||
return FAIL;
|
||||
if (val != retval) {
|
||||
sprintf(mess, "Could not set high voltage. Set %d, but got %d\n", val, retval);
|
||||
sprintf(mess, "Could not set high voltage. Set %d, but got %d\n", val,
|
||||
retval);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1654,8 +1667,8 @@ int setHighVoltage(int val, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getHighVoltage(int *retval, char* mess) {
|
||||
int ret = DAC6571_Get(retval, mess);
|
||||
int getHighVoltage(int *retval, char *mess) {
|
||||
int ret = DAC6571_Get(retval, mess);
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", retval));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ void initStopServer();
|
||||
|
||||
// set up detector
|
||||
void setupDetector();
|
||||
int resetToDefaultDacs(int hardReset, char* mess);
|
||||
int resetToDefaultDacs(int hardReset, char *mess);
|
||||
int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, int *retval);
|
||||
int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value);
|
||||
void setASICDefaults();
|
||||
@@ -109,21 +109,20 @@ int64_t getActualTime();
|
||||
int64_t getMeasurementTime();
|
||||
|
||||
// parameters - module, settings
|
||||
int setSettings(enum detectorSettings sett, char* mess);
|
||||
int setSettings(enum detectorSettings sett, char *mess);
|
||||
enum detectorSettings getSettings();
|
||||
|
||||
// parameters - dac, adc, hv
|
||||
int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val);
|
||||
int getOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex);
|
||||
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess);
|
||||
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess);
|
||||
|
||||
int getADC(enum ADCINDEX ind, int *value);
|
||||
int setHighVoltage(int val, char* mess);
|
||||
int getHighVoltage(int *retval, char* mess);
|
||||
int setHighVoltage(int val, char *mess);
|
||||
int getHighVoltage(int *retval, char *mess);
|
||||
|
||||
// parameters - timing, extsig
|
||||
int setMaster(enum MASTERINDEX m);
|
||||
|
||||
@@ -583,7 +583,7 @@ void setupDetector() {
|
||||
setElectronCollectionMode(DEFAULT_ELECTRON_COLLECTION_MODE);
|
||||
}
|
||||
|
||||
int resetToDefaultDacs(int hardReset, char* mess) {
|
||||
int resetToDefaultDacs(int hardReset, char *mess) {
|
||||
LOG(logINFOBLUE, ("Resetting %s to Default Dac values\n",
|
||||
(hardReset == 1 ? "hard" : "")));
|
||||
|
||||
@@ -629,7 +629,7 @@ int resetToDefaultDacs(int hardReset, char* mess) {
|
||||
}
|
||||
|
||||
// set to default
|
||||
if (setDAC((enum DACINDEX)i, value, 0, mess) == FAIL)
|
||||
if (setDAC((enum DACINDEX)i, value, 0, mess) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
@@ -1192,7 +1192,7 @@ int setModule(sls_detector_module myMod, char *mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setSettings(enum detectorSettings sett, char* mess) {
|
||||
int setSettings(enum detectorSettings sett, char *mess) {
|
||||
if (sett == UNINITIALIZED) {
|
||||
sprintf(mess, "Cannot set settings to uninitialized\n");
|
||||
LOG(logERROR, (mess));
|
||||
@@ -1336,7 +1336,7 @@ void setGainMode(enum gainMode mode) {
|
||||
}
|
||||
|
||||
/* parameters - dac, adc, hv */
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
|
||||
// validate index
|
||||
@@ -1347,42 +1347,54 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
}
|
||||
// validate mV
|
||||
if (mV && val == LTC2620_GetPowerDownValue()) {
|
||||
sprintf(mess, "Could not set DAC %s. Cannot use power down value and use 'mV'\n", dacNames[ind]);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %s. Cannot use power down value and use 'mV'\n",
|
||||
dacNames[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate min value
|
||||
if (val < 0 && val != LTC2620_GetPowerDownValue()) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d cannot be negative\n", dacNames[ind], val);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d cannot be negative\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate max value
|
||||
if (mV && val > DAC_MAX_MV) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d exceed maximum %d mV\n", dacNames[ind], val, DAC_MAX_MV);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d mV\n",
|
||||
dacNames[ind], val, DAC_MAX_MV);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
else if (!mV && val > LTC2620_GetMaxInput()) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d exceed maximum %d \n", dacNames[ind], val, LTC2620_GetMaxInput());
|
||||
} else if (!mV && val > LTC2620_GetMaxInput()) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d \n",
|
||||
dacNames[ind], val, LTC2620_GetMaxInput());
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
if (validateDAC(ind, val, mV, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val, (mV ? "mV" : "dac units")));
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val,
|
||||
(mV ? "mV" : "dac units")));
|
||||
|
||||
// mV: convert to dac value
|
||||
int dacval = val;
|
||||
if (mV) {
|
||||
if (LTC2620_VoltageToDac(val, &dacval) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %s. Could not convert %d mV to dac units.\n", dacNames[ind], val);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1393,7 +1405,7 @@ int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
dacValues[ind] = dacval;
|
||||
|
||||
if (ind == J_VREF_COMP) {
|
||||
@@ -1401,12 +1413,13 @@ int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
if (val == LTC2620_GetPowerDownValue())
|
||||
val = 0;
|
||||
bus_w(addr, (bus_r(addr) & ~(EXT_DAQ_CTRL_VREF_COMP_MSK)));
|
||||
bus_w(addr, (bus_r(addr) | ((val << EXT_DAQ_CTRL_VREF_COMP_OFST) & EXT_DAQ_CTRL_VREF_COMP_MSK)));
|
||||
bus_w(addr, (bus_r(addr) | ((val << EXT_DAQ_CTRL_VREF_COMP_OFST) &
|
||||
EXT_DAQ_CTRL_VREF_COMP_MSK)));
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
|
||||
// validate index
|
||||
if (ind < 0 || ind >= NDAC) {
|
||||
sprintf(mess, "Could not get DAC %d. Invalid index.\n", ind);
|
||||
@@ -1415,19 +1428,22 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
}
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
if (!mV) {
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac\n", dacNames[ind], dacValues[ind]));
|
||||
LOG(logDEBUG1,
|
||||
("Getting DAC %s : %d dac\n", dacNames[ind], dacValues[ind]));
|
||||
*retval = dacValues[ind];
|
||||
return OK;
|
||||
}
|
||||
// convert to mV
|
||||
*retval = -1;
|
||||
if (LTC2620_DacToVoltage(dacValues[ind], retval) == FAIL) {
|
||||
sprintf(mess, "Could not get DAC %s. Could not convert %d dac units to mV\n", dacNames[ind], dacValues[ind]);
|
||||
sprintf(mess,
|
||||
"Could not get DAC %s. Could not convert %d dac units to mV\n",
|
||||
dacNames[ind], dacValues[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logDEBUG1,
|
||||
("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind], dacValues[ind], *retval));
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind],
|
||||
dacValues[ind], *retval));
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -1457,7 +1473,7 @@ int getADC(enum ADCINDEX ind) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
int setHighVoltage(int val, char* mess) {
|
||||
int setHighVoltage(int val, char *mess) {
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set high voltage. Invalid value:%d\n", val);
|
||||
LOG(logERROR, (mess));
|
||||
@@ -1469,7 +1485,7 @@ int setHighVoltage(int val, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getHighVoltage(int *retval, char* mess) {
|
||||
int getHighVoltage(int *retval, char *mess) {
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", retval));
|
||||
return highvoltage;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ void initStopServer();
|
||||
|
||||
// set up detector
|
||||
void setupDetector();
|
||||
int resetToDefaultDacs(int hardReset, char* mess);
|
||||
int resetToDefaultDacs(int hardReset, char *mess);
|
||||
int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, int *retval);
|
||||
int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value);
|
||||
int readConfigFile();
|
||||
@@ -116,19 +116,19 @@ int64_t getMeasurementTime();
|
||||
|
||||
// parameters - module, settings
|
||||
int setModule(sls_detector_module myMod, char *mess);
|
||||
int setSettings(enum detectorSettings sett, char* mess);
|
||||
int setSettings(enum detectorSettings sett, char *mess);
|
||||
enum detectorSettings getSettings();
|
||||
enum gainMode getGainMode();
|
||||
void setGainMode(enum gainMode mode);
|
||||
|
||||
// parameters - dac, adc, hv
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess);
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess);
|
||||
|
||||
int getADC(enum ADCINDEX ind);
|
||||
int setHighVoltage(int val, char* mess);
|
||||
int getHighVoltage(int *retval, char* mess);
|
||||
int setHighVoltage(int val, char *mess);
|
||||
int getHighVoltage(int *retval, char *mess);
|
||||
|
||||
// parameters - timing, extsig
|
||||
int setMaster(enum MASTERINDEX m);
|
||||
|
||||
@@ -524,7 +524,7 @@ void setupDetector() {
|
||||
setParallelMode(DEFAULT_PARALLEL_ENABLE);
|
||||
}
|
||||
|
||||
int resetToDefaultDacs(int hardReset, char* mess) {
|
||||
int resetToDefaultDacs(int hardReset, char *mess) {
|
||||
LOG(logINFOBLUE, ("Resetting %s to Default Dac values\n",
|
||||
(hardReset == 1 ? "hard" : "")));
|
||||
|
||||
@@ -820,7 +820,7 @@ int setModule(sls_detector_module myMod, char *mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setSettings(enum detectorSettings sett, char* mess) {
|
||||
int setSettings(enum detectorSettings sett, char *mess) {
|
||||
if (sett == UNINITIALIZED) {
|
||||
sprintf(mess, "Cannot set settings to uninitialized\n");
|
||||
LOG(logERROR, (mess));
|
||||
@@ -911,7 +911,7 @@ enum detectorSettings getSettings() {
|
||||
}
|
||||
|
||||
/* parameters - dac, adc, hv */
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
|
||||
// validate index
|
||||
@@ -922,42 +922,54 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
}
|
||||
// validate mV
|
||||
if (mV && val == LTC2620_GetPowerDownValue()) {
|
||||
sprintf(mess, "Could not set DAC %s. Cannot use power down value and use 'mV'\n", dacNames[ind]);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %s. Cannot use power down value and use 'mV'\n",
|
||||
dacNames[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate min value
|
||||
if (val < 0 && val != LTC2620_GetPowerDownValue()) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d cannot be negative\n", dacNames[ind], val);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d cannot be negative\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate max value
|
||||
if (mV && val > DAC_MAX_MV) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d exceed maximum %d mV\n", dacNames[ind], val, DAC_MAX_MV);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d mV\n",
|
||||
dacNames[ind], val, DAC_MAX_MV);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
else if (!mV && val > LTC2620_GetMaxInput()) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d exceed maximum %d \n", dacNames[ind], val, LTC2620_GetMaxInput());
|
||||
} else if (!mV && val > LTC2620_GetMaxInput()) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d \n",
|
||||
dacNames[ind], val, LTC2620_GetMaxInput());
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
if (validateDAC(ind, val, mV, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val, (mV ? "mV" : "dac units")));
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val,
|
||||
(mV ? "mV" : "dac units")));
|
||||
|
||||
// mV: convert to dac value
|
||||
int dacval = val;
|
||||
if (mV) {
|
||||
if (LTC2620_VoltageToDac(val, &dacval) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %s. Could not convert %d mV to dac units.\n", dacNames[ind], val);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -968,12 +980,12 @@ int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
dacValues[ind] = dacval;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
|
||||
// validate index
|
||||
if (ind < 0 || ind >= NDAC) {
|
||||
sprintf(mess, "Could not get DAC %d. Invalid index.\n", ind);
|
||||
@@ -982,23 +994,25 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
}
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
if (!mV) {
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac\n", dacNames[ind], dacValues[ind]));
|
||||
LOG(logDEBUG1,
|
||||
("Getting DAC %s : %d dac\n", dacNames[ind], dacValues[ind]));
|
||||
*retval = dacValues[ind];
|
||||
return OK;
|
||||
}
|
||||
// convert to mV
|
||||
*retval = -1;
|
||||
if (LTC2620_DacToVoltage(dacValues[ind], retval) == FAIL) {
|
||||
sprintf(mess, "Could not get DAC %s. Could not convert %d dac units to mV\n", dacNames[ind], dacValues[ind]);
|
||||
sprintf(mess,
|
||||
"Could not get DAC %s. Could not convert %d dac units to mV\n",
|
||||
dacNames[ind], dacValues[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logDEBUG1,
|
||||
("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind], dacValues[ind], *retval));
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind],
|
||||
dacValues[ind], *retval));
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int getADC(enum ADCINDEX ind) {
|
||||
#ifdef VIRTUAL
|
||||
return 0;
|
||||
@@ -1025,7 +1039,7 @@ int getADC(enum ADCINDEX ind) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
int setHighVoltage(int val, char* mess) {
|
||||
int setHighVoltage(int val, char *mess) {
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set high voltage. Invalid value:%d\n", val);
|
||||
LOG(logERROR, (mess));
|
||||
@@ -1037,12 +1051,11 @@ int setHighVoltage(int val, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getHighVoltage(int *retval, char* mess) {
|
||||
int getHighVoltage(int *retval, char *mess) {
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", retval));
|
||||
return highvoltage;
|
||||
}
|
||||
|
||||
|
||||
/* parameters - timing, extsig */
|
||||
|
||||
int setMaster(enum MASTERINDEX m) {
|
||||
|
||||
@@ -69,7 +69,7 @@ void initStopServer();
|
||||
|
||||
// set up detector
|
||||
void setupDetector();
|
||||
int resetToDefaultDacs(int hardReset, char* mess);
|
||||
int resetToDefaultDacs(int hardReset, char *mess);
|
||||
int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, int *retval);
|
||||
int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value);
|
||||
|
||||
@@ -111,16 +111,16 @@ int64_t getMeasurementTime();
|
||||
|
||||
// parameters - module, settings
|
||||
int setModule(sls_detector_module myMod, char *mess);
|
||||
int setSettings(enum detectorSettings sett, char* mess);
|
||||
int setSettings(enum detectorSettings sett, char *mess);
|
||||
enum detectorSettings getSettings();
|
||||
|
||||
// parameters - dac, adc, hv
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess);
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess);
|
||||
int getADC(enum ADCINDEX ind);
|
||||
int setHighVoltage(int val, char* mess);
|
||||
int getHighVoltage(int *retval, char* mess);
|
||||
int setHighVoltage(int val, char *mess);
|
||||
int getHighVoltage(int *retval, char *mess);
|
||||
|
||||
// parameters - timing, extsig
|
||||
int setMaster(enum MASTERINDEX m);
|
||||
|
||||
@@ -556,7 +556,7 @@ void setupDetector() {
|
||||
setReadoutSpeed(DEFAULT_READOUT_SPEED);
|
||||
}
|
||||
|
||||
int resetToDefaultDacs(int hardReset, char* mess) {
|
||||
int resetToDefaultDacs(int hardReset, char *mess) {
|
||||
LOG(logINFOBLUE, ("Resetting %s to Default Dac values\n",
|
||||
(hardReset == 1 ? "hard" : "")));
|
||||
|
||||
@@ -1322,7 +1322,7 @@ int setModule(sls_detector_module myMod, char *mess) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// update vth and countermask
|
||||
updateVthAndCounterMask();
|
||||
|
||||
@@ -1444,7 +1444,7 @@ int getAllTrimbits() {
|
||||
return value;
|
||||
}
|
||||
|
||||
int setSettings(enum detectorSettings sett, char* mess) {
|
||||
int setSettings(enum detectorSettings sett, char *mess) {
|
||||
int *dacVals = NULL;
|
||||
switch (sett) {
|
||||
case STANDARD:
|
||||
@@ -1497,7 +1497,7 @@ void validateSettings() {
|
||||
// if one value does not match, = undefined
|
||||
for (int i = 0; i < NSPECIALDACS; ++i) {
|
||||
int retval = 0;
|
||||
char emsg[MAX_STR_LENGTH]= {0};
|
||||
char emsg[MAX_STR_LENGTH] = {0};
|
||||
if (getDAC(specialDacs[i], 0, &retval, emsg) == FAIL) {
|
||||
sett = UNDEFINED;
|
||||
break;
|
||||
@@ -1538,7 +1538,7 @@ void setThresholdEnergy(int counterIndex, int eV) {
|
||||
}
|
||||
|
||||
/* parameters - dac, hv */
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
|
||||
// validate index (threshold included)
|
||||
@@ -1549,18 +1549,23 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
}
|
||||
// validate min value
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d cannot be negative\n", dacNames[ind], val);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d cannot be negative\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// validate max value
|
||||
if (mV && val > DAC_MAX_MV) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d exceed maximum %d mV\n", dacNames[ind], val, DAC_MAX_MV);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d mV\n",
|
||||
dacNames[ind], val, DAC_MAX_MV);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
else if (!mV && val > LTC2620_D_GetMaxInput()) {
|
||||
sprintf(mess, "Could not set DAC %s. Input value %d exceed maximum %d \n", dacNames[ind], val, LTC2620_D_GetMaxInput());
|
||||
} else if (!mV && val > LTC2620_D_GetMaxInput()) {
|
||||
sprintf(mess,
|
||||
"Could not set DAC %s. Input value %d exceed maximum %d \n",
|
||||
dacNames[ind], val, LTC2620_D_GetMaxInput());
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1568,25 +1573,28 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
}
|
||||
|
||||
// counterEnableCheck false only if setDAC called directly
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, int counterEnableCheck, char* mess) {
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, int counterEnableCheck,
|
||||
char *mess) {
|
||||
if (validateDAC(ind, val, mV, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val, (mV ? "mV" : "dac units")));
|
||||
LOG(logINFO, ("Setting DAC %s: %d %s \n", dacNames[ind], val,
|
||||
(mV ? "mV" : "dac units")));
|
||||
|
||||
// threshold dacs:
|
||||
// - remember dac value if not disabled value
|
||||
// - if counter disabled, set disabled val
|
||||
// - if counter disabled, set disabled val
|
||||
// (except when set direcly from client)
|
||||
//
|
||||
// vthreshold:
|
||||
// vthreshold:
|
||||
// - remember dac value for every counter
|
||||
//
|
||||
// others: set dac as normal
|
||||
|
||||
// only for threshold dacs or vthreshold
|
||||
if (ind == M_VTHRESHOLD || ind == M_VTH1 || ind == M_VTH2 || ind == M_VTH3) {
|
||||
if (ind == M_VTHRESHOLD || ind == M_VTH1 || ind == M_VTH2 ||
|
||||
ind == M_VTH3) {
|
||||
uint32_t counters = getCounterMask();
|
||||
int vthdacs[] = {M_VTH1, M_VTH2, M_VTH3};
|
||||
|
||||
@@ -1603,14 +1611,18 @@ int setDAC(enum DACINDEX ind, int val, int mV, int counterEnableCheck, char* mes
|
||||
// convert to dac units
|
||||
if (mV) {
|
||||
if (LTC2620_D_VoltageToDac(val, &dacval) == FAIL) {
|
||||
sprintf(mess, "Could not set %s. Could not convert input %d mV to dac\n", dacNames[ind], val);
|
||||
sprintf(mess,
|
||||
"Could not set %s. Could not convert "
|
||||
"input %d mV to dac\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
// remember value
|
||||
vthEnabledVals[i] = dacval;
|
||||
LOG(logINFO, ("Remembering %s [%d]\n", dacNames[ind], dacval));
|
||||
LOG(logINFO,
|
||||
("Remembering %s [%d]\n", dacNames[ind], dacval));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1635,21 +1647,25 @@ int setDAC(enum DACINDEX ind, int val, int mV, int counterEnableCheck, char* mes
|
||||
return setGeneralDAC(ind, val, mV, mess);
|
||||
}
|
||||
|
||||
int setGeneralDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int setGeneralDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
|
||||
LOG(logDEBUG1, ("Setting General DAC %s: %d %s \n", dacNames[ind], val, (mV ? "mV" : "dac units")));
|
||||
LOG(logDEBUG1, ("Setting General DAC %s: %d %s \n", dacNames[ind], val,
|
||||
(mV ? "mV" : "dac units")));
|
||||
|
||||
// mV: convert to dac value
|
||||
int dacval = val;
|
||||
if (mV) {
|
||||
if (LTC2620_D_VoltageToDac(val, &dacval) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %s. Could not convert %d mV to dac units.\n", dacNames[ind], val);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %s. Could not convert %d mV to dac units.\n",
|
||||
dacNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (LTC2620_D_SetDACValue((int)ind, val) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %s.\n", dacNames[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
@@ -1676,11 +1692,11 @@ void setVthDac(int index, int enable) {
|
||||
if (enable) {
|
||||
value = vthEnabledVals[index];
|
||||
}
|
||||
char msg[MAX_STR_LENGTH]= {0};
|
||||
char msg[MAX_STR_LENGTH] = {0};
|
||||
setGeneralDAC(vthdacs[index], value, 0, msg);
|
||||
}
|
||||
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
|
||||
|
||||
// vthreshold
|
||||
if (ind == M_VTHRESHOLD) {
|
||||
@@ -1699,7 +1715,8 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
}
|
||||
// different values for enabled counters
|
||||
else if (retval1 != *retval) {
|
||||
sprintf(mess, "Could not get vthrehsold DAC. Different values for enabled counters.\n");
|
||||
sprintf(mess, "Could not get vthrehsold DAC. Different "
|
||||
"values for enabled counters.\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1711,23 +1728,25 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
|
||||
char *dacNames[] = {DAC_NAMES};
|
||||
if (!mV) {
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac\n", dacNames[ind], detectorDacs[ind]));
|
||||
LOG(logDEBUG1,
|
||||
("Getting DAC %s : %d dac\n", dacNames[ind], detectorDacs[ind]));
|
||||
*retval = detectorDacs[ind];
|
||||
return OK;
|
||||
}
|
||||
// convert to mV
|
||||
*retval = -1;
|
||||
if (LTC2620_D_DacToVoltage(detectorDacs[ind], retval) == FAIL) {
|
||||
sprintf(mess, "Could not get DAC %s. Could not convert %d dac units to mV\n", dacNames[ind], detectorDacs[ind]);
|
||||
sprintf(mess,
|
||||
"Could not get DAC %s. Could not convert %d dac units to mV\n",
|
||||
dacNames[ind], detectorDacs[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logDEBUG1,
|
||||
("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind], detectorDacs[ind], *retval));
|
||||
LOG(logDEBUG1, ("Getting DAC %s : %d dac (%d mV)\n", dacNames[ind],
|
||||
detectorDacs[ind], *retval));
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int getADC(enum ADCINDEX ind, int *value) {
|
||||
LOG(logDEBUG1, ("Reading FPGA temperature...\n"));
|
||||
if (readParameterFromFile(TEMPERATURE_FILE_NAME, "temperature", value) ==
|
||||
@@ -1739,12 +1758,12 @@ int getADC(enum ADCINDEX ind, int *value) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setHighVoltage(int val, char* mess) {
|
||||
int setHighVoltage(int val, char *mess) {
|
||||
// validate input value
|
||||
if (val < 0 || val > HV_SOFT_MAX_VOLTAGE) {
|
||||
sprintf(mess, "Invalid Voltage. Valid range (0 - %d)\n",
|
||||
HV_SOFT_MAX_VOLTAGE);
|
||||
LOG(logERROR, (mess));
|
||||
HV_SOFT_MAX_VOLTAGE);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
@@ -1758,7 +1777,8 @@ int setHighVoltage(int val, char* mess) {
|
||||
if (getHighVoltage(&retval, mess) == FAIL)
|
||||
return FAIL;
|
||||
if (val != retval) {
|
||||
sprintf(mess, "Could not set high voltage. Set %d, but got %d\n", val, retval);
|
||||
sprintf(mess, "Could not set high voltage. Set %d, but got %d\n", val,
|
||||
retval);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1766,8 +1786,8 @@ int setHighVoltage(int val, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getHighVoltage(int *retval, char* mess) {
|
||||
int ret = DAC6571_Get(retval, mess);
|
||||
int getHighVoltage(int *retval, char *mess) {
|
||||
int ret = DAC6571_Get(retval, mess);
|
||||
LOG(logDEBUG1, ("High Voltage: %d\n", retval));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ void initStopServer();
|
||||
// set up detector
|
||||
int allocateDetectorStructureMemory();
|
||||
void setupDetector();
|
||||
int resetToDefaultDacs(int hardReset, char* mess);
|
||||
int resetToDefaultDacs(int hardReset, char *mess);
|
||||
int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, int *retval);
|
||||
int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value);
|
||||
void setASICDefaults();
|
||||
@@ -125,7 +125,7 @@ int setModule(sls_detector_module myMod, char *mess);
|
||||
int setTrimbits(int *trimbits);
|
||||
int setAllTrimbits(int val);
|
||||
int getAllTrimbits();
|
||||
int setSettings(enum detectorSettings sett, char* mess);
|
||||
int setSettings(enum detectorSettings sett, char *mess);
|
||||
enum detectorSettings getSettings();
|
||||
|
||||
// parameters - threshold
|
||||
@@ -133,16 +133,17 @@ int getThresholdEnergy(int counterIndex);
|
||||
void setThresholdEnergy(int counterIndex, int eV);
|
||||
|
||||
// parameters - dac, adc, hv
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, int counterEnableCheck, char* mess);
|
||||
int setGeneralDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess);
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, int counterEnableCheck,
|
||||
char *mess);
|
||||
int setGeneralDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess);
|
||||
|
||||
void setVthDac(int index, int enable);
|
||||
|
||||
int getADC(enum ADCINDEX ind, int *value);
|
||||
int setHighVoltage(int val, char* mess);
|
||||
int getHighVoltage(int *retval, char* mess);
|
||||
int setHighVoltage(int val, char *mess);
|
||||
int getHighVoltage(int *retval, char *mess);
|
||||
|
||||
// parameters - timing, extsig
|
||||
int isMaster(int *retval);
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
void DAC6571_SetDefines(int hardMaxV, char *driverfname);
|
||||
int DAC6571_Set(int val, char* mess);
|
||||
int DAC6571_Get(int *retval, char* mess);
|
||||
int DAC6571_Set(int val, char *mess);
|
||||
int DAC6571_Get(int *retval, char *mess);
|
||||
|
||||
@@ -30,9 +30,9 @@ void DAC6571_SetDefines(int hardMaxV, char *driverfname) {
|
||||
#endif
|
||||
}
|
||||
|
||||
int DAC6571_Set(int val, char* mess) {
|
||||
int DAC6571_Set(int val, char *mess) {
|
||||
LOG(logDEBUG1, ("Setting high voltage to %d\n", val));
|
||||
if (val < 0) {
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Invalid value. Cannot be negative.\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
@@ -43,7 +43,9 @@ int DAC6571_Set(int val, char* mess) {
|
||||
// convert value
|
||||
if (ConvertToDifferentRange(0, DAC6571_HardMaxVoltage, DAC6571_MIN_DAC_VAL,
|
||||
DAC6571_MAX_DAC_VAL, val, &dacvalue) == FAIL) {
|
||||
sprintf(mess, "Could not convert %d high voltage to a valid dac value\n", val);
|
||||
sprintf(mess,
|
||||
"Could not convert %d high voltage to a valid dac value\n",
|
||||
val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -55,7 +57,9 @@ int DAC6571_Set(int val, char* mess) {
|
||||
// open file
|
||||
FILE *fd = fopen(DAC6571_DriverFileName, "w");
|
||||
if (fd == NULL) {
|
||||
sprintg(mess, "Could not open file %s for writing to set high voltage\n", DAC6571_DriverFileName);
|
||||
sprintg(mess,
|
||||
"Could not open file %s for writing to set high voltage\n",
|
||||
DAC6571_DriverFileName);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -67,7 +71,7 @@ int DAC6571_Set(int val, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int DAC6571_Get(int *retval, char* mess) {
|
||||
int DAC6571_Get(int *retval, char *mess) {
|
||||
LOG(logDEBUG1, ("Getting high voltage\n"));
|
||||
int dacvalue = 0;
|
||||
|
||||
@@ -86,7 +90,9 @@ int DAC6571_Get(int *retval, char* mess) {
|
||||
if (ConvertToDifferentRange(DAC6571_MIN_DAC_VAL, DAC6571_MAX_DAC_VAL, 0,
|
||||
DAC6571_HardMaxVoltage, dacvalue,
|
||||
retval) == FAIL) {
|
||||
sprintf(mess, "Could not convert %d dac value to a valid high voltage\n", dacvalue);
|
||||
sprintf(mess,
|
||||
"Could not convert %d dac value to a valid high voltage\n",
|
||||
dacvalue);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -96,7 +102,9 @@ int DAC6571_Get(int *retval, char* mess) {
|
||||
// open file
|
||||
FILE *fd = fopen(DAC6571_DriverFileName, "w");
|
||||
if (fd == NULL) {
|
||||
sprintf(mess, "Could not open file %s for writing to get high voltage\n", DAC6571_DriverFileName);
|
||||
sprintf(mess,
|
||||
"Could not open file %s for writing to get high voltage\n",
|
||||
DAC6571_DriverFileName);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
@@ -233,14 +233,15 @@ int LTC2620_SetDACValue(int dacnum, int val) {
|
||||
|
||||
// validate value
|
||||
if ((val < 0 && val != LTC2620_PWR_DOWN_VAL) || val > LTC2620_MAX_VAL) {
|
||||
LOG(logERROR, ("Could not set DAC %d. Input value %d is out of bounds (0 to %d)\n", val,
|
||||
LTC2620_MAX_VAL));
|
||||
LOG(logERROR, ("Could not set DAC %d. Input value %d is out of bounds "
|
||||
"(0 to %d)\n",
|
||||
val, LTC2620_MAX_VAL));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
LOG(logINFO,("\tSetting DAC %d: %d dac\n", dacnum, val));
|
||||
LOG(logINFO, ("\tSetting DAC %d: %d dac\n", dacnum, val));
|
||||
#ifndef VIRTUAL
|
||||
LTC2620_SetDAC(dacnum, val);
|
||||
LTC2620_SetDAC(dacnum, val);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -69,12 +69,15 @@ int LTC2620_D_SetDACValue(int dacnum, int val) {
|
||||
}
|
||||
|
||||
// validate value
|
||||
if ((val < 0 && val != LTC2620_D_PWR_DOWN_VAL) || val > LTC2620_D_MAX_DAC_VAL) {
|
||||
LOG(logERROR, ("Could not set DAC %d. Input value %d is out of bounds (0 to %d)\n", val, LTC2620_D_MAX_DAC_VAL));
|
||||
if ((val < 0 && val != LTC2620_D_PWR_DOWN_VAL) ||
|
||||
val > LTC2620_D_MAX_DAC_VAL) {
|
||||
LOG(logERROR, ("Could not set DAC %d. Input value %d is out of bounds "
|
||||
"(0 to %d)\n",
|
||||
val, LTC2620_D_MAX_DAC_VAL));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
LOG(logINFO,("\tSetting DAC %d: %d dac\n", dacnum, val));
|
||||
LOG(logINFO, ("\tSetting DAC %d: %d dac\n", dacnum, val));
|
||||
|
||||
#ifndef VIRTUAL
|
||||
return OK;
|
||||
@@ -86,7 +89,7 @@ int LTC2620_D_SetDACValue(int dacnum, int val) {
|
||||
strcpy(fnameFormat, LTC2620_D_DriverFileName);
|
||||
#if defined(XILINX_CHIPTESTBOARDD)
|
||||
if (val == LTC2620_D_PWR_DOWN_VAL) {
|
||||
LOG(logINFO, ("Powering down DAC %2d [%-6s] \n", dacnum, dacname));
|
||||
LOG(logINFO, ("Powering down DAC %2d\n", dacnum));
|
||||
strcpy(fnameFormat, LTC2620_D_PowerDownDriverFileName);
|
||||
}
|
||||
sprintf(fname, fnameFormat, dacnum);
|
||||
@@ -103,11 +106,11 @@ int LTC2620_D_SetDACValue(int dacnum, int val) {
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef XILINX_CHIPTESTBOARDD
|
||||
if (writeValue == LTC2620_D_PWR_DOWN_VAL)
|
||||
if (val == LTC2620_D_PWR_DOWN_VAL)
|
||||
fprintf(fd, "1\n"); //-100?:Invalid Argument
|
||||
else
|
||||
#endif
|
||||
fprintf(fd, "%d\n", val);
|
||||
fprintf(fd, "%d\n", val);
|
||||
fclose(fd);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
@@ -1158,7 +1158,6 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
||||
|
||||
switch (ind) {
|
||||
|
||||
|
||||
#ifdef EIGERD
|
||||
case IO_DELAY:
|
||||
retval = setIODelay(val);
|
||||
@@ -1167,18 +1166,17 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
||||
return retval;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(CHIPTESTBOARDD)
|
||||
case ADC_VPP:
|
||||
if (val != GET_FLAG)
|
||||
ret = setADCVpp(val, mV, mess);
|
||||
else
|
||||
ret = getADCVpp(mV, &retval, mess);
|
||||
return retval;
|
||||
return retval;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D) || defined(EIGERD) || defined(JUNGFRAUD) || defined(MOENCHD) || defined(CHIPTESTBOARDD)
|
||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D) || defined(EIGERD) || \
|
||||
defined(JUNGFRAUD) || defined(MOENCHD) || defined(CHIPTESTBOARDD)
|
||||
case HIGH_VOLTAGE:
|
||||
if (val != GET_FLAG)
|
||||
ret = setHighVoltage(val, mess);
|
||||
@@ -1187,27 +1185,28 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
||||
return retval;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CHIPTESTBOARDD
|
||||
case V_POWER_CHIP:
|
||||
if (val != GET_FLAG) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Can not set Vchip. Can only be set automatically in the background (+200mV from highest power regulator voltage).\n");
|
||||
sprintf(
|
||||
mess,
|
||||
"Can not set Vchip. Can only be set automatically in the "
|
||||
"background (+200mV from highest power regulator voltage).\n");
|
||||
LOG(logERROR, (mess));
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
ret = getVchip(&retval, mess);
|
||||
return retval;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(CHIPTESTBOARDD) || defined(XILINX_CHIPTESTBOARDD)
|
||||
case V_LIMIT:
|
||||
if (val != GET_FLAG) {
|
||||
if (!mV) {
|
||||
ret = FAIL;
|
||||
strcpy(mess, "Could not set vlimit. VLimit should be in "
|
||||
"mV and not dac units.\n");
|
||||
"mV and not dac units.\n");
|
||||
LOG(logERROR, (mess));
|
||||
return retval;
|
||||
}
|
||||
@@ -1217,10 +1216,6 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
||||
return retval;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(CHIPTESTBOARDD) || defined(XILINX_CHIPTESTBOARDD)
|
||||
case V_POWER_A:
|
||||
case V_POWER_B:
|
||||
@@ -1233,7 +1228,10 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
||||
if (val != GET_FLAG) {
|
||||
if (!mV) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set power. Power regulator %d should be in mV and not dac units.\n", ind);
|
||||
sprintf(mess,
|
||||
"Could not set power. Power regulator %d should be in "
|
||||
"mV and not dac units.\n",
|
||||
ind);
|
||||
LOG(logERROR, (mess));
|
||||
return retval;
|
||||
}
|
||||
@@ -1243,7 +1241,6 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
||||
return retval;
|
||||
#endif
|
||||
|
||||
|
||||
// actual dacs
|
||||
default:
|
||||
serverDacIndex = getDACIndex(ind);
|
||||
@@ -1278,7 +1275,7 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
||||
return retval;
|
||||
}
|
||||
LOG(logERROR, ("Settings has been changed "
|
||||
"to undefined (changed specific dacs)\n"));
|
||||
"to undefined (changed specific dacs)\n"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -1287,7 +1284,7 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
||||
#else
|
||||
ret = setDAC(serverDacIndex, val, mV, mess);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
// get
|
||||
else
|
||||
ret = getDAC(serverDacIndex, mV, &retval, mess);
|
||||
@@ -1295,7 +1292,6 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int set_dac(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
@@ -3045,7 +3041,7 @@ int validateAndSetAllTrimbits(int arg) {
|
||||
#ifdef EIGERD
|
||||
// changes settings to undefined
|
||||
if (getSettings() != UNDEFINED) {
|
||||
setSettings(UNDEFINED);
|
||||
setSettings(UNDEFINED, mess);
|
||||
LOG(logERROR,
|
||||
("Settings has been changed to undefined (change all "
|
||||
"trimbits)\n"));
|
||||
|
||||
@@ -414,7 +414,8 @@ void setupDetector() {
|
||||
// dacs only
|
||||
LOG(logINFOBLUE, ("Powering down all dacs\n"));
|
||||
for (int idac = 0; idac < NDAC_ONLY; ++idac) {
|
||||
initError = setDAC(idac, LTC2620_D_GetPowerDownValue(), 0, initErrorMessage);
|
||||
initError =
|
||||
setDAC(idac, LTC2620_D_GetPowerDownValue(), 0, initErrorMessage);
|
||||
if (initError == FAIL)
|
||||
return;
|
||||
}
|
||||
@@ -1160,7 +1161,7 @@ int64_t getMeasurementTime() {
|
||||
}
|
||||
|
||||
/* parameters - dac, adc, hv */
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
// validate index
|
||||
if (ind < 0 || ind >= NDAC) {
|
||||
sprintf(mess, "Could not set DAC %d. Invalid index.\n", ind);
|
||||
@@ -1170,13 +1171,20 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
// validate mV
|
||||
if (mV) {
|
||||
if (val == LTC2620_D_GetPowerDownValue()) {
|
||||
sprintf(mess, "Could not set DAC %d. Cannot use power down value and use 'mV'\n", ind);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %d. Cannot use power down value and use "
|
||||
"'mV'\n",
|
||||
ind);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// power regulators are converted to dacs at setPower with diff conv.
|
||||
if (ind >= NDAC_ONLY) {
|
||||
sprintf(mess, "Could not set DAC %d. Cannot convert to dac units for power regulator at this stage. Should have been earlier.\n", ind);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %d. Cannot convert to dac units for power "
|
||||
"regulator at this stage. Should have been earlier.\n",
|
||||
ind);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1191,13 +1199,16 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
// validate max value
|
||||
if (val != LTC2620_D_GetPowerDownValue()) {
|
||||
if (!mV) {
|
||||
// dacs and power regs
|
||||
if (val > LTC2620_D_GetMaxInput()) {
|
||||
sprintf(mess, "Could not set DAC %d. Input %d exceeds max dac value %d\n", ind, val, LTC2620_D_GetMaxInput());
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %d. Input %d exceeds max dac value %d\n",
|
||||
ind, val, LTC2620_D_GetMaxInput());
|
||||
LOG(logERROR, (mess))
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1205,26 +1216,38 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
if (vLimit > 0 && ind < NDAC_ONLY) {
|
||||
int dacmV = 0;
|
||||
if (LTC2620_D_DacToVoltage(val, &dacmV) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %d. Could not convert input %d to mV\n", ind, val);
|
||||
log(logERROR, (mess));
|
||||
sprintf(mess,
|
||||
"Could not set DAC %d. Could not convert input %d "
|
||||
"to mV\n",
|
||||
(int)ind, val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
if (dacmV > vLimit) {
|
||||
sprintf(mess, "Could not set DAC %d. Input %d (%d mV) exceeds vLimit value %d\n", ind, val, dacmV, vLimit);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %d. Input %d (%d mV) exceeds "
|
||||
"vLimit value %d\n",
|
||||
ind, val, dacmV, vLimit);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// only dacs in mV here
|
||||
else {
|
||||
if (val > DAC_MAX_MV) {
|
||||
sprintf("Could not set DAC %d. Input %d mV exceeds max dac value %d mV\n", ind, val, DAC_MAX_MV);
|
||||
sprintf(mess,
|
||||
"Could not set DAC %d. Input %d mV exceeds max dac "
|
||||
"value %d mV\n",
|
||||
(int)ind, val, DAC_MAX_MV);
|
||||
LOG(logERROR, (mess))
|
||||
return FAIL;
|
||||
}
|
||||
if (vLimit > 0 && val > vLimit) {
|
||||
sprintf("Could not set DAC %d. Input %d mV exceeds vLimit %d mV\n", ind, val, vLimit);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %d. Input %d mV exceeds vLimit %d mV\n",
|
||||
ind, val, vLimit);
|
||||
LOG(logERROR, (mess))
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1233,17 +1256,21 @@ int validateDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess) {
|
||||
if (validateDAC(ind, val, mV, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
LOG(logINFO, ("Setting dac[%d]: %d %s \n", (int)ind, val, (mV ? "mV" : "dac units")));
|
||||
LOG(logINFO, ("Setting dac[%d]: %d %s \n", (int)ind, val,
|
||||
(mV ? "mV" : "dac units")));
|
||||
|
||||
// dacs only, mV, convert to dac value
|
||||
int dacval = val;
|
||||
if (mV && ind < NDAC_ONLY) {
|
||||
if (LTC2620_D_VoltageToDac(val, &dacval) == FAIL) {
|
||||
sprintf(mess, "Could not set DAC %d. Could not convert %d mV to dac units.\n", ind, val);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set DAC %d. Could not convert %d mV to dac units.\n",
|
||||
ind, val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1254,12 +1281,12 @@ int setDAC(enum DACINDEX ind, int val, int mV, char* mess) {
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
dacValues[ind] = dacval;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess) {
|
||||
// validate index
|
||||
if (ind < 0 || ind > NDAC) {
|
||||
sprintf(mess, "Could not get DAC %d. Invalid index.\n", ind);
|
||||
@@ -1268,7 +1295,10 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
}
|
||||
// validate mV
|
||||
if (mV && ind >= NDAC_ONLY) {
|
||||
sprintf(mess, "Could not get DAC %d. Cannot convert to dac units for power regulator at this stage. Should have been earlier.\n");
|
||||
sprintf(mess,
|
||||
"Could not get DAC %d. Cannot convert to dac units for power "
|
||||
"regulator at this stage. Should have been earlier.\n",
|
||||
ind);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1281,7 +1311,9 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
// convert to mV
|
||||
*retval = -1;
|
||||
if (LTC2620_D_DacToVoltage(dacValues[ind], retval) == FAIL) {
|
||||
sprintf(mess, "Could not get DAC %d. Could not convert %d dac units to mV\n", ind, dacValues[ind]);
|
||||
sprintf(mess,
|
||||
"Could not get DAC %d. Could not convert %d dac units to mV\n",
|
||||
ind, dacValues[ind]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1292,16 +1324,17 @@ int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess) {
|
||||
|
||||
int getVLimit() { return vLimit; }
|
||||
|
||||
int setVLimit(int val, char* mess) {
|
||||
int setVLimit(int val, char *mess) {
|
||||
if (val < 0) {
|
||||
sprintf(mess, "Could not set vlimit. Invalid value %d\n", val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
vLimit = val;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int isPowerValid(enum PWRINDEX ind, int val, char* mess) {
|
||||
int isPowerValid(enum PWRINDEX ind, int val, char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
|
||||
int min = (ind == PWR_IO) ? VIO_MIN_MV : POWER_RGLTR_MIN;
|
||||
@@ -1309,16 +1342,19 @@ int isPowerValid(enum PWRINDEX ind, int val, char* mess) {
|
||||
// also checking vlimit if set
|
||||
if (vLimit > 0 && vLimit < max)
|
||||
max = vLimit;
|
||||
|
||||
|
||||
if (val != 0 && (val < min || val > max)) {
|
||||
sprintf(mess, "Could not set %s. Invalid value. Must be between %d and %d mV\n", powerNames[ind], min, max);
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set %s. Invalid value. Must be between %d and %d mV\n",
|
||||
powerNames[ind], min, max);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getPowerRailMask(enum PWRINDEX ind, uint32_t* mask, char* mess) {
|
||||
int getPowerRailMask(enum PWRINDEX ind, uint32_t *mask, char *mess) {
|
||||
mask = 0;
|
||||
switch (ind) {
|
||||
case PWR_IO:
|
||||
@@ -1344,8 +1380,7 @@ int getPowerRailMask(enum PWRINDEX ind, uint32_t* mask, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int EnablePowerRail(enum PWRINDEX ind, char* mess) {
|
||||
int EnablePowerRail(enum PWRINDEX ind, char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
uint32_t addr = CTRL_REG;
|
||||
uint32_t mask = 0;
|
||||
@@ -1358,7 +1393,7 @@ int EnablePowerRail(enum PWRINDEX ind, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int DisablePowerRail(enum PWRINDEX ind, char* mess) {
|
||||
int DisablePowerRail(enum PWRINDEX ind, char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
uint32_t addr = CTRL_REG;
|
||||
uint32_t mask = 0;
|
||||
@@ -1371,7 +1406,7 @@ int DisablePowerRail(enum PWRINDEX ind, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getPowerRail(enum PWRINDEX ind, int* retval, char* mess) {
|
||||
int getPowerRail(enum PWRINDEX ind, int *retval, char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
uint32_t addr = CTRL_REG;
|
||||
uint32_t mask = 0;
|
||||
@@ -1380,13 +1415,14 @@ int getPowerRail(enum PWRINDEX ind, int* retval, char* mess) {
|
||||
return FAIL;
|
||||
|
||||
*retval = (bus_r(addr) & mask);
|
||||
LOG(logDEBUG1, ("Power rail retval for %s: %s\n", powerNames[ind], ((*retval > 0) ? "Enabled" : "Disabled")));
|
||||
LOG(logDEBUG1, ("Power rail retval for %s: %s\n", powerNames[ind],
|
||||
((*retval > 0) ? "Enabled" : "Disabled")));
|
||||
|
||||
return OK;
|
||||
return OK;
|
||||
}
|
||||
|
||||
// for power rail index and name debugging
|
||||
int getPowerIndex(enum DACINDEX ind, enum PWRINDEX* pwrIndex, char* mess) {
|
||||
int getPowerIndex(enum DACINDEX ind, enum PWRINDEX *pwrIndex, char *mess) {
|
||||
pwrIndex = 0;
|
||||
switch (ind) {
|
||||
case D_PWR_IO:
|
||||
@@ -1412,11 +1448,58 @@ int getPowerIndex(enum DACINDEX ind, enum PWRINDEX* pwrIndex, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getPower(enum DACINDEX ind, int* retval, char* mess) {
|
||||
enum PWRINDEX pwrIndex = 0;
|
||||
int convertPowerRegDACtoVoltage(enum PWRINDEX ind, int val, int *retval,
|
||||
char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
if (ConvertToDifferentRange(LTC2620_D_GetMaxInput(),
|
||||
LTC2620_D_GetMinInput(), POWER_RGLTR_MIN,
|
||||
POWER_RGLTR_MAX, val, retval) == FAIL) {
|
||||
sprintf(mess, "Could not get %s. Could not convert %d dac to mV\n",
|
||||
powerNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int convertPowerRegVoltagetoDAC(enum PWRINDEX ind, int val, int *retval,
|
||||
char *mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
if (ConvertToDifferentRange(POWER_RGLTR_MIN, POWER_RGLTR_MAX,
|
||||
LTC2620_D_GetMaxInput(),
|
||||
LTC2620_D_GetMinInput(), val, retval) == FAIL) {
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set %s. Invalid value %d mV to convert to dac units.\n",
|
||||
powerNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int initPower(enum DACINDEX ind, char *mess) {
|
||||
if (ind == D_PWR_EMPTY)
|
||||
return OK;
|
||||
|
||||
enum PWRINDEX pwrIndex = 0;
|
||||
if (getPowerIndex(ind, &pwrIndex, initErrorMessage) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
int dacval = 0;
|
||||
int min = (ind == D_PWR_IO) ? VIO_MIN_MV : POWER_RGLTR_MIN;
|
||||
if (convertPowerRegVoltagetoDAC(pwrIndex, min, &dacval, initErrorMessage) ==
|
||||
FAIL)
|
||||
return FAIL;
|
||||
|
||||
if (setDAC(ind, dacval, 0, initErrorMessage) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getPower(enum DACINDEX ind, int *retval, char *mess) {
|
||||
enum PWRINDEX pwrIndex = 0;
|
||||
*retval = -1;
|
||||
|
||||
// validate index
|
||||
@@ -1433,50 +1516,14 @@ int getPower(enum DACINDEX ind, int* retval, char* mess) {
|
||||
}
|
||||
|
||||
// mV
|
||||
if (convertPowerRegDACtoVoltage(pwrIndex, dacValues[ind], retval, mess) == FAIL)
|
||||
if (convertPowerRegDACtoVoltage(pwrIndex, dacValues[ind], retval, mess) ==
|
||||
FAIL)
|
||||
return FAIL;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int convertPowerRegDACtoVoltage(enum PWRINDEX ind, int val, int* retval, char* mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
if (ConvertToDifferentRange(LTC2620_D_GetMaxInput(), LTC2620_D_GetMinInput(), POWER_RGLTR_MIN, POWER_RGLTR_MAX, val, retval) == FAIL) {
|
||||
sprintf(mess, "Could not get %s. Could not convert %d dac to mV\n", powerNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
int convertPowerRegVoltagetoDAC(enum PWRINDEX ind, int val, int* retval, char* mess) {
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
if (ConvertToDifferentRange(POWER_RGLTR_MIN, POWER_RGLTR_MAX, LTC2620_D_GetMaxInput(), LTC2620_D_GetMinInput(), val, retval) == FAIL) {
|
||||
sprintf(mess, "Could not set %s. Invalid value %d mV to convert to dac units.\n", powerNames[ind], val);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
int initPower(enum DACINDEX ind, char* mess) {
|
||||
if (ind == D_PWR_EMPTY)
|
||||
return OK;
|
||||
|
||||
enum PWRINDEX pwrIndex = 0;
|
||||
if (getPowerIndex(ind, &pwrIndex, initErrorMessage) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
int dacval = 0;
|
||||
int min = (ind == D_PWR_IO) ? VIO_MIN_MV : POWER_RGLTR_MIN;
|
||||
if (convertPowerRegVoltagetoDAC(pwrIndex, min, &dacval, initErrorMessage) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
if (setDAC(ind, dacval, 0, initErrorMessage) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int setPower(enum DACINDEX ind, int val, char* mess) {
|
||||
int setPower(enum DACINDEX ind, int val, char *mess) {
|
||||
enum PWRINDEX pwrIndex = 0;
|
||||
char *powerNames[] = {PWR_NAMES};
|
||||
|
||||
@@ -1485,9 +1532,9 @@ int setPower(enum DACINDEX ind, int val, char* mess) {
|
||||
return FAIL;
|
||||
|
||||
// validate values (invalidate power down)
|
||||
if (!isPowerValid(pwrIndex, val, mess) == FAIL)
|
||||
if (isPowerValid(pwrIndex, val, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
|
||||
LOG(logINFOBLUE, ("Setting %s to %d mV\n", val));
|
||||
|
||||
if (DisablePowerRail(pwrIndex, mess) == FAIL)
|
||||
@@ -1495,12 +1542,13 @@ int setPower(enum DACINDEX ind, int val, char* mess) {
|
||||
|
||||
// convert to dac units
|
||||
int dacval = val;
|
||||
if (val != LTC2620_GetPowerDownValue()) {
|
||||
if (val != LTC2620_D_GetPowerDownValue()) {
|
||||
if (convertPowerRegVoltagetoDAC(pwrIndex, val, &dacval, mess) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
LOG(logINFO, ("Setting %s (DAC %d): %d dac (%d mV)\n", powerNames[pwrIndex], dacval, val));
|
||||
LOG(logINFO, ("Setting %s (DAC %d): %d dac (%d mV)\n", powerNames[pwrIndex],
|
||||
dacval, val));
|
||||
if (setDAC(ind, dacval, 0, mess) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
@@ -1512,7 +1560,6 @@ int setPower(enum DACINDEX ind, int val, char* mess) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int getADC(enum ADCINDEX ind, int *value) {
|
||||
*value = 0;
|
||||
#ifdef VIRTUAL
|
||||
|
||||
@@ -119,31 +119,33 @@ int64_t getMeasurementTime();
|
||||
int setModule(sls_detector_module myMod, char *mess);
|
||||
|
||||
// parameters - dac, adc, hv
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char* mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int* retval, char* mess);
|
||||
int validateDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int setDAC(enum DACINDEX ind, int val, int mV, char *mess);
|
||||
int getDAC(enum DACINDEX ind, int mV, int *retval, char *mess);
|
||||
int getVLimit();
|
||||
int setVLimit(int val, char* mess);
|
||||
int setVLimit(int val, char *mess);
|
||||
|
||||
int getPowerRailMask(enum PWRINDEX ind, uint32_t* mask, char* mess);
|
||||
int EnablePowerRail(enum PWRINDEX ind, char* mess);
|
||||
int DisablePowerRail(enum PWRINDEX ind, char* mess);
|
||||
int getPowerRail(enum PWRINDEX ind, int* retval, char* mess);
|
||||
int getPowerRailMask(enum PWRINDEX ind, uint32_t *mask, char *mess);
|
||||
int EnablePowerRail(enum PWRINDEX ind, char *mess);
|
||||
int DisablePowerRail(enum PWRINDEX ind, char *mess);
|
||||
int getPowerRail(enum PWRINDEX ind, int *retval, char *mess);
|
||||
|
||||
int isPowerValid(enum PWRINDEX ind, int val, char* mess);
|
||||
int getPowerIndex(enum DACINDEX ind, enum PWRINDEX* pwrIndex, char* mess);
|
||||
int isPowerValid(enum PWRINDEX ind, int val, char *mess);
|
||||
int getPowerIndex(enum DACINDEX ind, enum PWRINDEX *pwrIndex, char *mess);
|
||||
|
||||
int convertPowertoDACUnits(enum PWRINDEX ind, int val, int* retval, char* mess);
|
||||
int initPower(enum DACINDEX ind, char* mess);
|
||||
int getPower(enum DACINDEX ind, int* retval, char* mess);
|
||||
int setPower(enum DACINDEX ind, int val, char* mess);
|
||||
int convertPowerRegDACtoVoltage(enum PWRINDEX ind, int val, int *retval,
|
||||
char *mess);
|
||||
int convertPowerRegVoltagetoDAC(enum PWRINDEX ind, int val, int *retval,
|
||||
char *mess);
|
||||
int initPower(enum DACINDEX ind, char *mess);
|
||||
int getPower(enum DACINDEX ind, int *retval, char *mess);
|
||||
int setPower(enum DACINDEX ind, int val, char *mess);
|
||||
|
||||
int getADC(enum ADCINDEX ind, int *value);
|
||||
int getSlowADC(int ichan, int *retval);
|
||||
int getTemperature(int *retval);
|
||||
int setHighVoltage(int val);
|
||||
|
||||
|
||||
// parameters - timing, extsig
|
||||
void setTiming(enum timingMode arg);
|
||||
enum timingMode getTiming();
|
||||
|
||||
@@ -119,11 +119,9 @@ enum DACINDEX {
|
||||
D_PWR_C
|
||||
};
|
||||
|
||||
|
||||
enum PWRINDEX { PWR_IO, PWR_A, PWR_B, PWR_C, PWR_D};
|
||||
enum PWRINDEX { PWR_IO, PWR_A, PWR_B, PWR_C, PWR_D };
|
||||
#define PWR_NAMES "VIO", "VA", "VB", "VC", "VD"
|
||||
|
||||
|
||||
/* Struct Definitions */
|
||||
// For arm has to be multiple of 16
|
||||
// We dont byteswap in the upd_gen so the order has to be different
|
||||
|
||||
Reference in New Issue
Block a user