Line data Source code
1 : /**
2 : * @file FrequencyCounterNode.cpp
3 : *
4 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "timing/FrequencyCounterNode.hpp"
10 :
11 : #include "timing/toolbox.hpp"
12 : #include "logging/Logging.hpp"
13 :
14 : #include <string>
15 : #include <vector>
16 :
17 : namespace dunedaq {
18 : namespace timing {
19 :
20 0 : UHAL_REGISTER_DERIVED_NODE(FrequencyCounterNode)
21 :
22 : //-----------------------------------------------------------------------------
23 0 : FrequencyCounterNode::FrequencyCounterNode(const uhal::Node& node)
24 0 : : TimingNode(node)
25 0 : {}
26 : //-----------------------------------------------------------------------------
27 :
28 : //-----------------------------------------------------------------------------
29 0 : FrequencyCounterNode::~FrequencyCounterNode() {}
30 : //-----------------------------------------------------------------------------
31 :
32 : //-----------------------------------------------------------------------------
33 : std::string
34 0 : FrequencyCounterNode::get_status(bool print_out) const
35 : {
36 0 : std::stringstream status;
37 0 : auto subnodes = read_sub_nodes(getNode("csr.ctrl"));
38 0 : status << format_reg_table(subnodes, "Freq counter state");
39 0 : if (print_out)
40 0 : TLOG() << status.str();
41 0 : return status.str();
42 0 : }
43 : //-----------------------------------------------------------------------------
44 :
45 : //-----------------------------------------------------------------------------
46 : std::vector<double>
47 0 : FrequencyCounterNode::measure_frequencies(uint8_t number_of_clocks) const // NOLINT(build/unsigned)
48 : {
49 0 : std::vector<double> frequencies;
50 :
51 0 : for (uint8_t i = 0; i < number_of_clocks; ++i) { // NOLINT(build/unsigned)
52 0 : getNode("ctrl.chan_sel").write(i);
53 0 : getNode("ctrl.en_crap_mode").write(0);
54 0 : getClient().dispatch();
55 :
56 0 : millisleep(2000);
57 :
58 0 : uhal::ValWord<uint32_t> frequency = getNode("freq.count").read(); // NOLINT(build/unsigned)
59 0 : uhal::ValWord<uint32_t> frequency_valid = getNode("freq.valid").read(); // NOLINT(build/unsigned)
60 0 : getClient().dispatch();
61 :
62 0 : if (frequency_valid.value()) {
63 0 : double freq = frequency.value() * 119.20928 / 1000000;
64 0 : frequencies.push_back(freq);
65 : } else {
66 0 : frequencies.push_back(-1);
67 : }
68 0 : }
69 0 : return frequencies;
70 0 : }
71 : //-----------------------------------------------------------------------------
72 :
73 : } // namespace timing
74 : } // namespace dunedaq
|