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];