From 224c8d9f8d0cc461f62488c20dd5868da988336f Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 20 May 2021 14:51:37 +0200 Subject: [PATCH] m3 server: setting counter mask, set vth[i] for counter[i] and its M_VTH1, not VTH1 --- .../slsDetectorFunctionList.c | 40 ++++++++++--------- .../include/slsDetectorFunctionList.h | 6 +-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 7e0c737b1..c3efc3261 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -5,8 +5,8 @@ #include "RegisterDefs.h" #include "clogger.h" #include "common.h" -#include "mythen3.h" #include "loadPattern.h" +#include "mythen3.h" #include "sharedMemory.h" #include "sls/versionAPI.h" #ifdef VIRTUAL @@ -21,7 +21,6 @@ #include #endif - // Global variable from slsDetectorServer_funcs extern int debugflag; extern int updateFlag; @@ -47,7 +46,7 @@ enum detectorSettings thisSettings; sls_detector_module *detectorModules = NULL; int *detectorChans = NULL; int *detectorDacs = NULL; -int *channelMask=NULL; +int *channelMask = NULL; int32_t clkPhase[NUM_CLOCKS] = {}; uint32_t clkDivider[NUM_CLOCKS] = {}; @@ -379,7 +378,6 @@ void allocateDetectorStructureMemory() { memset(channelMask, 0, NCHIP * NCHAN * sizeof(char)); detectorDacs = malloc(NDAC * sizeof(int)); - LOG(logDEBUG1, ("modules from 0x%x to 0x%x\n", detectorModules, detectorModules)); LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n", detectorChans, detectorChans)); @@ -519,7 +517,7 @@ void setupDetector() { powerChip(1); if (!initError) { - setChipStatusRegister(CSR_default); + setChipStatusRegister(CSR_default); } setAllTrimbits(DEFAULT_TRIMBIT_VALUE); @@ -938,8 +936,9 @@ void setCounterMask(uint32_t arg) { for (int i = 0; i < NCOUNTERS; ++i) { // if change in enable if ((arg & (1 << i)) ^ (oldmask & (1 << i))) { - // will disable if counter disabled - setDAC(VTH1, vthEnabledVals[i], 0); + // will disable if counter disabled, else set corresponding vth dac + enum DACINDEX vth = (i == 0 ? M_VTH1 : (i == 1 ? M_VTH2 : M_VTH3)); + setDAC(vth, vthEnabledVals[i], 0); } } } @@ -1057,7 +1056,7 @@ int64_t getMeasurementTime() { /* parameters - module, speed, readout */ -int setDACS(int* dacs){ +int setDACS(int *dacs) { for (int i = 0; i < NDAC; ++i) { if (dacs[i] != -1) { setDAC((enum DACINDEX)i, dacs[i], 0); @@ -1074,17 +1073,16 @@ int setDACS(int* dacs){ return OK; } - int setModule(sls_detector_module myMod, char *mess) { LOG(logINFO, ("Setting module\n")); - if (setChipStatusRegister(myMod.reg)){ + if (setChipStatusRegister(myMod.reg)) { sprintf(mess, "Could not CSR from module\n"); LOG(logERROR, (mess)); return FAIL; } - if (setDACS(myMod.dacs)){ + if (setDACS(myMod.dacs)) { sprintf(mess, "Could not set dacs\n"); LOG(logERROR, (mess)); return FAIL; @@ -1093,7 +1091,7 @@ int setModule(sls_detector_module myMod, char *mess) { for (int i = 0; i < NCOUNTERS; ++i) { if (myMod.eV[i] >= 0) { setThresholdEnergy(i, myMod.eV[i]); - }else{ + } else { setThresholdEnergy(i, -1); } } @@ -1267,6 +1265,12 @@ void setDAC(enum DACINDEX ind, int val, int mV) { return; } + // out of scope, NDAC + 1 for vthreshold + if ((int)ind > NDAC + 1) { + LOG(logERROR, ("Unknown dac index %d\n", ind)); + return; + } + if (ind == M_VTHRESHOLD) { LOG(logINFO, ("Setting Threshold voltages to %d %s\n", val, (mV ? "mv" : ""))); @@ -1373,13 +1377,11 @@ int setHighVoltage(int val) { return highvoltage; } -int isMaster(){ - return !(bus_r(0x18) >> 31); -} +int isMaster() { return !(bus_r(0x18) >> 31); } /* parameters - timing */ void setTiming(enum timingMode arg) { - + if (!isMaster() && arg == AUTO_TIMING) arg = TRIGGER_EXPOSURE; @@ -2663,7 +2665,7 @@ int setChipStatusRegister(int csr) { return OK; } -int setGainCaps(int caps){ +int setGainCaps(int caps) { // Update only gain caps, leave the rest of the CSR unchanged int csr = getChipStatusRegister(); csr &= ~GAIN_MASK; @@ -2674,8 +2676,8 @@ int setGainCaps(int caps){ return setChipStatusRegister(csr); } -int getGainCaps(){ +int getGainCaps() { int csr = getChipStatusRegister(); int caps = csrToGainCaps(csr); - return caps; + return caps; } diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 65b5d7fb1..1f18cd371 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -25,7 +25,7 @@ #include "blackfin.h" #endif -#if defined(MYTHEN3D) +#if defined(MYTHEN3D) #include "mythen3.h" #endif @@ -289,8 +289,6 @@ int64_t getMeasurementTime(); int setModule(sls_detector_module myMod, char *mess); #endif #ifdef MYTHEN3D -int setBit(int ibit, int patword); -int clearBit(int ibit, int patword); int setTrimbits(int *trimbits); int setAllTrimbits(int val); int getAllTrimbits(); @@ -360,7 +358,7 @@ int isMaster(); int setGainCaps(int caps); int getGainCaps(); int setChipStatusRegister(int csr); -int setDACS(int* dacs); +int setDACS(int *dacs); #endif #if defined(GOTTHARDD) || defined(MYTHEN3D) void setExtSignal(int signalIndex, enum externalSignalFlag mode);