mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
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:
Binary file not shown.
Binary file not shown.
@ -3024,8 +3024,8 @@ void setVetoAlgorithm(enum vetoAlgorithm alg,
|
||||
bus_w(addr, value);
|
||||
}
|
||||
|
||||
void setBadChannels(int nch, int *channels) {
|
||||
LOG(logINFO, ("Setting %d bad channels\n", nch));
|
||||
int setBadChannels(int numChannels, int *channelList) {
|
||||
LOG(logINFO, ("Setting %d bad channels\n", numChannels));
|
||||
|
||||
int numAddr = MASK_STRIP_NUM_REGS;
|
||||
int startAddr = MASK_STRIP_START_REG;
|
||||
@ -3037,42 +3037,44 @@ void setBadChannels(int nch, int *channels) {
|
||||
}
|
||||
|
||||
// setting badchannels, loop through list
|
||||
for (int i = 0; i < nch; ++i) {
|
||||
LOG(logINFO, ("\t[%d]: %d\n", i, channels[i]));
|
||||
int iaddr = channels[i] / 32;
|
||||
int iBit = channels[i] % 32;
|
||||
for (int i = 0; i != numChannels; ++i) {
|
||||
LOG(logINFO, ("\t[%d]: %d\n", i, channelList[i]));
|
||||
int iaddr = channelList[i] / 32;
|
||||
int iBit = channelList[i] % 32;
|
||||
uint32_t addr = startAddr + iaddr * REG_OFFSET;
|
||||
LOG(logDEBUG1,
|
||||
("val:%d iaddr:%d iBit:%d, addr:0x%x old:0x%x val:0x%x\n",
|
||||
channels[i], iaddr, iBit, addr, bus_r(addr), (1 << iBit)));
|
||||
channelList[i], iaddr, iBit, addr, bus_r(addr), (1 << iBit)));
|
||||
bus_w(addr, bus_r(addr) | (1 << iBit));
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int *getBadChannels(int *nch) {
|
||||
int *getBadChannels(int *numChannels) {
|
||||
int *retvals = NULL;
|
||||
// count number of bad channels
|
||||
*nch = 0;
|
||||
for (int i = 0; i < MASK_STRIP_NUM_REGS; ++i) {
|
||||
*numChannels = 0;
|
||||
for (int i = 0; i != MASK_STRIP_NUM_REGS; ++i) {
|
||||
uint32_t addr = MASK_STRIP_START_REG + i * REG_OFFSET;
|
||||
*nch += __builtin_popcount(bus_r(addr));
|
||||
*numChannels += __builtin_popcount(bus_r(addr));
|
||||
}
|
||||
if (*nch > 0) {
|
||||
if (*numChannels > 0) {
|
||||
// get list of bad channels
|
||||
retvals = malloc(*nch * sizeof(int));
|
||||
retvals = malloc(*numChannels * sizeof(int));
|
||||
memset(retvals, 0, *numChannels * sizeof(int));
|
||||
if (retvals == NULL) {
|
||||
*nch = -1;
|
||||
*numChannels = -1;
|
||||
return NULL;
|
||||
}
|
||||
int chIndex = 0;
|
||||
int numAddr = MASK_STRIP_NUM_REGS;
|
||||
// loop through registers
|
||||
for (int iaddr = 0; iaddr < numAddr; ++iaddr) {
|
||||
for (int iaddr = 0; iaddr != numAddr; ++iaddr) {
|
||||
// calculate address and get value
|
||||
uint32_t addr = MASK_STRIP_START_REG + iaddr * REG_OFFSET;
|
||||
uint32_t val = bus_r(addr);
|
||||
// loop through 32 bits
|
||||
for (int iBit = 0; iBit < 32; ++iBit) {
|
||||
for (int iBit = 0; iBit != 32; ++iBit) {
|
||||
// masked, add to list
|
||||
if ((val >> iBit) & 0x1) {
|
||||
LOG(logDEBUG1, ("iaddr:%d iBit:%d val:0x%x, ch:%d\n", iaddr,
|
||||
@ -3084,7 +3086,7 @@ int *getBadChannels(int *nch) {
|
||||
}
|
||||
// debugging
|
||||
LOG(logDEBUG1, ("Reading Bad channel list\n"));
|
||||
for (int i = 0; i < (*nch); ++i) {
|
||||
for (int i = 0; i != (*numChannels); ++i) {
|
||||
LOG(logDEBUG1, ("[%d]: %d\n", i, retvals[i]));
|
||||
}
|
||||
return retvals;
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -624,8 +624,11 @@ int getVetoStream();
|
||||
enum vetoAlgorithm getVetoAlgorithm(enum streamingInterface interface);
|
||||
void setVetoAlgorithm(enum vetoAlgorithm alg,
|
||||
enum streamingInterface interface);
|
||||
void setBadChannels(int nch, int *channels);
|
||||
int *getBadChannels(int *nch);
|
||||
#endif
|
||||
|
||||
#if defined(GOTTHARD2D) || defined(MYTHEN3D)
|
||||
int setBadChannels(int numChannels, int *channelList);
|
||||
int *getBadChannels(int *numChannels);
|
||||
#endif
|
||||
|
||||
#if defined(JUNGFRAUD) || defined(EIGERD)
|
||||
|
@ -31,8 +31,8 @@ extern int64_t set64BitReg(int64_t value, int aLSB, int aMSB);
|
||||
#endif
|
||||
|
||||
void initializePatternAddresses() {
|
||||
LOG(logINFO, ("Setting default Loop and Wait Addresses(0x%x)\n",
|
||||
MAX_PATTERN_LENGTH - 1));
|
||||
LOG(logDEBUG1, ("Setting default Loop and Wait Addresses(0x%x)\n",
|
||||
MAX_PATTERN_LENGTH - 1));
|
||||
for (int i = 0; i != MAX_LEVELS; ++i) {
|
||||
setPatternLoopAddresses(i, MAX_PATTERN_LENGTH - 1,
|
||||
MAX_PATTERN_LENGTH - 1);
|
||||
|
@ -1897,11 +1897,11 @@ int acquire(int blocking, int file_des) {
|
||||
uint32_t sourceip = getDetectorIP();
|
||||
char src_ip[INET_ADDRSTRLEN];
|
||||
getIpAddressinString(src_ip, sourceip);
|
||||
sprintf(mess,
|
||||
"Invalid udp source ip address for this detector. Must be "
|
||||
"same "
|
||||
"as hardware detector ip address %s in 1G readout mode \n",
|
||||
src_ip);
|
||||
sprintf(
|
||||
mess,
|
||||
"Invalid udp source ip address for this detector. Must be "
|
||||
"same as hardware detector ip address %s in 1G readout mode \n",
|
||||
src_ip);
|
||||
LOG(logERROR, (mess));
|
||||
} else
|
||||
#endif
|
||||
@ -7981,7 +7981,7 @@ int get_bad_channels(int file_des) {
|
||||
|
||||
LOG(logDEBUG1, ("Getting bad channels\n"));
|
||||
|
||||
#ifndef GOTTHARD2D
|
||||
#if !defined(GOTTHARD2D) && !defined(MYTHEN3D)
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// get only
|
||||
@ -8022,44 +8022,53 @@ int set_bad_channels(int file_des) {
|
||||
|
||||
LOG(logDEBUG1, ("Setting %d bad channels\n", nargs));
|
||||
|
||||
#ifndef GOTTHARD2D
|
||||
#if !defined(GOTTHARD2D) && !defined(MYTHEN3D)
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// only set
|
||||
if (Server_VerifyLock() == OK) {
|
||||
// validate bad channel number
|
||||
int maxChannel = NCHAN * NCHIP;
|
||||
#ifdef MYTHEN3D
|
||||
maxChannel = NCHAN_1_COUNTER * NCHIP;
|
||||
#endif
|
||||
for (int i = 0; i < nargs; ++i) {
|
||||
LOG(logDEBUG1, ("\t[%d]:%d\n", i, args[i]));
|
||||
if (args[i] < 0 || args[i] >= (NCHAN * NCHIP)) {
|
||||
if (args[i] < 0 || args[i] >= maxChannel) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,
|
||||
"Could not set bad channels. Invalid bad channel "
|
||||
"number %d. Options [0-%d]\n",
|
||||
args[i], NCHIP * NCHAN - 1);
|
||||
args[i], maxChannel - 1);
|
||||
LOG(logERROR, (mess));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret == OK) {
|
||||
setBadChannels(nargs, args);
|
||||
int nretvals = 0;
|
||||
int *retvals = getBadChannels(&nretvals);
|
||||
if (nretvals == -1) {
|
||||
ret = FAIL;
|
||||
strcpy(mess,
|
||||
"Could not get bad channels. Memory allcoation error\n");
|
||||
ret = setBadChannels(nargs, args);
|
||||
if (ret == FAIL) {
|
||||
strcpy(mess, "Could not set bad channels.\n");
|
||||
LOG(logERROR, (mess));
|
||||
} else if (nretvals != nargs) {
|
||||
ret = FAIL;
|
||||
sprintf(
|
||||
mess,
|
||||
"Could not set bad channels. Set %d channels, but read %d "
|
||||
"channels\n",
|
||||
nargs, nretvals);
|
||||
LOG(logERROR, (mess));
|
||||
}
|
||||
if (retvals != NULL) {
|
||||
free(retvals);
|
||||
} else {
|
||||
int nretvals = 0;
|
||||
int *retvals = getBadChannels(&nretvals);
|
||||
if (nretvals == -1) {
|
||||
ret = FAIL;
|
||||
strcpy(mess, "Could not get bad channels. Memory "
|
||||
"allcoation error\n");
|
||||
LOG(logERROR, (mess));
|
||||
} else if (nretvals != nargs) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,
|
||||
"Could not set bad channels. Set %d channels, but "
|
||||
"read %d "
|
||||
"channels\n",
|
||||
nargs, nretvals);
|
||||
LOG(logERROR, (mess));
|
||||
}
|
||||
if (retvals != NULL) {
|
||||
free(retvals);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user