This commit is contained in:
maliakal_d 2020-05-19 18:59:07 +02:00
parent cd90f09a30
commit e208d3ebe8
7 changed files with 97 additions and 71 deletions

View File

@ -846,7 +846,7 @@ void setNumGates(int val) {
} }
} }
int getNumExtGates() { return bus_r(ASIC_EXP_EXT_GATE_NUMBER_REG); } int getNumGates() { return bus_r(ASIC_EXP_EXT_GATE_NUMBER_REG); }
void updateGatePeriod() { void updateGatePeriod() {
uint64_t max = 0; uint64_t max = 0;
@ -863,21 +863,27 @@ void updateGatePeriod() {
ASIC_EXP_GATE_PERIOD_MSB_REG); ASIC_EXP_GATE_PERIOD_MSB_REG);
} }
int setExptime(int gateIndex, int64_t val) { int64_t getGatePeriod() {
return get64BitReg(ASIC_EXP_GATE_PERIOD_LSB_REG,
ASIC_EXP_GATE_PERIOD_MSB_REG) /
(1E-9 * getFrequency(SYSTEM_C2));
}
int setExpTime(int gateIndex, int64_t val) {
uint32_t alsb = 0; uint32_t alsb = 0;
uint32_t amsb = 0; uint32_t amsb = 0;
switch (gateIndex) { switch (gateIndex) {
case 0: case 0:
alsb = ASIC_EXP_GATE_0_WIDTH_LSB_REG; alsb = ASIC_EXP_GATE_0_WIDTH_LSB_REG;
blsb = ASIC_EXP_GATE_0_WIDTH_MSB_REG; amsb = ASIC_EXP_GATE_0_WIDTH_MSB_REG;
break; break;
case 1: case 1:
alsb = ASIC_EXP_GATE_1_WIDTH_LSB_REG; alsb = ASIC_EXP_GATE_1_WIDTH_LSB_REG;
blsb = ASIC_EXP_GATE_1_WIDTH_MSB_REG; amsb = ASIC_EXP_GATE_1_WIDTH_MSB_REG;
break; break;
case 2: case 2:
alsb = ASIC_EXP_GATE_2_WIDTH_LSB_REG; alsb = ASIC_EXP_GATE_2_WIDTH_LSB_REG;
blsb = ASIC_EXP_GATE_2_WIDTH_MSB_REG; amsb = ASIC_EXP_GATE_2_WIDTH_MSB_REG;
break; break;
default: default:
LOG(logERROR, ("Invalid gate index: %d\n", gateIndex)); LOG(logERROR, ("Invalid gate index: %d\n", gateIndex));
@ -905,19 +911,21 @@ int setExptime(int gateIndex, int64_t val) {
return OK; return OK;
} }
int64_t getExptime(int gateIndex) { int64_t getExpTime(int gateIndex) {
uint32_t alsb = 0;
uint32_t amsb = 0;
switch (gateIndex) { switch (gateIndex) {
case 0: case 0:
alsb = ASIC_EXP_GATE_0_WIDTH_LSB_REG; alsb = ASIC_EXP_GATE_0_WIDTH_LSB_REG;
blsb = ASIC_EXP_GATE_0_WIDTH_MSB_REG; amsb = ASIC_EXP_GATE_0_WIDTH_MSB_REG;
break; break;
case 1: case 1:
alsb = ASIC_EXP_GATE_1_WIDTH_LSB_REG; alsb = ASIC_EXP_GATE_1_WIDTH_LSB_REG;
blsb = ASIC_EXP_GATE_1_WIDTH_MSB_REG; amsb = ASIC_EXP_GATE_1_WIDTH_MSB_REG;
break; break;
case 2: case 2:
alsb = ASIC_EXP_GATE_2_WIDTH_LSB_REG; alsb = ASIC_EXP_GATE_2_WIDTH_LSB_REG;
blsb = ASIC_EXP_GATE_2_WIDTH_MSB_REG; amsb = ASIC_EXP_GATE_2_WIDTH_MSB_REG;
break; break;
default: default:
LOG(logERROR, ("Invalid gate index: %d\n", gateIndex)); LOG(logERROR, ("Invalid gate index: %d\n", gateIndex));
@ -932,15 +940,15 @@ int setGateDelay(int gateIndex, int64_t val) {
switch (gateIndex) { switch (gateIndex) {
case 0: case 0:
alsb = ASIC_EXP_GATE_0_DELAY_LSB_REG; alsb = ASIC_EXP_GATE_0_DELAY_LSB_REG;
blsb = ASIC_EXP_GATE_0_DELAY_MSB_REG; amsb = ASIC_EXP_GATE_0_DELAY_MSB_REG;
break; break;
case 1: case 1:
alsb = ASIC_EXP_GATE_1_DELAY_LSB_REG; alsb = ASIC_EXP_GATE_1_DELAY_LSB_REG;
blsb = ASIC_EXP_GATE_1_DELAY_MSB_REG; amsb = ASIC_EXP_GATE_1_DELAY_MSB_REG;
break; break;
case 2: case 2:
alsb = ASIC_EXP_GATE_2_DELAY_LSB_REG; alsb = ASIC_EXP_GATE_2_DELAY_LSB_REG;
blsb = ASIC_EXP_GATE_2_DELAY_MSB_REG; amsb = ASIC_EXP_GATE_2_DELAY_MSB_REG;
break; break;
default: default:
LOG(logERROR, ("Invalid gate index: %d\n", gateIndex)); LOG(logERROR, ("Invalid gate index: %d\n", gateIndex));
@ -969,18 +977,20 @@ int setGateDelay(int gateIndex, int64_t val) {
} }
int64_t getGateDelay(int gateIndex) { int64_t getGateDelay(int gateIndex) {
uint32_t alsb = 0;
uint32_t amsb = 0;
switch (gateIndex) { switch (gateIndex) {
case 0: case 0:
alsb = ASIC_EXP_GATE_0_DELAY_LSB_REG; alsb = ASIC_EXP_GATE_0_DELAY_LSB_REG;
blsb = ASIC_EXP_GATE_0_DELAY_MSB_REG; amsb = ASIC_EXP_GATE_0_DELAY_MSB_REG;
break; break;
case 1: case 1:
alsb = ASIC_EXP_GATE_1_DELAY_LSB_REG; alsb = ASIC_EXP_GATE_1_DELAY_LSB_REG;
blsb = ASIC_EXP_GATE_1_DELAY_MSB_REG; amsb = ASIC_EXP_GATE_1_DELAY_MSB_REG;
break; break;
case 2: case 2:
alsb = ASIC_EXP_GATE_2_DELAY_LSB_REG; alsb = ASIC_EXP_GATE_2_DELAY_LSB_REG;
blsb = ASIC_EXP_GATE_2_DELAY_MSB_REG; amsb = ASIC_EXP_GATE_2_DELAY_MSB_REG;
break; break;
default: default:
LOG(logERROR, ("Invalid gate index: %d\n", gateIndex)); LOG(logERROR, ("Invalid gate index: %d\n", gateIndex));
@ -1205,16 +1215,6 @@ void setTiming(enum timingMode arg) {
LOG(logERROR, ("Unknown timing mode %d\n", arg)); LOG(logERROR, ("Unknown timing mode %d\n", arg));
return; return;
} }
// internal gating
if (arg == AUTO_TIMING || arg == TRIGGER_EXPOSURE) {
setNumGates(1); // should be in firmware
// TOOD: number of counters-> set appropriate gatewidth and
// gatedelay to 0
setMaxGatePulseWidth();
}
// external gating
else {
}
} }
} }
@ -1942,7 +1942,7 @@ void *start_timer(void *arg) {
int64_t periodNs = getPeriod(); int64_t periodNs = getPeriod();
int numFrames = (getNumFrames() * getNumTriggers()); int numFrames = (getNumFrames() * getNumTriggers());
int64_t expUs = getExpTime() / 1000; int64_t expUs = getGatePeriod() / 1000;
// int dr = setDynamicRange(-1); // int dr = setDynamicRange(-1);
int imagesize = calculateDataBytes(); int imagesize = calculateDataBytes();

View File

@ -214,8 +214,10 @@ int64_t getPeriod();
void setNumIntGates(int val); void setNumIntGates(int val);
void setNumGates(int val); void setNumGates(int val);
int getNumGates(); int getNumGates();
int setExptime(int gateIndex, int64_t val); void updateGatePeriod();
int64_t getExptime(int gateIndex); int64_t getGatePeriod();
int setExpTime(int gateIndex, int64_t val);
int64_t getExpTime(int gateIndex);
int setGateDelay(int gateIndex, int64_t val); int setGateDelay(int gateIndex, int64_t val);
int64_t getGateDelay(int gateIndex); int64_t getGateDelay(int gateIndex);
#endif #endif

View File

@ -329,12 +329,12 @@ void function_table() {
flist[F_UPDATE_RATE_CORRECTION] = &update_rate_correction; flist[F_UPDATE_RATE_CORRECTION] = &update_rate_correction;
flist[F_GET_RECEIVER_PARAMETERS] = &get_receiver_parameters; flist[F_GET_RECEIVER_PARAMETERS] = &get_receiver_parameters;
flist[F_START_PATTERN] = &start_pattern; flist[F_START_PATTERN] = &start_pattern;
FLIST[F_SET_NUM_GATES] = &set_num_gates; flist[F_SET_NUM_GATES] = &set_num_gates;
FLIST[F_GET_NUM_GATES] = &get_num_gates; flist[F_GET_NUM_GATES] = &get_num_gates;
FLIST[F_SET_GATE_DELAY] = &set_gate_delay; flist[F_SET_GATE_DELAY] = &set_gate_delay;
FLIST[F_GET_GATE_DELAY] = &get_gate_delay; flist[F_GET_GATE_DELAY] = &get_gate_delay;
flist[F_GET_EXPTIME_ALL_GATES = &get_exptime_all_gates; flist[F_GET_EXPTIME_ALL_GATES] = &get_exptime_all_gates;
flist[F_GET_GATE_DELAY_ALL_GATES = &get_gate_delay_all_gates; flist[F_GET_GATE_DELAY_ALL_GATES] = &get_gate_delay_all_gates;
// check // check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -2107,7 +2107,7 @@ int get_exptime(int file_des) {
gateIndex); gateIndex);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else { } else {
retval = getExptime(gateIndex); retval = getExpTime(gateIndex);
LOG(logDEBUG1, ("retval exptime %lld ns\n", (long long int)retval)); LOG(logDEBUG1, ("retval exptime %lld ns\n", (long long int)retval));
} }
#else #else
@ -6953,8 +6953,12 @@ int get_receiver_parameters(int file_des) {
if (n < 0) if (n < 0)
return printSocketReadError(); return printSocketReadError();
// exptime // exptime
#ifdef MYTHEN3D
i64 = getExpTime(0);
#else
i64 = getExpTime(); i64 = getExpTime();
#endif
n += sendData(file_des, &i64, sizeof(i64), INT64); n += sendData(file_des, &i64, sizeof(i64), INT64);
if (n < 0) if (n < 0)
return printSocketReadError(); return printSocketReadError();
@ -7212,6 +7216,7 @@ int set_gate_delay(int file_des) {
} }
} }
} }
}
#endif #endif
return Server_SendResult(file_des, INT64, NULL, 0); return Server_SendResult(file_des, INT64, NULL, 0);
} }
@ -7228,19 +7233,18 @@ int get_gate_delay(int file_des) {
#if !defined(MYTHEN3D) #if !defined(MYTHEN3D)
functionNotImplemented(); functionNotImplemented();
#else #else
// get only // get only
if (gateIndex < 0 || gateIndex > 2) { if (gateIndex < 0 || gateIndex > 2) {
ret = FAIL; ret = FAIL;
sprintf(mess, sprintf(mess,
"Could not set gate delay. Invalid gate index %d. " "Could not set gate delay. Invalid gate index %d. "
"Options [0-2]\n", "Options [0-2]\n",
gateIndex); gateIndex);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else { } else {
retval = getGateDelay(gateIndex); retval = getGateDelay(gateIndex);
LOG(logDEBUG1, LOG(logDEBUG1, ("retval gate delay %lld ns\n", (long long int)retval));
("retval gate delay %lld ns\n", (long long int)retval)); }
}
#endif #endif
return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
} }
@ -7253,11 +7257,11 @@ int get_exptime_all_gates(int file_des) {
#if !defined(MYTHEN3D) #if !defined(MYTHEN3D)
functionNotImplemented(); functionNotImplemented();
#else #else
for (int i = 0; i != 2; ++i) { for (int i = 0; i != 2; ++i) {
retvals[i] = getExpTime(i); retvals[i] = getExpTime(i);
LOG(logDEBUG1, ("retval exptime %lld ns (index:%d)\n", LOG(logDEBUG1, ("retval exptime %lld ns (index:%d)\n",
(long long int)retvals[i], i)); (long long int)retvals[i], i));
} }
#endif #endif
return Server_SendResult(file_des, INT64, retvals, sizeof(retvals)); return Server_SendResult(file_des, INT64, retvals, sizeof(retvals));
} }
@ -7270,11 +7274,11 @@ int get_gate_delay_all_gates(int file_des) {
#if !defined(MYTHEN3D) #if !defined(MYTHEN3D)
functionNotImplemented(); functionNotImplemented();
#else #else
for (int i = 0; i != 2; ++i) { for (int i = 0; i != 2; ++i) {
retvals[i] = getGateDelay(i); retvals[i] = getGateDelay(i);
LOG(logDEBUG1, ("retval gate delay %lld ns (index:%d)\n", LOG(logDEBUG1, ("retval gate delay %lld ns (index:%d)\n",
(long long int)retvals[i], i)); (long long int)retvals[i], i));
} }
#endif #endif
return Server_SendResult(file_des, INT64, retvals, sizeof(retvals)); return Server_SendResult(file_des, INT64, retvals, sizeof(retvals));
} }

