Line data Source code
1 : /**
2 : * @file EchoMonitorNode.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/EchoMonitorNode.hpp"
10 :
11 : #include "timing/TimingIssues.hpp"
12 : #include "timing/toolbox.hpp"
13 : #include "logging/Logging.hpp"
14 :
15 : #include <string>
16 : #include <chrono>
17 :
18 : namespace dunedaq {
19 : namespace timing {
20 :
21 0 : UHAL_REGISTER_DERIVED_NODE(EchoMonitorNode)
22 :
23 : //-----------------------------------------------------------------------------
24 0 : EchoMonitorNode::EchoMonitorNode(const uhal::Node& node)
25 0 : : TimingNode(node)
26 0 : {}
27 : //-----------------------------------------------------------------------------
28 :
29 : //-----------------------------------------------------------------------------
30 0 : EchoMonitorNode::~EchoMonitorNode() {}
31 : //-----------------------------------------------------------------------------
32 :
33 : //-----------------------------------------------------------------------------
34 : std::string
35 0 : EchoMonitorNode::get_status(bool print_out) const
36 : {
37 0 : std::stringstream status;
38 0 : auto subnodes = read_sub_nodes(getNode("csr.stat"));
39 0 : status << format_reg_table(subnodes, "Echo mon state");
40 0 : if (print_out)
41 0 : TLOG() << status.str();
42 0 : return status.str();
43 0 : }
44 : //-----------------------------------------------------------------------------
45 :
46 : //-----------------------------------------------------------------------------
47 : uint64_t // NOLINT(build/unsigned)
48 0 : EchoMonitorNode::send_echo_and_measure_delay(int64_t timeout) const
49 : {
50 :
51 0 : getNode("csr.ctrl.go").write(0x1);
52 0 : getClient().dispatch();
53 :
54 0 : auto start = std::chrono::high_resolution_clock::now();
55 :
56 0 : uhal::ValWord<uint32_t> done; // NOLINT(build/unsigned)
57 0 : uhal::ValWord<uint32_t> delta_t;
58 :
59 0 : while (true) {
60 :
61 0 : done = getNode("csr.stat.rx_done").read();
62 0 : delta_t = getNode("csr.stat.deltat").read();
63 0 : getClient().dispatch();
64 :
65 0 : TLOG_DEBUG(6) << "rx done: " << done.value() << ", delta_t: " << delta_t.value();
66 :
67 0 : if (done.value())
68 : {
69 0 : if (delta_t.value() == 0xffff)
70 : {
71 0 : throw EchoReplyTimeout(ERS_HERE);
72 : }
73 : else
74 : {
75 : break;
76 : }
77 : }
78 :
79 0 : auto now = std::chrono::high_resolution_clock::now();
80 0 : auto ms_since_start = std::chrono::duration_cast<std::chrono::milliseconds>(now - start);
81 :
82 0 : if (ms_since_start.count() > timeout)
83 0 : throw EchoFlagTimeout(ERS_HERE, timeout);
84 :
85 0 : std::this_thread::sleep_for(std::chrono::microseconds(10));
86 0 : }
87 :
88 0 : TLOG_DEBUG(4) << "delta t: " << format_reg_value(delta_t.value(), 10);
89 :
90 0 : return delta_t.value();
91 0 : }
92 : //-----------------------------------------------------------------------------
93 :
94 : } // namespace timing
95 : } // namespace dunedaq
|