confadc added to client, removed conf adc depending on burst mode

This commit is contained in:
2020-07-15 13:30:30 +02:00
parent 7752b86d97
commit d7f490701b
12 changed files with 335 additions and 73 deletions

View File

@ -503,7 +503,7 @@ int readConfigFile() {
memset(line, 0, LZ);
char command[LZ];
int nadcRead = 0;
int nAdcTotal = 0;
// keep reading a line
while (fgets(line, LZ, fd)) {
@ -617,7 +617,7 @@ int readConfigFile() {
break;
}
// validations
if (value > ASIC_ADC_MAX_VAL) {
if (value < 0 || value > ASIC_ADC_MAX_VAL) {
sprintf(initErrorMessage,
"Could not configure adc from on-board server config "
"file. Invalid value (max 0x%x). Line:[%s].\n",
@ -625,28 +625,23 @@ int readConfigFile() {
break;
}
int chipmin = 0;
int chipmax = NCHIP;
int adcmin = 0;
int adcmax = NADC;
// specific chip
if (ichip != -1) {
chipmin = ichip;
chipmax = ichip + 1;
}
// specific adc
if (iadc != -1) {
adcmin = iadc;
adcmax = iadc + 1;
if (setADCConfiguration(ichip, iadc, value) == FAIL) {
sprintf(initErrorMessage,
"Could not configure adc from on-board server "
"config file. Line:[%s].\n",
line);
break;
}
for (int i = chipmin; i < chipmax; ++i) {
for (int j = adcmin; j < adcmax; ++j) {
adcConfiguration[i][j] = (uint8_t)value;
++nadcRead;
}
// to ensure all adcs are configured at start up
int nadc = 1;
if (iadc == -1) {
nadc = NADC;
}
if (ichip == -1) {
nadc *= NCHIP;
}
nAdcTotal += nadc;
}
// vchip command
@ -762,17 +757,11 @@ int readConfigFile() {
fclose(fd);
if (!strlen(initErrorMessage)) {
if (nadcRead != NADC * NCHIP) {
if (nAdcTotal != NADC * NCHIP) {
sprintf(initErrorMessage,
"Could not configure adc from on-board server config file. "
"Insufficient adcconf commands. Read %d, expected %d\n",
nadcRead, NADC * NCHIP);
}
}
for (int i = 0; i < NCHIP; ++i) {
for (int j = 0; j < NADC; ++j) {
LOG(logDEBUG2,
("adc read %d %d: 0x%02hhx\n", i, j, adcConfiguration[i][j]));
nAdcTotal, NADC * NCHIP);
}
}
@ -1934,24 +1923,52 @@ int setVetoFile(int chipIndex, int *gainIndices, int *values) {
return configureASICVetoReference(chipIndex, values);
}
int configureSingleADCDriver(int chipIndex) {
LOG(logINFO, ("Configuring ADC for %s chips [chipIndex:%d Burst Mode:%d]\n",
chipIndex == -1 ? "All" : "Single", chipIndex, burstMode));
int setADCConfiguration(int chipIndex, int adcIndex, int value) {
LOG(logINFO, ("Configuring ADC [chipIndex:%d, adcIndex:%d, value:0x%x]\n",
chipIndex, adcIndex, value));
// validations
if (chipIndex < -1 || chipIndex >= NCHIP) {
LOG(logERROR, ("Invalid chip index %d\n", chipIndex));
return FAIL;
}
if (adcIndex < -1 || adcIndex >= NADC) {
LOG(logERROR, ("Invalid adc index %d\n", adcIndex));
return FAIL;
}
// validations
if (value < 0 || value > ASIC_ADC_MAX_VAL) {
LOG(logERROR, ("Invalid value 0x%x\n", value));
return FAIL;
}
int chipmin = 0;
int chipmax = NCHIP;
int adcmin = 0;
int adcmax = NADC;
// specific chip
if (chipIndex != -1) {
chipmin = chipIndex;
chipmax = chipIndex + 1;
}
// specific adc
if (adcIndex != -1) {
adcmin = adcIndex;
adcmax = adcIndex + 1;
}
// update values
for (int i = chipmin; i < chipmax; ++i) {
for (int j = adcmin; j < adcmax; ++j) {
adcConfiguration[i][j] = (uint8_t)value;
LOG(logDEBUG1,
("Value [%d][%d]: 0x%02hhx\n", i, j, adcConfiguration[i][j]));
}
}
// single chip configuration
int ind = chipIndex;
// all chips, take the first one as all equal
if (ind == -1) {
ind = 0;
}
uint8_t values[NADC];
memcpy(values, adcConfiguration + ind * NADC, NADC);
// change adc values if continuous mode
for (int i = 0; i < NADC; ++i) {
if (burstMode == BURST_OFF) {
values[i] |= ASIC_CONTINUOUS_MODE_MSK;
}
LOG(logDEBUG2, ("Value %d: 0x%02hhx\n", i, values[i]));
}
const int lenDataBitsPerADC = ASIC_ADC_MAX_BITS; // 7
const int lenBits = lenDataBitsPerADC * NADC; // 224
@ -1966,8 +1983,9 @@ int configureSingleADCDriver(int chipIndex) {
for (int ich = 0; ich < NADC; ++ich) {
// loop through all bits in a value
for (int iBit = 0; iBit < lenDataBitsPerADC; ++iBit) {
commandBytes[offset++] =
((values[ich] >> (lenDataBitsPerADC - 1 - iBit)) & 0x1);
commandBytes[offset++] = ((adcConfiguration[ind][ich] >>
(lenDataBitsPerADC - 1 - iBit)) &
0x1);
}
}
@ -1994,29 +2012,46 @@ int configureSingleADCDriver(int chipIndex) {
return OK;
}
int configureADC() {
LOG(logINFO, ("Configuring ADC \n"));
int getADCConfiguration(int chipIndex, int adcIndex) {
// already validated at tcp interface
if (chipIndex < -1 || chipIndex >= NCHIP) {
LOG(logERROR, ("Invalid chip index %d\n", chipIndex));
return -1;
}
if (adcIndex < -1 || adcIndex >= NADC) {
LOG(logERROR, ("Invalid adc index %d\n", adcIndex));
return -1;
}
int chipmin = 0;
int chipmax = NCHIP;
int adcmin = 0;
int adcmax = NADC;
// specific chip
if (chipIndex != -1) {
chipmin = chipIndex;
chipmax = chipIndex + 1;
}
// specific adc
if (adcIndex != -1) {
adcmin = adcIndex;
adcmax = adcIndex + 1;
}
int val = adcConfiguration[chipmin][adcmin];
int equal = 1;
for (int i = 0; i < NADC; ++i) {
int val = adcConfiguration[0][i];
for (int j = 1; j < NCHIP; ++j) {
if (adcConfiguration[j][i] != val) {
equal = 0;
break;
// ensure same values for chip and adc in question
for (int i = chipmin; i < chipmax; ++i) {
for (int j = adcmin; j < adcmax; ++j) {
if (adcConfiguration[i][j] != val) {
LOG(logINFO,
("\tADC configuration 0x%x at [%d][%d] differs from 0x%x "
"at "
"[%d][%d], returning -1\n",
adcConfiguration[i][j], i, j, val, chipmin, adcmin));
return -1;
}
}
}
if (equal) {
return configureSingleADCDriver(-1);
} else {
for (int i = 0; i < NCHIP; ++i) {
if (configureSingleADCDriver(i) == FAIL) {
return FAIL;
}
}
}
return OK;
return val;
}
int setBurstModeinFPGA(enum burstMode value) {
@ -2121,20 +2156,20 @@ int setBurstMode(enum burstMode burst) {
}
}
LOG(logINFO, ("\tDone Updating registers\n"))
return configureASICGlobalSettings();
}
int configureASICGlobalSettings() {
LOG(logINFO, ("\tSetting %s Mode in Chip\n",
burstMode == BURST_OFF ? "Continuous" : "Burst"));
int modeValue =
burstMode ? ASIC_GLOBAL_BURST_VALUE : ASIC_GLOBAL_CONT_VALUE;
int value = ((modeValue << ASIC_GLOBAL_MODE_OFST) & ASIC_GLOBAL_MODE_MSK) |
((filter << ASIC_FILTER_OFST) & ASIC_FILTER_MSK) |
((cdsGain << ASIC_CDS_GAIN_OFST) & ASIC_CDS_GAIN_MSK);
LOG(logINFO, ("\tsetting value:0x%x (mode:%d, filter:%d, cdsgain:%d)\n",
value, modeValue, filter, cdsGain));
LOG(logINFO,
("\tSending Global Chip settings:0x%x (mode:%d(%s), filter:%d, "
"cdsgain:%d)\n",
value, modeValue, (burstMode == BURST_OFF ? "Continuous" : "Burst"),
filter, cdsGain));
const int padding = 6; // due to address (4) to make it byte aligned
const int lenTotalBits = padding + ASIC_GLOBAL_SETT_MAX_BITS +
@ -2172,7 +2207,7 @@ int configureASICGlobalSettings() {
return FAIL;
}
return configureADC();
return OK;
}
enum burstMode getBurstMode() {

View File

@ -507,8 +507,8 @@ int setVetoPhoton(int chipIndex, int gainIndex, int *values);
int configureASICVetoReference(int chipIndex, int *values);
int getVetoPhoton(int chipIndex, int *retvals);
int setVetoFile(int chipIndex, int *gainIndices, int *values);
int configureSingleADCDriver(int chipIndex);
int configureADC();
int setADCConfiguration(int chipIndex, int adcIndex, int value);
int getADCConfiguration(int chipIndex, int adcIndex);
int setBurstModeinFPGA(enum burstMode value);
int setBurstMode(enum burstMode burst);
int configureASICGlobalSettings();

View File

@ -233,4 +233,6 @@ int get_cds_gain(int);
int set_cds_gain(int);
int get_filter(int);
int set_filter(int);
int set_veto_file(int);
int set_veto_file(int);
int get_adc_config(int);
int set_adc_config(int);

View File

@ -351,6 +351,8 @@ void function_table() {
flist[F_GET_FILTER] = &get_filter;
flist[F_SET_FILTER] = &set_filter;
flist[F_SET_VETO_FILE] = &set_veto_file;
flist[F_GET_ADC_CONFIGURATION] = &get_adc_config;
flist[F_SET_ADC_CONFIGURATION] = &set_adc_config;
// check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -7819,4 +7821,108 @@ int set_veto_file(int file_des) {
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}
}
int get_adc_config(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[2] = {-1, -1};
int retval = -1;
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
LOG(logDEBUG1, ("Getting adc configuration [chipIndex:%d, adcIndex:%d]\n",
args[0], args[1]));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// get only
int chipIndex = args[0];
int adcIndex = args[1];
if (chipIndex < -1 || chipIndex >= NCHIP) {
ret = FAIL;
sprintf(mess,
"Could not get adc configuration. Invalid chip index %d\n",
chipIndex);
LOG(logERROR, (mess));
} else if (adcIndex < -1 || adcIndex >= NADC) {
ret = FAIL;
sprintf(mess, "Could not get adc configuration. Invalid adc index %d\n",
adcIndex);
LOG(logERROR, (mess));
} else {
retval = getADCConfiguration(chipIndex, adcIndex);
LOG(logDEBUG1, ("adc config retval: %u\n", retval));
if (retval == -1) {
ret = FAIL;
sprintf(mess,
"Could not get a single adc configuration. Different "
"values for "
"selected adc (%d) and chip (%d) range.\n",
chipIndex, adcIndex);
LOG(logERROR, (mess));
}
}
#endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}
int set_adc_config(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[3] = {-1, -1, -1};
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
LOG(logDEBUG1,
("Setting adc configuration [chipIndex:%d, adcIndex:%d, value:0x%x]\n",
args[0], args[1], args[2]));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
int chipIndex = args[0];
int adcIndex = args[1];
int value = args[2];
if (chipIndex < -1 || chipIndex >= NCHIP) {
ret = FAIL;
sprintf(mess,
"Could not get adc configuration. Invalid chip index %d. "
"Options: [-1 to %d]\n",
chipIndex, NCHIP);
LOG(logERROR, (mess));
} else if (adcIndex < -1 || adcIndex >= NADC) {
ret = FAIL;
sprintf(mess,
"Could not get adc configuration. Invalid adc index %d. "
"Options: [-1 to %d]\n",
adcIndex, NADC);
LOG(logERROR, (mess));
} else if (value < 0 || value > ASIC_ADC_MAX_VAL) {
ret = FAIL;
sprintf(mess,
"Could not get adc configuration. Invalid value 0x%x. "
"Options: [0 to 0x%x]\n",
value, ASIC_ADC_MAX_VAL);
LOG(logERROR, (mess));
} else {
ret = setADCConfiguration(chipIndex, adcIndex, value);
if (ret == FAIL) {
sprintf(mess,
"Could not set adc configuration in chip (chipIndex: "
"%d, adcIndex: %d, value:0x%x).\n",
chipIndex, adcIndex, value);
LOG(logERROR, (mess));
} else {
int retval = getADCConfiguration(chipIndex, adcIndex);
LOG(logDEBUG1, ("adc config retval: %u\n", retval));
validate(value, retval, "configure adc", HEX);
}
}
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}