View File

@ -381,7 +381,7 @@ std::string CmdProxy::Exptime(int action) {
WrongNumberOfParameters(1); WrongNumberOfParameters(1);
} }
// vector of exptimes // vector of exptimes
if (gateIndex == -1 & if (gateIndex == -1 &&
det->getDetectorType().squash() == defs::MYTHEN3) { det->getDetectorType().squash() == defs::MYTHEN3) {
auto t = det->getExptimeForAllGates({det_id}); auto t = det->getExptimeForAllGates({det_id});
if (args.size() == 0) { if (args.size() == 0) {
@ -410,14 +410,14 @@ std::string CmdProxy::Exptime(int action) {
std::string time_str(args[0]); std::string time_str(args[0]);
std::string unit = RemoveUnit(time_str); std::string unit = RemoveUnit(time_str);
auto t = StringTo<time::ns>(time_str, unit); auto t = StringTo<time::ns>(time_str, unit);
if (type == MYTHEN3) { if (type == defs::MYTHEN3) {
det->setExptime(gateIndex, t, {det_id}); det->setExptime(gateIndex, t, {det_id});
} else { } else {
det->setExptime(t, {det_id}); det->setExptime(t, {det_id});
} }
} else if (args.size() == 2) { } else if (args.size() == 2) {
auto t = StringTo<time::ns>(args[0], args[1]); auto t = StringTo<time::ns>(args[0], args[1]);
if (type == MYTHEN3) { if (type == defs::MYTHEN3) {
det->setExptime(gateIndex, t, {det_id}); det->setExptime(gateIndex, t, {det_id});
} else { } else {
det->setExptime(t, {det_id}); det->setExptime(t, {det_id});
@ -434,6 +434,7 @@ std::string CmdProxy::Exptime(int action) {
} else { } else {
throw sls::RuntimeError("Unknown action"); throw sls::RuntimeError("Unknown action");
} }
return os.str();
} }
std::string CmdProxy::Speed(int action) { std::string CmdProxy::Speed(int action) {
@ -1777,6 +1778,7 @@ std::string CmdProxy::GateDelay(int action) {
} else { } else {
throw sls::RuntimeError("Unknown action"); throw sls::RuntimeError("Unknown action");
} }
return os.str();
} }
/* CTB / Moench Specific */ /* CTB / Moench Specific */

View File

@ -1275,7 +1275,14 @@ void Detector::setExptime(int gateIndex, ns t, Positions pos) {
} }
Result<std::array<ns, 3>> Detector::getExptimeForAllGates(Positions pos) const { Result<std::array<ns, 3>> Detector::getExptimeForAllGates(Positions pos) const {
return pimpl->Parallel(&Module::getExptimeForAllGates, pos); auto t = pimpl->Parallel(&Module::getExptimeForAllGates, pos);
Result<std::array<ns, 3>> res(t.size());
for (unsigned int i = 0; i < t.size(); ++i) {
for (unsigned int j = 0; j != 3; ++j) {
res[i][j] = static_cast<ns>(t[i][j]);
}
}
return res;
} }
Result<ns> Detector::getGateDelay(int gateIndex, Positions pos) const { Result<ns> Detector::getGateDelay(int gateIndex, Positions pos) const {
@ -1288,7 +1295,14 @@ void Detector::setGateDelay(int gateIndex, ns t, Positions pos) {
Result<std::array<ns, 3>> Result<std::array<ns, 3>>
Detector::getGateDelayForAllGates(Positions pos) const { Detector::getGateDelayForAllGates(Positions pos) const {
return pimpl->Parallel(&Module::getGateDelayForAllGates, pos); auto t = pimpl->Parallel(&Module::getGateDelayForAllGates, pos);
Result<std::array<ns, 3>> res(t.size());
for (unsigned int i = 0; i < t.size(); ++i) {
for (unsigned int j = 0; j != 3; ++j) {
res[i][j] = static_cast<ns>(t[i][j]);
}
}
return res;
} }
// CTB/ Moench Specific // CTB/ Moench Specific

View File

@ -1041,7 +1041,7 @@ int64_t Module::getExptime(int gateIndex) {
void Module::setExptime(int gateIndex, int64_t value) { void Module::setExptime(int gateIndex, int64_t value) {
int64_t prevVal = value; int64_t prevVal = value;
if (shm()->myDetectorType == EIGER) { if (shm()->myDetectorType == EIGER) {
prevVal = getExptime(); prevVal = getExptime(-1);
} }
LOG(logDEBUG1) << "Setting exptime to " << value LOG(logDEBUG1) << "Setting exptime to " << value
<< "ns (gateindex: " << gateIndex << ")"; << "ns (gateindex: " << gateIndex << ")";
@ -1056,8 +1056,10 @@ void Module::setExptime(int gateIndex, int64_t value) {
} }
} }
std::array<int, 3> Module::getExptimeForAllGates() { std::array<int64_t, 3> Module::getExptimeForAllGates() {
return sendToDetector<int64_t>(F_GET_EXPTIME_ALL_GATES); std::array<int64_t, 3> retval;
sendToDetector(F_GET_EXPTIME_ALL_GATES, nullptr, retval);
return retval;
} }
int64_t Module::getGateDelay(int gateIndex) { int64_t Module::getGateDelay(int gateIndex) {
@ -1071,8 +1073,10 @@ void Module::setGateDelay(int gateIndex, int64_t value) {
sendToDetector(F_SET_GATE_DELAY, args, nullptr); sendToDetector(F_SET_GATE_DELAY, args, nullptr);
} }
std::array<int, 3> Module::getGateDelayForAllGates() { std::array<int64_t, 3> Module::getGateDelayForAllGates() {
return sendToDetector<int64_t>(F_GET_GATE_DELAY_ALL_GATES); std::array<int64_t, 3> retval;
sendToDetector(F_GET_GATE_DELAY_ALL_GATES, nullptr, retval);
return retval;
} }
int64_t Module::getPeriod() { return sendToDetector<int64_t>(F_GET_PERIOD); } int64_t Module::getPeriod() { return sendToDetector<int64_t>(F_GET_PERIOD); }

View File

@ -432,7 +432,7 @@ class Module : public virtual slsDetectorDefs {
void setExptime(int gateIndex, int64_t value); void setExptime(int gateIndex, int64_t value);
/** [Mythen3] for all gates */ /** [Mythen3] for all gates */
std::array<int, 3> getExptimeForAllGates(); std::array<int64_t, 3> getExptimeForAllGates();
/** [Mythen3] gatIndex: 0-2 */ /** [Mythen3] gatIndex: 0-2 */
int64_t getGateDelay(int gateIndex); int64_t getGateDelay(int gateIndex);
@ -441,7 +441,7 @@ class Module : public virtual slsDetectorDefs {
void setGateDelay(int gateIndex, int64_t value); void setGateDelay(int gateIndex, int64_t value);
/** [Mythen3] for all gates */ /** [Mythen3] for all gates */
std::array<int, 3> getGateDelayForAllGates(); std::array<int64_t, 3> getGateDelayForAllGates();
int64_t getPeriod(); int64_t getPeriod();