gotthard2: bursttype to burstmode

This commit is contained in:
maliakal_d 2020-01-23 11:03:14 +01:00
parent f881133795
commit a9e375ed34
16 changed files with 147 additions and 201 deletions

View File

@ -46,8 +46,7 @@ int injectedChannelsOffset = 0;
int injectedChannelsIncrement = 0;
int vetoReference[NCHIP][NCHAN];
uint8_t adcConfiguration[NCHIP][NADC];
int burstMode = 0;
enum burstModeType burstType = INTERNAL;
int burstMode = BURST_INTERNAL;
int64_t exptime_ns = 0;
int64_t period_ns = 0;
int64_t nframes = 0;
@ -349,8 +348,7 @@ void setupDetector() {
highvoltage = 0;
injectedChannelsOffset = 0;
injectedChannelsIncrement = 0;
burstMode = 0;
burstType = INTERNAL;
burstMode = BURST_INTERNAL;
exptime_ns = 0;
period_ns = 0;
nframes = 0;
@ -431,8 +429,6 @@ void setupDetector() {
return;
}
#endif
// set burst mode will take in burstType and also set it
burstType = DEFAULT_BURST_TYPE;
setBurstMode(DEFAULT_BURST_MODE);
setSettings(DEFAULT_SETTINGS);
@ -1667,10 +1663,10 @@ int configureSingleADCDriver(int chipIndex) {
{
int i = 0;
for (i = 0; i < NADC; ++i) {
if (!burstMode) {
if (burstMode == BURST_OFF) {
values[i] |= ASIC_CONTINUOUS_MODE_MSK;
}
FILE_LOG(logDEBUG1, ("Value %d: 0x%02hhx\n", i, values[i]));
FILE_LOG(logDEBUG2, ("Value %d: 0x%02hhx\n", i, values[i]));
}
}
@ -1746,14 +1742,39 @@ int configureADC() {
return OK;
}
int setBurstModeinFPGA(enum burstMode value) {
uint32_t addr = ASIC_CONFIG_REG;
uint32_t runmode = 0;
switch (value) {
case BURST_OFF:
runmode = ASIC_CONFIG_RUN_MODE_CONT_VAL;
break;
case BURST_INTERNAL:
runmode = ASIC_CONFIG_RUN_MODE_INT_BURST_VAL;
break;
case BURST_EXTERNAL:
runmode = ASIC_CONFIG_RUN_MODE_EXT_BURST_VAL;
break;
default:
FILE_LOG(logERROR, ("Unknown burst mode %d\n", value));
return FAIL;
}
FILE_LOG(logDEBUG1, ("Run mode (FPGA val): %d\n", runmode));
bus_w(addr, bus_r(addr) &~ ASIC_CONFIG_RUN_MODE_MSK);
bus_w(addr, bus_r(addr) | ((runmode << ASIC_CONFIG_RUN_MODE_OFST) & ASIC_CONFIG_RUN_MODE_MSK));
burstMode = value;
return OK;
}
int setBurstMode(int burst) {
FILE_LOG(logINFO, ("Setting %s Mode\n", burst == 1 ? "Burst" : "Continuous"));
burstMode = burst;
setBurstType(burstType);
int setBurstMode(enum burstMode burst) {
FILE_LOG(logINFO, ("Setting burst mode to %s\n", burst == BURST_OFF ? "off" : (burst == BURST_INTERNAL ? "internal" : "external")));
FILE_LOG(logINFO, ("\tSetting %s Mode in Chip\n", burst == 1 ? "Burst" : "Continuous"));
int value = burst ? ASIC_GLOBAL_BURST_VALUE : ASIC_GLOBAL_CONT_VALUE;
if (setBurstModeinFPGA(burst) == FAIL) {
return FAIL;
}
FILE_LOG(logINFO, ("\tSetting %s Mode in Chip\n", burstMode == BURST_OFF ? "Continuous" : "Burst"));
int value = burstMode ? ASIC_GLOBAL_BURST_VALUE : ASIC_GLOBAL_CONT_VALUE;
const int padding = 6; // due to address (4) to make it byte aligned
const int lenTotalBits = padding + ASIC_GLOBAL_SETT_MAX_BITS + ASIC_ADDR_MAX_BITS; // 4 + 6 + 4 = 16
@ -1794,58 +1815,28 @@ int setBurstMode(int burst) {
return configureADC();
}
int getBurstMode() {
enum burstMode getBurstMode() {
uint32_t addr = ASIC_CONFIG_REG;
int runmode = bus_r (addr) & ASIC_CONFIG_RUN_MODE_MSK;
switch (runmode) {
case ASIC_CONFIG_RUN_MODE_CONT_VAL:
return BURST_OFF;
case ASIC_CONFIG_RUN_MODE_INT_BURST_VAL:
return BURST_INTERNAL;
case ASIC_CONFIG_RUN_MODE_EXT_BURST_VAL:
return 1;
return BURST_EXTERNAL;
default:
return 0;
}
}
void setBurstType(enum burstModeType val) {
uint32_t addr = ASIC_CONFIG_REG;
uint32_t runmode = ASIC_CONFIG_RUN_MODE_CONT_VAL;
if (burstMode) {
switch (val) {
case INTERNAL:
runmode = ASIC_CONFIG_RUN_MODE_INT_BURST_VAL;
break;
case EXTERNAL:
runmode = ASIC_CONFIG_RUN_MODE_EXT_BURST_VAL;
break;
default:
FILE_LOG(logERROR, ("Unknown burst type %d\n", val));
return;
}
FILE_LOG(logDEBUG1, ("Run mode: %d\n", runmode));
bus_w(addr, bus_r(addr) &~ ASIC_CONFIG_RUN_MODE_MSK);
bus_w(addr, bus_r(addr) | ((runmode << ASIC_CONFIG_RUN_MODE_OFST) & ASIC_CONFIG_RUN_MODE_MSK));
}
}
enum burstModeType getBurstType() {
uint32_t addr = ASIC_CONFIG_REG;
int runmode = bus_r (addr) & ASIC_CONFIG_RUN_MODE_MSK;
switch (runmode) {
case ASIC_CONFIG_RUN_MODE_INT_BURST_VAL:
return INTERNAL;
case ASIC_CONFIG_RUN_MODE_EXT_BURST_VAL:
return EXTERNAL;
default:
FILE_LOG(logERROR, ("Unknown burst type read from FPGA: %d\n", runmode));
FILE_LOG(logERROR, ("Unknown run mode read from FPGA %d\n", runmode));
return -1;
}
}
/* aquisition */
int updateAcquisitionRegisters(char* mess) {
// burst mode
if (burstMode) {
if (burstMode != BURST_OFF) {
// validate #frames in burst mode
if (nframes > MAX_FRAMES_IN_BURST_MODE) {
sprintf(mess, "Could not start acquisition because number of frames %lld must be <= %d in burst mode.\n", (long long unsigned int)nframes, MAX_FRAMES_IN_BURST_MODE);

View File

@ -29,8 +29,7 @@
#define TYPE_NO_MODULE_STARTING_VAL (800)
/** Default Parameters */
#define DEFAULT_BURST_MODE (1)
#define DEFAULT_BURST_TYPE (INTERNAL)
#define DEFAULT_BURST_MODE (BURST_INTERNAL)
#define DEFAULT_NUM_FRAMES (1)
#define DEFAULT_NUM_CYCLES (1)
#define DEFAULT_EXPTIME (1 * 1000 * 1000) // 1 ms

View File

@ -474,10 +474,9 @@ int setVetoPhoton(int chipIndex, int gainIndex, int* values);
int getVetoPhoton(int chipIndex, int* retvals);
int configureSingleADCDriver(int chipIndex);
int configureADC();
int setBurstMode(int burst);
int getBurstMode();
void setBurstType(enum burstModeType val);
enum burstModeType getBurstType();
int setBurstModeinFPGA(enum burstMode value);
int setBurstMode(enum burstMode burst);
enum burstMode getBurstMode();
#endif

View File

@ -206,5 +206,3 @@ int set_adc_enable_mask_10g(int);
int get_adc_enable_mask_10g(int);
int set_counter_mask(int);
int get_counter_mask(int);
int set_burst_type(int);
int get_burst_type(int);

View File

@ -308,8 +308,6 @@ const char* getFunctionName(enum detFuncs func) {
case F_GET_ADC_ENABLE_MASK_10G: return "F_GET_ADC_ENABLE_MASK_10G";
case F_SET_COUNTER_MASK: return "F_SET_COUNTER_MASK";
case F_GET_COUNTER_MASK: return "F_GET_COUNTER_MASK";
case F_SET_BURST_TYPE: return "F_SET_BURST_TYPE";
case F_GET_BURST_TYPE: return "F_GET_BURST_TYPE";
default: return "Unknown Function";
}
@ -494,8 +492,6 @@ void function_table() {
flist[F_GET_ADC_ENABLE_MASK_10G] = &get_adc_enable_mask_10g;
flist[F_SET_COUNTER_MASK] = &set_counter_mask;
flist[F_GET_COUNTER_MASK] = &get_counter_mask;
flist[F_SET_BURST_TYPE] = &set_burst_type;
flist[F_GET_BURST_TYPE] = &get_burst_type;
// check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -6499,22 +6495,35 @@ int set_veto_reference(int file_des) {
int set_burst_mode(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int arg = -1;
enum burstMode arg = BURST_OFF;
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError();
FILE_LOG(logINFO, ("Setting burst mode: %d\n", arg));
FILE_LOG(logDEBUG1, ("Setting burst mode: %d\n", arg));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
arg = arg == 0 ? 0 : 1;
ret = setBurstMode(arg);
if (ret == FAIL) {
sprintf(mess, "Could not set burst mode to %d\n", arg);
FILE_LOG(logERROR, (mess));
switch (arg) {
case BURST_OFF:
case BURST_INTERNAL:
case BURST_EXTERNAL:
break;
default:
modeNotImplemented("Burst mode", (int)arg);
break;
}
if (ret == OK) {
setBurstMode(arg);
enum burstMode retval = getBurstMode();
FILE_LOG(logDEBUG, ("burst mode retval: %d\n", retval));
if (retval != arg) {
ret = FAIL;
sprintf(mess, "Could not set burst type. Set %d, got %d\n", arg, retval);
FILE_LOG(logERROR, (mess));
}
}
}
#endif
@ -6525,7 +6534,7 @@ int set_burst_mode(int file_des) {
int get_burst_mode(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int retval = -1;
enum burstMode retval = BURST_OFF;
FILE_LOG(logDEBUG1, ("Getting burst mode\n"));
@ -6534,7 +6543,7 @@ int get_burst_mode(int file_des) {
#else
// get only
retval = getBurstMode();
FILE_LOG(logDEBUG1, ("Get burst mode:%d\n", retval));
FILE_LOG(logDEBUG1, ("Get burst mode retval:%d\n", retval));
#endif
return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval));
}
@ -6594,60 +6603,3 @@ int get_counter_mask(int file_des) {
#endif
return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval));
}
int set_burst_type(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
enum burstModeType arg = 0;
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError();
FILE_LOG(logINFO, ("Setting burst type: %d\n", arg));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
switch (arg) {
case INTERNAL:
case EXTERNAL:
break;
default:
modeNotImplemented("Burst type", (int)arg);
break;
}
if (ret == OK) {
setBurstType(arg);
enum burstModeType retval = getBurstType();
FILE_LOG(logDEBUG, ("burst type retval: %d\n", retval));
if (retval != arg) {
ret = FAIL;
sprintf(mess, "Could not set burst type. Set %s, got %s\n", (arg == 0 ? "internal" : "external"), (retval == 0 ? "internal" : "external"));
FILE_LOG(logERROR, (mess));
}
}
}
#endif
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
}
int get_burst_type(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
enum burstModeType retval = 0;
FILE_LOG(logDEBUG1, ("Getting burst type\n"));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// get only
retval = getBurstType();
FILE_LOG(logDEBUG, ("burst type retval: %d\n", retval));
#endif
return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval));
}

View File

@ -916,16 +916,10 @@ class Detector {
void setVetoReference(const int gainIndex, const int value, Positions pos = {});
/** [Gotthard2] */
Result<bool> getBurstMode(Positions pos = {});
Result<defs::burstMode> getBurstMode(Positions pos = {});
/** [Gotthard2] true = burst mode or false = continuous mode */
void setBurstMode(bool enable, Positions pos = {});
/** [Gotthard2] */
Result<defs::burstModeType> getBurstType(Positions pos = {});
/** [Gotthard2] Options: INTERNAL, EXTERNAL */
void setBurstType(defs::burstModeType val, Positions pos = {});
/** [Gotthard2] BURST_OFF, BURST_INTERNAL (default), BURST_EXTERNAL */
void setBurstMode(defs::burstMode value, Positions pos = {});
/**************************************************
* *

View File

@ -1225,6 +1225,51 @@ std::string CmdProxy::VetoReference(int action) {
return os.str();
}
std::string CmdProxy::BurstMode(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[off or 0, internal or 1, external or 2]\n\t[Gotthard2] Default is burst internal type"
<< '\n';
} else {
if (action == defs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto t = det->getBurstMode({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
defs::burstMode t;
try {
int ival = std::stoi(args[0]);
switch (ival) {
case 0:
t = defs::BURST_OFF;
break;
case 1:
t = defs::BURST_INTERNAL;
break;
case 2:
t = defs::BURST_EXTERNAL;
break;
default:
throw sls::RuntimeError("Unknown burst mode " + args[0]);
}
} catch (...) {
t = sls::StringTo<defs::burstMode>(args[0]);
}
det->setBurstMode(t, {det_id});
os << sls::ToString(t) << '\n'; // no args to convert 0,1,2 as well
} else {
throw sls::RuntimeError("Unknown action");
}
}
return os.str();
}
/* Mythen3 Specific */
std::string CmdProxy::Counters(int action) {

View File

@ -787,8 +787,7 @@ class CmdProxy {
{"inj_ch", &CmdProxy::InjectChannel},
{"vetophoton", &CmdProxy::VetoPhoton},
{"vetoref", &CmdProxy::VetoReference},
{"burstmode", &CmdProxy::burstmode},
{"bursttype", &CmdProxy::bursttype},
{"burstmode", &CmdProxy::BurstMode},
/* Mythen3 Specific */
{"counters", &CmdProxy::Counters},
@ -948,6 +947,7 @@ class CmdProxy {
std::string InjectChannel(int action);
std::string VetoPhoton(int action);
std::string VetoReference(int action);
std::string BurstMode(int action);
/* Mythen3 Specific */
std::string Counters(int action);
/* CTB Specific */
@ -1554,12 +1554,6 @@ class CmdProxy {
"[0, 1]\n\t[Gotthard] 1 adds channel intensity with precalculated values when taking an acquisition. Default is 0.");
/* Gotthard2 Specific */
INTEGER_COMMAND(burstmode, getBurstMode, setBurstMode, std::stoi,
"[0, 1]\n\t[Gotthard2] 1 sets to burst mode. 0 sets to continuous mode. Default is burst mode.");
INTEGER_COMMAND(bursttype, getBurstType, setBurstType, sls::StringTo<slsDetectorDefs::burstModeType>,
"[internal, external]\n\t[Gotthard2] Default is internal type.");
/* Mythen3 Specific */
/* CTB Specific */

View File

@ -1180,20 +1180,12 @@ void Detector::setVetoReference(const int gainIndex, const int value, Positions
pimpl->Parallel(&slsDetector::setVetoReference, pos, gainIndex, value);
}
Result<bool> Detector::getBurstMode(Positions pos) {
Result<defs::burstMode> Detector::getBurstMode(Positions pos) {
return pimpl->Parallel(&slsDetector::getBurstMode, pos);
}
void Detector::setBurstMode(bool enable, Positions pos) {
pimpl->Parallel(&slsDetector::setBurstMode, pos, enable);
}
Result<defs::burstModeType> Detector::getBurstType(Positions pos) {
return pimpl->Parallel(&slsDetector::getBurstType, pos);
}
void Detector::setBurstType(defs::burstModeType value, Positions pos) {
pimpl->Parallel(&slsDetector::setBurstType, pos, value);
void Detector::setBurstMode(defs::burstMode value, Positions pos) {
pimpl->Parallel(&slsDetector::setBurstMode, pos, value);
}
// Mythen3 Specific

View File

@ -2476,32 +2476,19 @@ void slsDetector::setVetoReference(const int gainIndex, const int value) {
sendToDetector(F_SET_VETO_REFERENCE, args, nullptr);
}
bool slsDetector::getBurstMode() {
slsDetectorDefs::burstMode slsDetector::getBurstMode() {
int retval = -1;
sendToDetector(F_GET_BURST_MODE, nullptr, retval);
FILE_LOG(logDEBUG1) << "Burst mode:" << retval;
return static_cast<bool>(retval);
return static_cast<slsDetectorDefs::burstMode>(retval);
}
void slsDetector::setBurstMode(bool enable) {
int arg = static_cast<int>(enable);
void slsDetector::setBurstMode(slsDetectorDefs::burstMode value) {
int arg = static_cast<int>(value);
FILE_LOG(logDEBUG1) << "Setting burst mode to " << arg;
sendToDetector(F_SET_BURST_MODE, arg, nullptr);
}
slsDetectorDefs::burstModeType slsDetector::getBurstType() {
int retval = -1;
sendToDetector(F_GET_BURST_TYPE, nullptr, retval);
FILE_LOG(logDEBUG1) << "Burst mode:" << retval;
return static_cast<burstModeType>(retval);
}
void slsDetector::setBurstType (burstModeType val) {
int arg = static_cast<int>(val);
FILE_LOG(logDEBUG1) << "Setting burst type to " << ToString(val);
sendToDetector(F_SET_BURST_TYPE, arg, nullptr);
}
int slsDetector::setCounterBit(int cb) {
int retval = -1;
FILE_LOG(logDEBUG1) << "Sending counter bit " << cb;

View File

@ -1131,17 +1131,11 @@ class slsDetector : public virtual slsDetectorDefs {
void setVetoReference(const int gainIndex, const int value);
/** [Gotthard2] */
bool getBurstMode();
burstMode getBurstMode();
/** [Gotthard2] true = burst mode or false = continuous mode */
void setBurstMode(bool enable);
/** [Gotthard2] */
burstModeType getBurstType();
/** [Gotthard2] Options: INTERNAL, EXTERNAL */
void setBurstType(burstModeType val);
/** [Gotthard2] BURST_OFF, BURST_INTERNAL (default), BURST_EXTERNAL */
void setBurstMode(burstMode value);
/**
* Set/get counter bit in detector (Gotthard)
* @param i is -1 to get, 0 to reset and any other value to set the counter

View File

@ -204,11 +204,13 @@ inline std::string ToString(const defs::detectorModeType s) {
}
}
inline std::string ToString(const defs::burstModeType s) {
inline std::string ToString(const defs::burstMode s) {
switch (s) {
case defs::INTERNAL:
case defs::BURST_OFF:
return std::string("off");
case defs::BURST_INTERNAL:
return std::string("internal");
case defs::EXTERNAL:
case defs::BURST_EXTERNAL:
return std::string("external");
default:
return std::string("Unknown");
@ -562,12 +564,14 @@ inline defs::dacIndex StringTo(const std::string& s) {
}
template <>
inline defs::burstModeType StringTo(const std::string& s) {
inline defs::burstMode StringTo(const std::string& s) {
if (s == "off")
return defs::BURST_OFF;
if (s == "internal")
return defs::INTERNAL;
return defs::BURST_INTERNAL;
if (s == "external")
return defs::EXTERNAL;
throw sls::RuntimeError("Unknown burst mode type" + s);
return defs::BURST_EXTERNAL;
throw sls::RuntimeError("Unknown burst mode " + s);
}

View File

@ -439,11 +439,12 @@ class slsDetectorDefs {
};
/**
* burst mode type for gotthard2
* burst mode for gotthard2
*/
enum burstModeType {
INTERNAL,
EXTERNAL,
enum burstMode {
BURST_OFF,
BURST_INTERNAL,
BURST_EXTERNAL,
};

View File

@ -188,8 +188,6 @@ enum detFuncs{
F_GET_ADC_ENABLE_MASK_10G,
F_SET_COUNTER_MASK,
F_GET_COUNTER_MASK,
F_SET_BURST_TYPE,
F_GET_BURST_TYPE,
NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this (detector server should not compile anyway) */
@ -445,8 +443,6 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_GET_ADC_ENABLE_MASK_10G: return "F_GET_ADC_ENABLE_MASK_10G";
case F_SET_COUNTER_MASK: return "F_SET_COUNTER_MASK";
case F_GET_COUNTER_MASK: return "F_GET_COUNTER_MASK";
case F_SET_BURST_TYPE: return "F_SET_BURST_TYPE";
case F_GET_BURST_TYPE: return "F_GET_BURST_TYPE";
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";

View File

@ -9,4 +9,4 @@
#define APIJUNGFRAU 0x200122
#define APIMYTHEN3 0x200122
#define APIEIGER 0x200122
#define APIGOTTHARD2 0x200122
#define APIGOTTHARD2 0x200123