CTB frequency rounding, CTB frequency measurement, CTB frequency units (#1423)

* round CTB clocks to next closest possible value, added freq measurement

* added time for firmware to measrue actual value after frequency change

* add check for backwards compatibility

* change CTB and XCTB clock values to MHz, TODO: units and validation errors

* changed runclk command to use units and float, TODO: dbit, adcclk, why is everything called StringTo ?

* do the same for dbit and adcclk

* added tolerance to exptime, fixed test

* update default values in server defs

* added virtual check in Altera_PLL, update testcases

* change python and pyctbgui to accept and return floating point MHz

* update help and comments

* Dev/ctb clocks fix (#1434)

* introduced new type Hz, typetraits, String conversions, command generation (not yet generated)

* incorrect unit typo

* cmd generation and compiles

* default to MHz, removed space between units for consistency with timers, min and max checks for clks

* in python, but need to change the default to Hz again for clean code and intuition

* allow ints, doubles, implicit conversions

* dont allow raw ints, doubles and implicit conversions

* fixed tests

* added operators for Hz in python

* fix test for min clk for xilinx ctb

* fix test

* fix python tests

* fixed xilinx period and default clks

* test fix

* removed the 3 clock cycle check for ctb and implemented properly the max adc clk frq for altera ctb

* removing 3 clock cycle code from xilinx as well

* formatting

* loadpattern before 3 clk cycles code

* actualtime and measurement time to be implemented in 100ns already in fw

* fix tests

* pyzmq dependency forthe tests

* fixed pyctbgui for freq

* insert tolerance check again

* also added tolerance check for patwaittime

* formatting

* minor: rounding test

* removed Rep redundant in ToString for freq

* intro frequency unit enums, removed unnecessary template behavior for ToString with freq unit, switching from parsing string unit argument to the enum argument for ToString, adding parsing string to unit at CLI boundary

* minor, and binaries

* minor, default clk vals are 0 but set up at detector setup

* get frequency only for that unit

* tolerance process

* missed in previous commit

* some more changes to exptime and validations

* ctb is probably done

* periodleft and delayleft

* fixed xilinx freq conv as well

* fixed m3 bug, binaries

* xilinx: setup also done in stop server so that the clk is not 0

* missed a test marker

* binaries in

* review fixes, simpler validation of timers in ctb and xilinx ctb

* typo fix

* format

* fix tests

---------

Co-authored-by: Martin Mueller <martin.mueller@psi.ch>
Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
This commit is contained in:
Martin Mueller
2026-05-06 15:52:13 +02:00
committed by GitHub
co-authored by GitHub muelle_m1 maliakal_d
parent bb1a73d718
commit 0837de2a5a
57 changed files with 2239 additions and 706 deletions
+117 -34
View File
@@ -72,34 +72,46 @@ std::string Caller::adcclk(int action) {
std::ostringstream os;
// print help
if (action == slsDetectorDefs::HELP_ACTION) {
os << R"V0G0N([n_clk in MHz]
[Ctb] ADC clock frequency in MHz.
[xilinx Ctb] ADC clock frequency in kHz. )V0G0N"
os << R"V0G0N([n_clk] [(optional unit) Hz(default)|kHz|MHz]
[Ctb][Xilinx Ctb] ADC clock frequency. )V0G0N"
<< std::endl;
return os.str();
}
// check if action and arguments are valid
if (action == slsDetectorDefs::GET_ACTION) {
if (1 && args.size() != 0) {
if (1 && args.size() != 0 && args.size() != 1) {
throw RuntimeError("Wrong number of arguments for action GET");
}
if (args.size() == 0) {
}
if (args.size() == 1) {
}
}
else if (action == slsDetectorDefs::PUT_ACTION) {
if (1 && args.size() != 1) {
if (1 && args.size() != 1 && args.size() != 2) {
throw RuntimeError("Wrong number of arguments for action PUT");
}
if (args.size() == 1) {
try {
StringTo<int>(args[0]);
std::string tmp_freq(args[0]);
std::string unit = RemoveUnit(tmp_freq);
auto converted_freq = StringTo<defs::Hz>(tmp_freq, unit);
} catch (...) {
throw RuntimeError("Could not convert argument 0 to int");
throw RuntimeError("Could not convert argument to defs::Hz");
}
}
if (args.size() == 2) {
try {
StringTo<defs::Hz>(args[0], args[1]);
} catch (...) {
throw RuntimeError("Could not convert arguments to defs::Hz");
}
}
@@ -117,13 +129,26 @@ std::string Caller::adcclk(int action) {
auto t = det->getADCClock(std::vector<int>{det_id});
os << OutString(t) << '\n';
}
if (args.size() == 1) {
auto t = det->getADCClock(std::vector<int>{det_id});
os << OutString(t, args[0]) << '\n';
}
}
if (action == slsDetectorDefs::PUT_ACTION) {
if (args.size() == 1) {
auto arg0 = StringTo<int>(args[0]);
det->setADCClock(arg0, std::vector<int>{det_id});
os << args.front() << '\n';
std::string tmp_freq(args[0]);
std::string unit = RemoveUnit(tmp_freq);
auto converted_freq = StringTo<defs::Hz>(tmp_freq, unit);
det->setADCClock(converted_freq, std::vector<int>{det_id});
os << args[0] << '\n';
}
if (args.size() == 2) {
auto converted_freq = StringTo<defs::Hz>(args[0], args[1]);
det->setADCClock(converted_freq, std::vector<int>{det_id});
os << args[0] << args[1] << '\n';
}
}
@@ -2482,34 +2507,46 @@ std::string Caller::dbitclk(int action) {
std::ostringstream os;
// print help
if (action == slsDetectorDefs::HELP_ACTION) {
os << R"V0G0N([n_clk in MHz]
[Ctb] Clock for latching the digital bits in MHz.
[xilinx Ctb] Clock for latching the digital bits in kHz. )V0G0N"
os << R"V0G0N([n_clk] [(optional unit) Hz(default)|kHz|MHz]
[Ctb][Xilinx Ctb] Clock for latching the digital bits. )V0G0N"
<< std::endl;
return os.str();
}
// check if action and arguments are valid
if (action == slsDetectorDefs::GET_ACTION) {
if (1 && args.size() != 0) {
if (1 && args.size() != 0 && args.size() != 1) {
throw RuntimeError("Wrong number of arguments for action GET");
}
if (args.size() == 0) {
}
if (args.size() == 1) {
}
}
else if (action == slsDetectorDefs::PUT_ACTION) {
if (1 && args.size() != 1) {
if (1 && args.size() != 1 && args.size() != 2) {
throw RuntimeError("Wrong number of arguments for action PUT");
}
if (args.size() == 1) {
try {
StringTo<int>(args[0]);
std::string tmp_freq(args[0]);
std::string unit = RemoveUnit(tmp_freq);
auto converted_freq = StringTo<defs::Hz>(tmp_freq, unit);
} catch (...) {
throw RuntimeError("Could not convert argument 0 to int");
throw RuntimeError("Could not convert argument to defs::Hz");
}
}
if (args.size() == 2) {
try {
StringTo<defs::Hz>(args[0], args[1]);
} catch (...) {
throw RuntimeError("Could not convert arguments to defs::Hz");
}
}
@@ -2527,13 +2564,26 @@ std::string Caller::dbitclk(int action) {
auto t = det->getDBITClock(std::vector<int>{det_id});
os << OutString(t) << '\n';
}
if (args.size() == 1) {
auto t = det->getDBITClock(std::vector<int>{det_id});
os << OutString(t, args[0]) << '\n';
}
}
if (action == slsDetectorDefs::PUT_ACTION) {
if (args.size() == 1) {
auto arg0 = StringTo<int>(args[0]);
det->setDBITClock(arg0, std::vector<int>{det_id});
os << args.front() << '\n';
std::string tmp_freq(args[0]);
std::string unit = RemoveUnit(tmp_freq);
auto converted_freq = StringTo<defs::Hz>(tmp_freq, unit);
det->setDBITClock(converted_freq, std::vector<int>{det_id});
os << args[0] << '\n';
}
if (args.size() == 2) {
auto converted_freq = StringTo<defs::Hz>(args[0], args[1]);
det->setDBITClock(converted_freq, std::vector<int>{det_id});
os << args[0] << args[1] << '\n';
}
}
@@ -7312,7 +7362,7 @@ std::string Caller::patfname(int action) {
// generate code for each action
if (action == slsDetectorDefs::GET_ACTION) {
if (args.size() == 0) {
auto t = det->getPatterFileName(std::vector<int>{det_id});
auto t = det->getPatternFileName(std::vector<int>{det_id});
os << OutString(t) << '\n';
}
}
@@ -9909,34 +9959,46 @@ std::string Caller::runclk(int action) {
std::ostringstream os;
// print help
if (action == slsDetectorDefs::HELP_ACTION) {
os << R"V0G0N([n_clk in MHz]
[Ctb] Run clock in MHz.
[xilinx Ctb] Run clock in kHz. )V0G0N"
os << R"V0G0N([n_clk] [(optional unit) Hz(default)|kHz|MHz]
[Ctb][Xilinx Ctb] Run clock frequency. )V0G0N"
<< std::endl;
return os.str();
}
// check if action and arguments are valid
if (action == slsDetectorDefs::GET_ACTION) {
if (1 && args.size() != 0) {
if (1 && args.size() != 0 && args.size() != 1) {
throw RuntimeError("Wrong number of arguments for action GET");
}
if (args.size() == 0) {
}
if (args.size() == 1) {
}
}
else if (action == slsDetectorDefs::PUT_ACTION) {
if (1 && args.size() != 1) {
if (1 && args.size() != 1 && args.size() != 2) {
throw RuntimeError("Wrong number of arguments for action PUT");
}
if (args.size() == 1) {
try {
StringTo<int>(args[0]);
std::string tmp_freq(args[0]);
std::string unit = RemoveUnit(tmp_freq);
auto converted_freq = StringTo<defs::Hz>(tmp_freq, unit);
} catch (...) {
throw RuntimeError("Could not convert argument 0 to int");
throw RuntimeError("Could not convert argument to defs::Hz");
}
}
if (args.size() == 2) {
try {
StringTo<defs::Hz>(args[0], args[1]);
} catch (...) {
throw RuntimeError("Could not convert arguments to defs::Hz");
}
}
@@ -9954,13 +10016,26 @@ std::string Caller::runclk(int action) {
auto t = det->getRUNClock(std::vector<int>{det_id});
os << OutString(t) << '\n';
}
if (args.size() == 1) {
auto t = det->getRUNClock(std::vector<int>{det_id});
os << OutString(t, args[0]) << '\n';
}
}
if (action == slsDetectorDefs::PUT_ACTION) {
if (args.size() == 1) {
auto arg0 = StringTo<int>(args[0]);
det->setRUNClock(arg0, std::vector<int>{det_id});
os << args.front() << '\n';
std::string tmp_freq(args[0]);
std::string unit = RemoveUnit(tmp_freq);
auto converted_freq = StringTo<defs::Hz>(tmp_freq, unit);
det->setRUNClock(converted_freq, std::vector<int>{det_id});
os << args[0] << '\n';
}
if (args.size() == 2) {
auto converted_freq = StringTo<defs::Hz>(args[0], args[1]);
det->setRUNClock(converted_freq, std::vector<int>{det_id});
os << args[0] << args[1] << '\n';
}
}
@@ -13062,21 +13137,24 @@ std::string Caller::syncclk(int action) {
std::ostringstream os;
// print help
if (action == slsDetectorDefs::HELP_ACTION) {
os << R"V0G0N([n_clk in MHz]
[Ctb] Sync clock in MHz. )V0G0N"
os << R"V0G0N([n_clk] [(optional unit) Hz(default)|kHz|MHz]
[Ctb] Sync clock. )V0G0N"
<< std::endl;
return os.str();
}
// check if action and arguments are valid
if (action == slsDetectorDefs::GET_ACTION) {
if (1 && args.size() != 0) {
if (1 && args.size() != 0 && args.size() != 1) {
throw RuntimeError("Wrong number of arguments for action GET");
}
if (args.size() == 0) {
}
if (args.size() == 1) {
}
}
else {
@@ -13091,6 +13169,11 @@ std::string Caller::syncclk(int action) {
auto t = det->getSYNCClock(std::vector<int>{det_id});
os << OutString(t) << '\n';
}
if (args.size() == 1) {
auto t = det->getSYNCClock(std::vector<int>{det_id});
os << OutString(t, args[0]) << '\n';
}
}
return os.str();