M3: fixed gain bits with negative polarity

This commit is contained in:
Erik Frojdh 2021-04-12 16:44:47 +02:00
parent d9cd780386
commit be5fee8126
14 changed files with 97 additions and 9 deletions

View File

@ -1143,6 +1143,9 @@ void init_det(py::module &m) {
.def("setGainCaps", .def("setGainCaps",
(void (Detector::*)(int, sls::Positions)) & Detector::setGainCaps, (void (Detector::*)(int, sls::Positions)) & Detector::setGainCaps,
py::arg(), py::arg() = Positions{}) py::arg(), py::arg() = Positions{})
.def("getGainCaps",
(Result<int>(Detector::*)(sls::Positions)) & Detector::getGainCaps,
py::arg() = Positions{})
.def("getNumberOfAnalogSamples", .def("getNumberOfAnalogSamples",
(Result<int>(Detector::*)(sls::Positions) const) & (Result<int>(Detector::*)(sls::Positions) const) &
Detector::getNumberOfAnalogSamples, Detector::getNumberOfAnalogSamples,

View File

@ -35,6 +35,44 @@ int getChipStatusRegister(){
return chipStatusRegister; return chipStatusRegister;
} }
int gainCapsToCsr(int caps){
//Translates bit representation
int csr = 0;
if (!(caps & M3_C10pre))
csr |= 1 << _CSR_C10pre;
if (caps & M3_C15sh)
csr |= 1 << CSR_C15sh;
if (caps & M3_C30sh)
csr |= 1 << CSR_C30sh;
if (caps & M3_C50sh)
csr |= 1 << CSR_C50sh;
if (caps & M3_C225ACsh)
csr |= 1 << CSR_C225ACsh;
if (!(caps & M3_C15pre))
csr |= 1 << _CSR_C15pre;
return csr;
}
int csrToGainCaps(int csr){
//Translates bit representation
int caps = 0;
if (!(csr & (1 << _CSR_C10pre)))
caps |= M3_C10pre;
if (csr & (1 << CSR_C15sh))
caps |= M3_C15sh;
if (csr & (1 << CSR_C30sh))
caps |= M3_C30sh;
if (csr & (1 << CSR_C50sh))
caps |= M3_C50sh;
if (csr & (1 << CSR_C225ACsh))
caps |= M3_C225ACsh;
if (!(csr & (1 << _CSR_C15pre)))
caps |= M3_C15pre;
return caps;
}
patternParameters *setChipStatusRegisterPattern(int csr) { patternParameters *setChipStatusRegisterPattern(int csr) {
int iaddr=0; int iaddr=0;
int nbits=18; int nbits=18;

View File

@ -37,23 +37,25 @@
#define CSR_invpol 4 #define CSR_invpol 4
#define CSR_dpulse 5 #define CSR_dpulse 5
#define CSR_interp 6 #define CSR_interp 6
#define CSR_C10pre 7 //#default #define _CSR_C10pre 7 //#default, negative polarity
#define CSR_pumprobe 8 #define CSR_pumprobe 8
#define CSR_apulse 9 #define CSR_apulse 9
#define CSR_C15sh 10 #define CSR_C15sh 10
#define CSR_C30sh 11 //#default #define CSR_C30sh 11 //#default
#define CSR_C50sh 12 #define CSR_C50sh 12
#define CSR_C225ACsh 13 // Connects 225fF SHAPER AC cap (1: 225 to shaper, 225 to GND. 0: 450 to shaper) #define CSR_C225ACsh 13 // Connects 225fF SHAPER AC cap (1: 225 to shaper, 225 to GND. 0: 450 to shaper)
#define CSR_C15pre 14 #define _CSR_C15pre 14 // negative polarity
#define CSR_default (1<<CSR_C10pre )|(1<< CSR_C30sh) #define CSR_default (1<<_CSR_C10pre )|(1<< CSR_C30sh)
#define GAIN_MASK ((1 << CSR_C10pre) | ( 1 << CSR_C15sh) | (1 << CSR_C30sh) | (1 << CSR_C50sh) | (1 << CSR_C225ACsh) | ( 1 << CSR_C15pre)) #define GAIN_MASK ((1 << _CSR_C10pre) | ( 1 << CSR_C15sh) | (1 << CSR_C30sh) | (1 << CSR_C50sh) | (1 << CSR_C225ACsh) | ( 1 << _CSR_C15pre))
int setBit(int ibit, int patword); int setBit(int ibit, int patword);
int clearBit(int ibit, int patword); int clearBit(int ibit, int patword);
int getChipStatusRegister(); int getChipStatusRegister();
int gainCapsToCsr(int caps);
int csrToGainCaps(int csr);
patternParameters *setChipStatusRegisterPattern(int csr); patternParameters *setChipStatusRegisterPattern(int csr);
patternParameters *setChannelRegisterChip(int ichip, int *mask, int *trimbits); patternParameters *setChannelRegisterChip(int ichip, int *mask, int *trimbits);

View File

@ -1078,8 +1078,8 @@ int setDACS(int* dacs){
int setModule(sls_detector_module myMod, char *mess) { int setModule(sls_detector_module myMod, char *mess) {
LOG(logINFO, ("Setting module\n")); LOG(logINFO, ("Setting module\n"));
if (setGainCaps(myMod.reg)){ if (setChipStatusRegister(myMod.reg)){
sprintf(mess, "Could not set module gain caps\n"); sprintf(mess, "Could not CSR from module\n");
LOG(logERROR, (mess)); LOG(logERROR, (mess));
return FAIL; return FAIL;
} }
@ -2667,7 +2667,15 @@ int setGainCaps(int caps){
// Update only gain caps, leave the rest of the CSR unchanged // Update only gain caps, leave the rest of the CSR unchanged
int csr = getChipStatusRegister(); int csr = getChipStatusRegister();
csr &= ~GAIN_MASK; csr &= ~GAIN_MASK;
caps &= GAIN_MASK;
caps = gainCapsToCsr(caps);
// caps &= GAIN_MASK;
csr |= caps; csr |= caps;
return setChipStatusRegister(csr); return setChipStatusRegister(csr);
} }
int getGainCaps(){
int csr = getChipStatusRegister();
int caps = csrToGainCaps(csr);
return caps;
}

View File

@ -358,6 +358,7 @@ enum timingMode getTiming();
void setInitialExtSignals(); void setInitialExtSignals();
int isMaster(); int isMaster();
int setGainCaps(int caps); int setGainCaps(int caps);
int getGainCaps();
int setChipStatusRegister(int csr); int setChipStatusRegister(int csr);
int setDACS(int* dacs); int setDACS(int* dacs);
#endif #endif

View File

@ -248,4 +248,5 @@ int load_default_pattern(int);
int get_all_threshold_energy(int); int get_all_threshold_energy(int);
int get_master(int); int get_master(int);
int get_csr(); int get_csr();
int set_gain_caps(int); int set_gain_caps(int);
int get_gain_caps(int);

View File

@ -371,6 +371,7 @@ void function_table() {
flist[F_GET_MASTER] = &get_master; flist[F_GET_MASTER] = &get_master;
flist[F_GET_CSR] = &get_csr; flist[F_GET_CSR] = &get_csr;
flist[F_SET_GAIN_CAPS] = &set_gain_caps; flist[F_SET_GAIN_CAPS] = &set_gain_caps;
flist[F_GET_GAIN_CAPS] = &get_gain_caps;
// check // check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -8423,3 +8424,25 @@ int set_gain_caps(int file_des){
#endif #endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
} }
int get_gain_caps(int file_des){
ret = OK;
memset(mess, 0, sizeof(mess));
// int arg = 0;
// if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
// return printSocketReadError();
LOG(logINFO, ("Getting gain caps\n"));
int retval = -1;
#ifndef MYTHEN3D
functionNotImplemented();
#else
if (Server_VerifyLock() == OK) {
retval = getGainCaps();
LOG(logDEBUG1, ("Gain caps: %u\n", retval));
}
#endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}

View File

@ -1314,6 +1314,8 @@ class Detector {
void setGainCaps(int caps, Positions pos = {}); void setGainCaps(int caps, Positions pos = {});
Result<int> getGainCaps(Positions pos = {});
///@{ ///@{
/** @name CTB / Moench Specific */ /** @name CTB / Moench Specific */

View File

@ -1992,7 +1992,7 @@ std::string CmdProxy::GainCaps(int action){
if (!args.empty()) if (!args.empty())
WrongNumberOfParameters(0); WrongNumberOfParameters(0);
auto tmp = det->getChipStatusRegister(); auto tmp = det->getGainCaps();
sls::Result<defs::M3_GainCaps> csr; sls::Result<defs::M3_GainCaps> csr;
for (auto val : tmp){ for (auto val : tmp){
if (val) if (val)

View File

@ -1623,6 +1623,10 @@ void Detector::setGainCaps(int caps, Positions pos){
return pimpl->Parallel(&Module::setGainCaps, pos, caps); return pimpl->Parallel(&Module::setGainCaps, pos, caps);
} }
Result<int> Detector::getGainCaps(Positions pos){
return pimpl->Parallel(&Module::getGainCaps, pos);
}
// CTB/ Moench Specific // CTB/ Moench Specific

View File

@ -2006,6 +2006,10 @@ void Module::setGainCaps(int caps){
sendToDetector<int>(F_SET_GAIN_CAPS, caps); sendToDetector<int>(F_SET_GAIN_CAPS, caps);
} }
int Module::getGainCaps(){
return sendToDetector<int>(F_GET_GAIN_CAPS);
}
// CTB / Moench Specific // CTB / Moench Specific
int Module::getNumberOfAnalogSamples() const { int Module::getNumberOfAnalogSamples() const {
return sendToDetector<int>(F_GET_NUM_ANALOG_SAMPLES); return sendToDetector<int>(F_GET_NUM_ANALOG_SAMPLES);

View File

@ -428,6 +428,7 @@ class Module : public virtual slsDetectorDefs {
bool isMaster() const; bool isMaster() const;
int getChipStatusRegister() const; int getChipStatusRegister() const;
void setGainCaps(int caps); void setGainCaps(int caps);
int getGainCaps();
/************************************************** /**************************************************
* * * *

View File

@ -223,6 +223,7 @@ enum detFuncs {
F_GET_MASTER, F_GET_MASTER,
F_GET_CSR, F_GET_CSR,
F_SET_GAIN_CAPS, F_SET_GAIN_CAPS,
F_GET_GAIN_CAPS,
NUM_DET_FUNCTIONS, NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this RECEIVER_ENUM_START = 256, /**< detector function should not exceed this