initial implementation

This commit is contained in:
Erik Frojdh
2021-03-29 14:21:48 +02:00
parent 7c4f9ee044
commit 043d582616
17 changed files with 164 additions and 3 deletions

View File

@@ -35,6 +35,32 @@ int getChipStatusRegister(){
return chipStatusRegister;
}
// int setGainCaps(int caps){
// int csr = getChipStatusRegister();
// int gain_mask = 0;
// gain_mask |= 1 << CSR_C10pre;
// gain_mask |= 1 << CSR_C15sh;
// gain_mask |= 1 << CSR_C30sh;
// gain_mask |= 1 << CSR_C50sh;
// gain_mask |= 1 << CSR_C225ACsh;
// gain_mask |= 1 << CSR_C15pre;
// 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
// return 0;
// }
patternParameters *setChipStatusRegister(int csr) {
int iaddr=0;
int nbits=18;

View File

@@ -48,6 +48,9 @@
#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))
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};
@@ -58,6 +61,7 @@ enum {Cac225, Cac_450};
int setBit(int ibit, int patword);
int clearBit(int ibit, int patword);
int getChipStatusRegister();
patternParameters *setChipStatusRegister(int csr);
patternParameters *setChannelRegisterChip(int ichip, int *mask, int *trimbits);
patternParameters *setInterpolation(int mask);

View File

@@ -2660,6 +2660,60 @@ int getNumberOfChips() { return NCHIP; }
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
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;
}
pat = setChipStatusRegister(csr);
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 setGain(int gain) {
// remember previous run clock
uint32_t prevRunClk = clkDivider[SYSTEM_C0];

View File

@@ -357,6 +357,7 @@ enum timingMode getTiming();
#ifdef MYTHEN3D
void setInitialExtSignals();
int isMaster();
int setGainCaps(int caps);
#endif
#if defined(GOTTHARDD) || defined(MYTHEN3D)
void setExtSignal(int signalIndex, enum externalSignalFlag mode);

View File

@@ -247,4 +247,5 @@ int get_pattern(int);
int load_default_pattern(int);
int get_all_threshold_energy(int);
int get_master(int);
int get_csr();
int get_csr();
int set_gain_caps(int);

View File

@@ -370,6 +370,7 @@ void function_table() {
flist[F_GET_ALL_THRESHOLD_ENERGY] = &get_all_threshold_energy;
flist[F_GET_MASTER] = &get_master;
flist[F_GET_CSR] = &get_csr;
flist[F_SET_GAIN_CAPS] = &set_gain_caps;
// check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@@ -8405,3 +8406,38 @@ int get_csr(int file_des){
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}
int set_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, ("Setting gain caps to: %u\n", arg));
int retval = -1;
#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);
// }
}
#endif
// return Server_SendResult(file_des, INT32, NULL, 0);
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}