M3badchannels (#526)

* badchannels for m3 and modify for g2 (file from single and multi)

* m3: invert polarity of bit 7 and 11 signals from setmodule, allow commas in bad channel file

* badchannel file can take commas, colons and comments (also taking care of spaces at the end of channel numbers)

* tests 'badchannels' and 'Channel file reading' added, removing duplicates in badchannel list, defining macro for num counters in client side

* fix segfault when list from file is empty, 

* fix tests assertion for ctbconfig (adding message) for c++11

* fixed badchannels in m3server (clocking in trimming) 

* badchannel tests can be run from any folder (finds the file)
This commit is contained in:
Dhanya Thattil
2022-09-01 15:30:04 +02:00
committed by GitHub
parent 02322bb3c2
commit 7de6f157b5
36 changed files with 499 additions and 221 deletions

View File

@ -97,6 +97,10 @@ patternParameters *setChipStatusRegisterPattern(int csr) {
return pat;
}
void flipNegativePolarityBits(int *csr) {
(*csr) ^= ((1 << _CSR_C10pre) | (1 << _CSR_C15pre));
}
int getGainCaps() {
int csr = chipStatusRegister;
// Translates bit representation
@ -209,7 +213,8 @@ int M3SetNegativePolarity(int enable) {
return csr;
}
patternParameters *setChannelRegisterChip(int ichip, int *mask, int *trimbits) {
patternParameters *setChannelRegisterChip(int ichip, char *mask,
int *trimbits) {
patternParameters *pat = malloc(sizeof(patternParameters));
memset(pat, 0, sizeof(patternParameters));
@ -279,44 +284,44 @@ patternParameters *setChannelRegisterChip(int ichip, int *mask, int *trimbits) {
// for each channel (all chips)
for (int ich = 0; ich < NCHAN_1_COUNTER; ich++) {
LOG(logDEBUG1, (" Chip %d, Channel %d\n", ichip, ich));
int val =
trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS + NCOUNTERS * ich] +
trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS + NCOUNTERS * ich +
1] *
64 +
trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS + NCOUNTERS * ich +
2] *
64 * 64;
int chanReg =
64 *
(trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS + NCOUNTERS * ich] +
trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS + NCOUNTERS * ich +
1] *
64 +
trimbits[ichip * NCHAN_1_COUNTER * NCOUNTERS + NCOUNTERS * ich +
2] *
64 * 64);
// push 6 0 bits
for (int i = 0; i < 3; i++) {
patword = clearBit(SIGNAL_serialIN, patword);
patword = clearBit(SIGNAL_clk, patword);
pat->word[iaddr++] = patword;
patword = setBit(SIGNAL_clk, patword);
pat->word[iaddr++] = patword;
}
for (int i = 0; i < 3; i++) {
if (mask[i])
patword = setBit(SIGNAL_serialIN, patword);
else
patword = clearBit(SIGNAL_serialIN, patword);
patword = clearBit(SIGNAL_clk, patword);
pat->word[iaddr++] = patword;
patword = setBit(SIGNAL_clk, patword);
pat->word[iaddr++] = patword;
for (int icounter = 0; icounter != 3; ++icounter) {
if (mask[ichip * NCHAN + ich * NCOUNTERS + icounter]) {
LOG(logDEBUG1,
("badchannel [modCounter:%d, modChan:%d, ichip:%d, ich:%d, "
"icounter:%d]\n",
ichip * NCHAN + ich * NCOUNTERS + icounter,
ichip * NCHAN_1_COUNTER + ich, ichip, ich, icounter));
chanReg |= (0x1 << (3 + icounter));
}
}
// deserialize
for (int i = 0; i < 18; i++) {
if (val & (1 << i)) {
if (chanReg & CHAN_REG_BAD_CHANNEL_MSK) {
LOG(logINFOBLUE,
("badchannel [chanReg:0x%x modCounter:%d, modChan:%d, "
"ichip:%d, ich:%d]\n",
chanReg, ichip * NCHAN + ich * NCOUNTERS,
ichip * NCHAN_1_COUNTER + ich, ichip, ich));
}
for (int i = 0; i < 24; i++) {
patword = clearBit(SIGNAL_clk, patword);
pat->word[iaddr++] = patword;
if (chanReg & (1 << (i + 1))) {
patword = setBit(SIGNAL_serialIN, patword);
} else {
patword = clearBit(SIGNAL_serialIN, patword);
}
patword = clearBit(SIGNAL_clk, patword);
pat->word[iaddr++] = patword;
patword = setBit(SIGNAL_clk, patword);
pat->word[iaddr++] = patword;

View File

@ -61,12 +61,15 @@
((1 << _CSR_C10pre) | (1 << CSR_C15sh) | (1 << CSR_C30sh) | \
(1 << CSR_C50sh) | (1 << CSR_C225ACsh) | (1 << _CSR_C15pre))
#define CHAN_REG_BAD_CHANNEL_MSK (0x38)
int setBit(int ibit, int patword);
int clearBit(int ibit, int patword);
int getChipStatusRegister();
patternParameters *setChipStatusRegisterPattern(int csr);
patternParameters *setChannelRegisterChip(int ichip, int *mask, int *trimbits);
patternParameters *setChannelRegisterChip(int ichip, char *mask, int *trimbits);
void flipNegativePolarityBits(int *csr);
int getGainCaps();
int M3SetGainCaps(int caps);
int getInterpolation();

View File

@ -52,7 +52,7 @@ enum detectorSettings thisSettings = UNINITIALIZED;
sls_detector_module *detectorModules = NULL;
int *detectorChans = NULL;
int *detectorDacs = NULL;
int *channelMask = NULL;
char *badChannelMask = NULL;
int defaultDacValues[NDAC] = DEFAULT_DAC_VALS;
int defaultDacValue_standard[] = SPECIAL_DEFAULT_STANDARD_DAC_VALS;
int defaultDacValue_fast[] = SPECIAL_DEFAULT_FAST_DAC_VALS;
@ -391,9 +391,9 @@ void initStopServer() {
void allocateDetectorStructureMemory() {
// Allocation of memory
detectorModules = malloc(sizeof(sls_detector_module));
detectorChans = malloc(NCHIP * NCHAN * sizeof(int));
channelMask = malloc(NCHIP * NCHAN * sizeof(char));
memset(channelMask, 0, NCHIP * NCHAN * sizeof(char));
detectorChans = malloc(NCHAN_PER_MODULE * sizeof(int));
badChannelMask = malloc(NCHAN_PER_MODULE * sizeof(char));
memset(badChannelMask, 0, NCHAN_PER_MODULE * sizeof(char));
detectorDacs = malloc(NDAC * sizeof(int));
LOG(logDEBUG1,
@ -404,7 +404,7 @@ void allocateDetectorStructureMemory() {
(detectorModules)->chanregs = detectorChans;
(detectorModules)->ndac = NDAC;
(detectorModules)->nchip = NCHIP;
(detectorModules)->nchan = NCHIP * NCHAN;
(detectorModules)->nchan = NCHAN_PER_MODULE;
(detectorModules)->reg = UNINITIALIZED;
(detectorModules)->iodelay = 0;
(detectorModules)->tau = 0;
@ -1291,6 +1291,7 @@ int setModule(sls_detector_module myMod, char *mess) {
detectorModules->serialnumber = myMod.serialnumber;
// csr reg
flipNegativePolarityBits(&myMod.reg);
if (setChipStatusRegister(myMod.reg)) {
sprintf(mess, "Could not CSR from module\n");
LOG(logERROR, (mess));
@ -1349,9 +1350,8 @@ int setTrimbits(int *trimbits) {
int error = 0;
char cmess[MAX_STR_LENGTH];
for (int ichip = 0; ichip < NCHIP; ichip++) {
patternParameters *pat = setChannelRegisterChip(
ichip, channelMask,
trimbits); // change here!!! @who: Change what?
patternParameters *pat =
setChannelRegisterChip(ichip, badChannelMask, trimbits);
if (pat == NULL) {
error = 1;
} else {
@ -2340,6 +2340,55 @@ int getClockDivider(enum CLKINDEX ind) {
return clkDivider[ind];
}
int setBadChannels(int numChannels, int *channelList) {
LOG(logINFO, ("Setting %d bad channels\n", numChannels));
memset(badChannelMask, 0, NCHAN_PER_MODULE * sizeof(char));
for (int i = 0; i != numChannels; ++i) {
LOG(logINFO, ("\t[%d]: %d\n", i, channelList[i]));
for (int ich = channelList[i] * NCOUNTERS;
ich != channelList[i] * NCOUNTERS + NCOUNTERS; ++ich) {
badChannelMask[ich] = 1;
}
}
for (int i = 0; i != NCHAN_PER_MODULE; ++i) {
if (badChannelMask[i]) {
LOG(logDEBUG1, ("[%d]:0x%02x\n", i, badChannelMask[i]));
}
}
return setTrimbits(detectorChans);
}
int *getBadChannels(int *numChannels) {
int *retvals = NULL;
*numChannels = 0;
for (int i = 0; i != NCHAN_PER_MODULE; i = i + NCOUNTERS) {
if (badChannelMask[i]) {
*numChannels += 1;
}
}
if (*numChannels > 0) {
retvals = malloc(*numChannels * sizeof(int));
memset(retvals, 0, *numChannels * sizeof(int));
if (retvals == NULL) {
*numChannels = -1;
return NULL;
}
// return only 1 channel for all counters
int ich = 0;
for (int i = 0; i != NCHAN_PER_MODULE; i = i + NCOUNTERS) {
if (badChannelMask[i]) {
retvals[ich++] = i / NCOUNTERS;
}
}
}
// debugging
LOG(logDEBUG1, ("Reading Bad channel list: %d\n", *numChannels));
for (int i = 0; i != (*numChannels); ++i) {
LOG(logDEBUG1, ("[%d]: %d\n", i, retvals[i]));
}
return retvals;
}
int getTransmissionDelayFrame() {
return ((bus_r(FMT_CONFIG_REG) & FMT_CONFIG_TXN_DELAY_MSK) >>
FMT_CONFIG_TXN_DELAY_OFST);

View File

@ -17,6 +17,7 @@
#define NCHAN_1_COUNTER (128)
#define NCHAN (128 * NCOUNTERS)
#define NCHIP (10)
#define NCHAN_PER_MODULE (NCHAN * NCHIP)
#define NDAC (16)
#define HV_SOFT_MAX_VOLTAGE (500)
#define HV_HARD_MAX_VOLTAGE (530)