mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
badchannels done
This commit is contained in:
@ -78,14 +78,11 @@
|
||||
/* Status register */
|
||||
#define STATUS_REG (0x04 * REG_OFFSET + BASE_CONTROL)
|
||||
|
||||
/* Look at me read only register */
|
||||
#define LOOK_AT_ME_REG (0x05 * REG_OFFSET + BASE_CONTROL)
|
||||
|
||||
/* System status register */
|
||||
#define SYSTEM_STATUS_REG (0x06 * REG_OFFSET + BASE_CONTROL)
|
||||
#define SYSTEM_STATUS_REG (0x05 * REG_OFFSET + BASE_CONTROL)
|
||||
|
||||
/* Config RW regiseter */
|
||||
#define CONFIG_REG (0x20 * REG_OFFSET + BASE_CONTROL)
|
||||
#define CONFIG_REG (0x08 * REG_OFFSET + BASE_CONTROL)
|
||||
|
||||
#define CONFIG_VETO_ENBL_OFST (0)
|
||||
#define CONFIG_VETO_ENBL_MSK (0x00000001 << CONFIG_VETO_ENBL_OFST)
|
||||
@ -93,7 +90,7 @@
|
||||
#define CONFIG_VETO_CH_10GB_ENBL_MSK (0x00000001 << CONFIG_VETO_CH_10GB_ENBL_OFST)
|
||||
|
||||
/* Control RW register */
|
||||
#define CONTROL_REG (0x21 * REG_OFFSET + BASE_CONTROL)
|
||||
#define CONTROL_REG (0x09 * REG_OFFSET + BASE_CONTROL)
|
||||
|
||||
#define CONTROL_STRT_ACQSTN_OFST (0)
|
||||
#define CONTROL_STRT_ACQSTN_MSK (0x00000001 << CONTROL_STRT_ACQSTN_OFST)
|
||||
@ -111,12 +108,16 @@
|
||||
#define CONTROL_PWR_CHIP_MSK (0x00000001 << CONTROL_PWR_CHIP_OFST)
|
||||
|
||||
/** DTA Offset Register */
|
||||
#define DTA_OFFSET_REG (0x24 * REG_OFFSET + BASE_CONTROL)
|
||||
#define DTA_OFFSET_REG (0x0A * REG_OFFSET + BASE_CONTROL)
|
||||
|
||||
/** Mask Strip Registers (40) */
|
||||
#define MASK_STRIP_START_REG (0x18 * REG_OFFSET + BASE_CONTROL)
|
||||
#define MASK_STRIP_NUM_REGS (40)
|
||||
|
||||
/* ASIC registers --------------------------------------------------*/
|
||||
|
||||
/* ASIC Config register */
|
||||
#define ASIC_CONFIG_REG (0x00 * REG_OFFSET + BASE_ASIC)
|
||||
#define ASIC_CONFIG_REG (0x00 * REG_OFFSET + BASE_ASIC)
|
||||
|
||||
#define ASIC_CONFIG_RUN_MODE_OFST (0)
|
||||
#define ASIC_CONFIG_RUN_MODE_MSK (0x00000003 << ASIC_CONFIG_RUN_MODE_OFST)
|
||||
|
@ -2316,6 +2316,72 @@ int getVeto() {
|
||||
CONFIG_VETO_ENBL_OFST);
|
||||
}
|
||||
|
||||
void setBadChannels(int nch, int *channels) {
|
||||
LOG(logINFO, ("Setting %d bad channels\n", nch));
|
||||
|
||||
int numAddr = MASK_STRIP_NUM_REGS;
|
||||
int startAddr = MASK_STRIP_START_REG;
|
||||
|
||||
// resetting all mask registers first
|
||||
for (int iaddr = 0; iaddr < numAddr; ++iaddr) {
|
||||
uint32_t addr = startAddr + iaddr * REG_OFFSET;
|
||||
bus_w(addr, 0);
|
||||
}
|
||||
|
||||
// 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;
|
||||
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)));
|
||||
bus_w(addr, bus_r(addr) | (1 << iBit));
|
||||
}
|
||||
}
|
||||
|
||||
int *getBadChannels(int *nch) {
|
||||
int *retvals = NULL;
|
||||
// count number of bad channels
|
||||
*nch = 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));
|
||||
}
|
||||
if (*nch > 0) {
|
||||
// get list of bad channels
|
||||
retvals = malloc(*nch * sizeof(int));
|
||||
if (retvals == NULL) {
|
||||
*nch = -1;
|
||||
return NULL;
|
||||
}
|
||||
int chIndex = 0;
|
||||
int numAddr = MASK_STRIP_NUM_REGS;
|
||||
// loop through registers
|
||||
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) {
|
||||
// masked, add to list
|
||||
if ((val >> iBit) & 0x1) {
|
||||
LOG(logDEBUG1, ("iaddr:%d iBit:%d val:0x%x, ch:%d\n", iaddr,
|
||||
iBit, val, iaddr * 32 + iBit));
|
||||
retvals[chIndex++] = iaddr * 32 + iBit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// debugging
|
||||
LOG(logDEBUG1, ("Reading Bad channel list\n"));
|
||||
for (int i = 0; i < (*nch); ++i) {
|
||||
LOG(logDEBUG1, ("[%d]: %d\n", i, retvals[i]));
|
||||
}
|
||||
return retvals;
|
||||
}
|
||||
|
||||
/* aquisition */
|
||||
|
||||
int startStateMachine() {
|
||||
|
@ -523,6 +523,8 @@ void setTimingSource(enum timingSourceType value);
|
||||
enum timingSourceType getTimingSource();
|
||||
void setVeto(int enable);
|
||||
int getVeto();
|
||||
void setBadChannels(int nch, int *channels);
|
||||
int *getBadChannels(int *nch);
|
||||
#endif
|
||||
|
||||
#if defined(JUNGFRAUD) || defined(EIGERD)
|
||||
|
@ -236,3 +236,5 @@ int set_filter(int);
|
||||
int set_veto_file(int);
|
||||
int get_adc_config(int);
|
||||
int set_adc_config(int);
|
||||
int get_bad_channels(int);
|
||||
int set_bad_channels(int);
|
@ -353,6 +353,8 @@ void function_table() {
|
||||
flist[F_SET_VETO_FILE] = &set_veto_file;
|
||||
flist[F_GET_ADC_CONFIGURATION] = &get_adc_config;
|
||||
flist[F_SET_ADC_CONFIGURATION] = &set_adc_config;
|
||||
flist[F_GET_BAD_CHANNELS] = &get_bad_channels;
|
||||
flist[F_SET_BAD_CHANNELS] = &set_bad_channels;
|
||||
|
||||
// check
|
||||
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
||||
@ -7926,3 +7928,100 @@ int set_adc_config(int file_des) {
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, NULL, 0);
|
||||
}
|
||||
|
||||
int get_bad_channels(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int nretvals = 0;
|
||||
int *retvals = NULL;
|
||||
|
||||
LOG(logDEBUG1, ("Getting bad channels\n"));
|
||||
|
||||
#ifndef GOTTHARD2D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// get only
|
||||
retvals = getBadChannels(&nretvals);
|
||||
if (nretvals == -1) {
|
||||
ret = FAIL;
|
||||
strcpy(mess, "Could not get bad channels. Memory allcoation error\n");
|
||||
LOG(logERROR, (mess));
|
||||
}
|
||||
#endif
|
||||
Server_SendResult(file_des, INT32, NULL, 0);
|
||||
if (ret != FAIL) {
|
||||
sendData(file_des, &nretvals, sizeof(nretvals), INT32);
|
||||
if (nretvals > 0) {
|
||||
sendData(file_des, retvals, sizeof(int) * nretvals, INT32);
|
||||
}
|
||||
}
|
||||
if (retvals != NULL) {
|
||||
free(retvals);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int set_bad_channels(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int nargs = 0;
|
||||
int *args = NULL;
|
||||
|
||||
if (receiveData(file_des, &nargs, sizeof(nargs), INT32) < 0)
|
||||
return printSocketReadError();
|
||||
|
||||
if (nargs > 0) {
|
||||
args = malloc(nargs * sizeof(int));
|
||||
if (receiveData(file_des, args, nargs * sizeof(int), INT32) < 0)
|
||||
return printSocketReadError();
|
||||
}
|
||||
|
||||
LOG(logDEBUG1, ("Setting %d bad channels\n", nargs));
|
||||
|
||||
#ifndef GOTTHARD2D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// only set
|
||||
if (Server_VerifyLock() == OK) {
|
||||
// validate bad channel number
|
||||
for (int i = 0; i < nargs; ++i) {
|
||||
LOG(logDEBUG1, ("\t[%d]:%d\n", i, args[i]));
|
||||
if (args[i] < 0 || args[i] >= (NCHAN * NCHIP)) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,
|
||||
"Could not set bad channels. Invalid bad channel "
|
||||
"number %d. Options [0-%d]\n",
|
||||
args[i], NCHIP * NCHAN - 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");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args != NULL) {
|
||||
free(args);
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, NULL, 0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user