mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-10 06:40:02 +02:00
CSR in trim files
This commit is contained in:
parent
01c785271f
commit
779a2a0199
@ -52,7 +52,7 @@ servers = [
|
||||
# "eigerDetectorServer",
|
||||
# "jungfrauDetectorServer",
|
||||
"mythen3DetectorServer",
|
||||
"gotthard2DetectorServer",
|
||||
# "gotthard2DetectorServer",
|
||||
# "gotthardDetectorServer",
|
||||
# "ctbDetectorServer",
|
||||
# "moenchDetectorServer",
|
||||
|
Binary file not shown.
@ -35,7 +35,7 @@ int getChipStatusRegister(){
|
||||
return chipStatusRegister;
|
||||
}
|
||||
|
||||
patternParameters *setChipStatusRegister(int csr) {
|
||||
patternParameters *setChipStatusRegisterPattern(int csr) {
|
||||
int iaddr=0;
|
||||
int nbits=18;
|
||||
int error=0;
|
||||
@ -121,7 +121,7 @@ patternParameters *setInterpolation(int mask) {
|
||||
else
|
||||
csr=chipStatusRegister & ~(1<< CSR_interp);
|
||||
|
||||
return setChipStatusRegister(csr);
|
||||
return setChipStatusRegisterPattern(csr);
|
||||
}
|
||||
|
||||
|
||||
@ -133,7 +133,7 @@ patternParameters *setPumpProbe(int mask) {
|
||||
else
|
||||
csr=chipStatusRegister & ~(1<< CSR_pumprobe);
|
||||
|
||||
return setChipStatusRegister(csr);
|
||||
return setChipStatusRegisterPattern(csr);
|
||||
|
||||
}
|
||||
patternParameters *setDigitalPulsing(int mask) {
|
||||
@ -144,7 +144,7 @@ patternParameters *setDigitalPulsing(int mask) {
|
||||
else
|
||||
csr=chipStatusRegister & ~(1<< CSR_dpulse);
|
||||
|
||||
return setChipStatusRegister(csr);
|
||||
return setChipStatusRegisterPattern(csr);
|
||||
|
||||
}
|
||||
patternParameters *setAnalogPulsing(int mask){
|
||||
@ -155,7 +155,7 @@ patternParameters *setAnalogPulsing(int mask){
|
||||
else
|
||||
csr=chipStatusRegister & ~(1<< CSR_apulse);
|
||||
|
||||
return setChipStatusRegister(csr);
|
||||
return setChipStatusRegisterPattern(csr);
|
||||
|
||||
}
|
||||
patternParameters *setNegativePolarity(int mask){
|
||||
@ -166,138 +166,10 @@ patternParameters *setNegativePolarity(int mask){
|
||||
else
|
||||
csr=chipStatusRegister & ~(1<< CSR_invpol);
|
||||
|
||||
return setChipStatusRegister(csr);
|
||||
return setChipStatusRegisterPattern(csr);
|
||||
|
||||
}
|
||||
|
||||
int setGainPreamp(int pgain, int *csr) {
|
||||
|
||||
|
||||
|
||||
switch (pgain) {
|
||||
case Cp_0:
|
||||
case Cp_15:
|
||||
*csr=(*csr)&~(1<<CSR_C10pre);
|
||||
break;
|
||||
case Cp_10:
|
||||
case Cp_45:
|
||||
*csr=(*csr)|(1<<CSR_C10pre);
|
||||
break;
|
||||
default:
|
||||
LOG(logERROR, ("Bad preamp gain"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (pgain) {
|
||||
case Cp_0:
|
||||
case Cp_10:
|
||||
*csr=(*csr)&~(1<<CSR_C15pre);
|
||||
break;
|
||||
case Cp_15:
|
||||
case Cp_45:
|
||||
*csr=(*csr)|(1<<CSR_C15pre);
|
||||
break;
|
||||
default:
|
||||
LOG(logERROR, ("Bad preamp gain"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
int setGainShaper(int shgain, int *csr){
|
||||
|
||||
|
||||
switch (shgain) {
|
||||
case Csh_0:
|
||||
case Csh_30:
|
||||
case Csh_50:
|
||||
case Csh_80:
|
||||
*csr=(*csr)&~(1<<CSR_C15sh);
|
||||
break;
|
||||
case Csh_15:
|
||||
case Csh_45:
|
||||
case Csh_65:
|
||||
case Csh_95:
|
||||
*csr=(*csr)|(1<<CSR_C15sh);
|
||||
break;
|
||||
default:
|
||||
LOG(logERROR, ("Bad shaper gain"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (shgain) {
|
||||
case Csh_0:
|
||||
case Csh_15:
|
||||
case Csh_50:
|
||||
case Csh_65:
|
||||
*csr=(*csr)&~(1<<CSR_C30sh);
|
||||
break;
|
||||
case Csh_30:
|
||||
case Csh_45:
|
||||
case Csh_80:
|
||||
case Csh_95:
|
||||
*csr=(*csr)|(1<<CSR_C30sh);
|
||||
break;
|
||||
default:
|
||||
LOG(logERROR, ("Bad shaper gain"));
|
||||
return 1;
|
||||
}
|
||||
switch (shgain) {
|
||||
case Csh_0:
|
||||
case Csh_15:
|
||||
case Csh_30:
|
||||
case Csh_45:
|
||||
*csr=(*csr)&~(1<<CSR_C50sh);
|
||||
break;
|
||||
case Csh_80:
|
||||
case Csh_50:
|
||||
case Csh_65:
|
||||
case Csh_95:
|
||||
*csr=(*csr)|(1<<CSR_C50sh);
|
||||
break;
|
||||
default:
|
||||
LOG(logERROR, ("Bad shaper gain"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setGainAC(int acgain, int *csr){
|
||||
|
||||
switch (acgain) {
|
||||
case Cac_450:
|
||||
*csr=(*csr)&~(1<<CSR_C225ACsh);
|
||||
break;
|
||||
case Cac225:
|
||||
*csr=(*csr)|(1<<CSR_C225ACsh);
|
||||
break;
|
||||
default:
|
||||
LOG(logERROR, ("Bad ac gain"));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
patternParameters *setChipGain(int pgain, int shgain, int acgain){
|
||||
int csr=chipStatusRegister;
|
||||
|
||||
if (setGainPreamp(pgain,&csr))
|
||||
return NULL;
|
||||
if (setGainShaper(shgain,&csr))
|
||||
return NULL;
|
||||
if (setGainAC(acgain,&csr))
|
||||
return NULL;
|
||||
|
||||
return setChipStatusRegister(csr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
patternParameters *setChannelRegisterChip(int ichip, int *mask, int *trimbits) {
|
||||
|
||||
patternParameters *pat = malloc(sizeof(patternParameters));
|
||||
|
@ -51,27 +51,16 @@
|
||||
#define GAIN_MASK ((1 << CSR_C10pre) | ( 1 << CSR_C15sh) | (1 << CSR_C30sh) | (1 << CSR_C50sh) | (1 << CSR_C225ACsh) | ( 1 << CSR_C15pre))
|
||||
|
||||
|
||||
enum {Cp_0, Cp_10, Cp_15, Cp_45};
|
||||
enum {Csh_0,Csh_15,Csh_30,Csh_45,Csh_50,Csh_65,Csh_80,Csh_95};
|
||||
enum {Cac225, Cac_450};
|
||||
|
||||
|
||||
|
||||
#define default_gain
|
||||
int setBit(int ibit, int patword);
|
||||
int clearBit(int ibit, int patword);
|
||||
int getChipStatusRegister();
|
||||
|
||||
patternParameters *setChipStatusRegister(int csr);
|
||||
patternParameters *setChipStatusRegisterPattern(int csr);
|
||||
patternParameters *setChannelRegisterChip(int ichip, int *mask, int *trimbits);
|
||||
patternParameters *setInterpolation(int mask);
|
||||
patternParameters *setPumpProbe(int mask);
|
||||
patternParameters *setDigitalPulsing(int mask);
|
||||
patternParameters *setAnalogPulsing(int mask);
|
||||
patternParameters *setNegativePolarity(int mask);
|
||||
patternParameters *setChipGain(int pgain, int shgain, int acgain);
|
||||
int setGainAC(int shgain, int *csr);
|
||||
int setGainShaper(int shgain, int *csr);
|
||||
int setGainPreamp(int pgain, int *csr);
|
||||
|
||||
#endif
|
||||
|
@ -518,7 +518,7 @@ void setupDetector() {
|
||||
|
||||
powerChip(1);
|
||||
if (initError != FAIL) {
|
||||
patternParameters *pat=setChipStatusRegister(CSR_default);
|
||||
patternParameters *pat=setChipStatusRegisterPattern(CSR_default);
|
||||
if (pat) {
|
||||
initError=loadPattern(pat);
|
||||
startStateMachine();
|
||||
@ -1060,38 +1060,39 @@ int64_t getMeasurementTime() {
|
||||
|
||||
/* parameters - module, speed, readout */
|
||||
|
||||
int setDACS(int* dacs){
|
||||
for (int i = 0; i < NDAC; ++i) {
|
||||
if (dacs[i] != -1) {
|
||||
setDAC((enum DACINDEX)i, dacs[i], 0);
|
||||
if (dacs[i] != detectorDacs[i]) {
|
||||
// dont complain if that counter was disabled
|
||||
if ((i == M_VTH1 || i == M_VTH2 || i == M_VTH3) &&
|
||||
(detectorDacs[i] == DEFAULT_COUNTER_DISABLED_VTH_VAL)) {
|
||||
continue;
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int setModule(sls_detector_module myMod, char *mess) {
|
||||
LOG(logINFO, ("Setting module\n"));
|
||||
|
||||
|
||||
if (setGainCaps(myMod.reg)){
|
||||
sprintf(mess, "Could not set module gain caps\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// dacs
|
||||
for (int i = 0; i < NDAC; ++i) {
|
||||
// ignore dacs with -1
|
||||
if (myMod.dacs[i] != -1) {
|
||||
setDAC((enum DACINDEX)i, myMod.dacs[i], 0);
|
||||
if (myMod.dacs[i] != detectorDacs[i]) {
|
||||
// dont complain if that counter was disabled
|
||||
if ((i == M_VTH1 || i == M_VTH2 || i == M_VTH3) &&
|
||||
(detectorDacs[i] == DEFAULT_COUNTER_DISABLED_VTH_VAL)) {
|
||||
continue;
|
||||
}
|
||||
sprintf(mess,
|
||||
"Could not set module. Could not set dac %d, wrote %d, "
|
||||
"read %d\n",
|
||||
i, myMod.dacs[i], detectorDacs[i]);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if (setDACS(myMod.dacs)){
|
||||
sprintf(mess, "Could not set dacs\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// threshold
|
||||
for (int i = 0; i < NCOUNTERS; ++i) {
|
||||
if (myMod.eV[i] >= 0) {
|
||||
setThresholdEnergy(i, myMod.eV[i]);
|
||||
@ -2632,105 +2633,45 @@ int getNumberOfDACs() { return NDAC; }
|
||||
int getNumberOfChannelsPerChip() { return NCHAN; }
|
||||
|
||||
|
||||
|
||||
int setGainCaps(int caps){
|
||||
//TODO Refactor!!!!!
|
||||
int csr = getChipStatusRegister();
|
||||
|
||||
LOG(logINFO, ("gain_mask: 0x%x\n", GAIN_MASK));
|
||||
LOG(logINFO, ("csr: 0x%x\n", csr));
|
||||
csr &= ~GAIN_MASK; //zero out the bits in the gain mask
|
||||
LOG(logINFO, ("csr: 0x%x\n", csr));
|
||||
caps &= GAIN_MASK;
|
||||
csr |= caps;
|
||||
|
||||
LOG(logINFO, ("csr: 0x%x\n", csr));
|
||||
|
||||
//now comes the actual setting
|
||||
// remember previous run clock
|
||||
int setChipStatusRegister(int csr){
|
||||
uint32_t prevRunClk = clkDivider[SYSTEM_C0];
|
||||
patternParameters *pat=NULL;
|
||||
|
||||
int error=0;
|
||||
// set to trimming clock
|
||||
if (setClockDivider(SYSTEM_C0, DEFAULT_TRIMMING_RUN_CLKDIV) == FAIL) {
|
||||
LOG(logERROR,
|
||||
("Could not start trimming. Could not set to trimming clock\n"));
|
||||
("Could not set to trimming clock in order to change CSR\n"));
|
||||
return FAIL;
|
||||
}
|
||||
pat = setChipStatusRegister(csr);
|
||||
pat = setChipStatusRegisterPattern(csr);
|
||||
|
||||
if (pat) {
|
||||
error|=loadPattern(pat);
|
||||
if (error==0)
|
||||
startPattern();
|
||||
free(pat);
|
||||
} else
|
||||
error=1;
|
||||
/////////////////////////////////////////////////////////////////
|
||||
error |= loadPattern(pat);
|
||||
if (error == 0)
|
||||
startPattern();
|
||||
free(pat);
|
||||
}else{
|
||||
error = 1;
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
|
||||
LOG(logINFO, ("The gain has been changed\n"));
|
||||
LOG(logINFO, ("CSR is now: 0x%x\n", csr));
|
||||
}
|
||||
trimmingPrint = logINFO;
|
||||
// set back to previous clock
|
||||
|
||||
if (setClockDivider(SYSTEM_C0, prevRunClk) == FAIL) {
|
||||
LOG(logERROR, ("Could not set to previous run clock after trimming\n"));
|
||||
LOG(logERROR, ("Could not set to previous run clock after changing CSR\n"));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (error != 0) {
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int setGain(int gain) {
|
||||
// remember previous run clock
|
||||
uint32_t prevRunClk = clkDivider[SYSTEM_C0];
|
||||
patternParameters *pat=NULL;
|
||||
int error=0;
|
||||
// set to trimming clock
|
||||
if (setClockDivider(SYSTEM_C0, DEFAULT_TRIMMING_RUN_CLKDIV) == FAIL) {
|
||||
LOG(logERROR,
|
||||
("Could not start trimming. Could not set to trimming clock\n"));
|
||||
return FAIL;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////
|
||||
int pgain=Cp_10;
|
||||
int shgain=Csh_30;
|
||||
int acgain=Cac_450;
|
||||
/*
|
||||
acgain=gain%2;
|
||||
gain/=2;
|
||||
shgain=gain%8;
|
||||
gain/=8;
|
||||
pgain=gain
|
||||
*/
|
||||
|
||||
|
||||
pat=setChipGain(pgain, shgain, acgain);
|
||||
if (pat) {
|
||||
error|=loadPattern(pat);
|
||||
if (error==0)
|
||||
startPattern();
|
||||
free(pat);
|
||||
} else
|
||||
error=1;
|
||||
/////////////////////////////////////////////////////////////////
|
||||
if (error == 0) {
|
||||
|
||||
LOG(logINFO, ("The gain has been changed\n"));
|
||||
}
|
||||
trimmingPrint = logINFO;
|
||||
// set back to previous clock
|
||||
if (setClockDivider(SYSTEM_C0, prevRunClk) == FAIL) {
|
||||
LOG(logERROR, ("Could not set to previous run clock after trimming\n"));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (error != 0) {
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int setGainCaps(int caps){
|
||||
// Update only gain caps, leave the rest of the CSR unchanged
|
||||
int csr = getChipStatusRegister();
|
||||
csr &= ~GAIN_MASK;
|
||||
caps &= GAIN_MASK;
|
||||
csr |= caps;
|
||||
return setChipStatusRegister(csr);
|
||||
}
|
||||
|
@ -358,6 +358,8 @@ enum timingMode getTiming();
|
||||
void setInitialExtSignals();
|
||||
int isMaster();
|
||||
int setGainCaps(int caps);
|
||||
int setChipStatusRegister(int csr);
|
||||
int setDACS(int* dacs);
|
||||
#endif
|
||||
#if defined(GOTTHARDD) || defined(MYTHEN3D)
|
||||
void setExtSignal(int signalIndex, enum externalSignalFlag mode);
|
||||
|
@ -8415,24 +8415,11 @@ int set_gain_caps(int file_des){
|
||||
#ifndef MYTHEN3D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// only set
|
||||
|
||||
if (Server_VerifyLock() == OK) {
|
||||
// if (arg != 0 && arg != 1) {
|
||||
// ret = FAIL;
|
||||
// sprintf(mess,
|
||||
// "Could not set gain caps. Invalid value %d. "
|
||||
// "Options [0-1]\n",
|
||||
// arg);
|
||||
// LOG(logERROR, (mess));
|
||||
// } else {
|
||||
setGainCaps(arg);
|
||||
retval = getChipStatusRegister(); //TODO! fix
|
||||
LOG(logDEBUG1, ("gain caps retval: %u\n", retval));
|
||||
// validate(arg, retval, " cds gain enable", DEC);
|
||||
// }
|
||||
setGainCaps(arg);
|
||||
retval = getChipStatusRegister(); //TODO! fix
|
||||
LOG(logDEBUG1, ("gain caps retval: %u\n", retval));
|
||||
}
|
||||
#endif
|
||||
// return Server_SendResult(file_des, INT32, NULL, 0);
|
||||
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user