DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
MasterGlobalNode.cpp
Go to the documentation of this file.
1
10
11#include "logging/Logging.hpp"
12
13#include <string>
14
15namespace dunedaq {
16namespace timing {
17
18UHAL_REGISTER_DERIVED_NODE(MasterGlobalNode)
19
20//-----------------------------------------------------------------------------
22 : TimingNode(node)
23{}
24//-----------------------------------------------------------------------------
25
26//-----------------------------------------------------------------------------
28//-----------------------------------------------------------------------------
29
30//-----------------------------------------------------------------------------
31std::string
32MasterGlobalNode::get_status(bool print_out) const
33{
34 std::stringstream status;
35 auto ctrl = read_sub_nodes(getNode("csr.ctrl"));
36 status << format_reg_table(ctrl, "Master global controls");
37
38 auto stat = read_sub_nodes(getNode("csr.stat"));
39 status << format_reg_table(stat, "Master global state");
40 if (print_out)
41 TLOG() << status.str();
42 return status.str();
43}
44//-----------------------------------------------------------------------------
45
46//-----------------------------------------------------------------------------
47void
48MasterGlobalNode::enable_upstream_endpoint(uint32_t timeout) const // NOLINT(build/unsigned)
49{
50 getNode("csr.ctrl.resync_cdr").write(0x1);
51 getNode("csr.ctrl.resync").write(0x1);
52 getClient().dispatch();
53
54 getNode("csr.ctrl.resync_cdr").write(0x0);
55 getNode("csr.ctrl.resync").write(0x0);
56 getClient().dispatch();
57
58 TLOG_DEBUG(4) << "Upstream CDR reset, waiting for lock";
59
60 auto start = std::chrono::high_resolution_clock::now();
61
62 // Wait for the rx and cdr to be happy
63 while (true) {
64 auto rx_ready = getNode("csr.stat.rx_rdy").read();
65 auto cdr_ready = getNode("csr.stat.cdr_locked").read();
66 getClient().dispatch();
67
68 TLOG_DEBUG(6) << std::hex << "rx ready: 0x" << rx_ready.value() << ", cdr ready: " << cdr_ready.value();
69
70 if (rx_ready.value() && cdr_ready.value())
71 {
72 TLOG_DEBUG(4) << "Master CDR and rx block ready!";
73 break;
74 }
75
76 auto now = std::chrono::high_resolution_clock::now();
77 auto ms_since_start = std::chrono::duration_cast<std::chrono::milliseconds>(now - start);
78
79 if (ms_since_start.count() > timeout)
80 throw ReceiverNotReady(ERS_HERE, cdr_ready.value(), rx_ready.value());
81
82 std::this_thread::sleep_for(std::chrono::microseconds(10));
83 }
84}
85//-----------------------------------------------------------------------------
86
87//-----------------------------------------------------------------------------
88bool
90{
91 auto rx_ready = getNode("csr.stat.rx_rdy").read();
92 getClient().dispatch();
93 return rx_ready.value();
94}
95//-----------------------------------------------------------------------------
96
97//-----------------------------------------------------------------------------
98void
99MasterGlobalNode::reset_command_counters(uint32_t timeout) const // NOLINT(build/unsigned)
100{
101 getNode("csr.ctrl.clr_ctrs").write(0x1);
102 getClient().dispatch();
103
104 TLOG_DEBUG(1) << "Command counters reset, waiting for them to be ready";
105
106 auto start = std::chrono::high_resolution_clock::now();
107
108 std::chrono::milliseconds ms_since_start(0);
109
110 uhal::ValWord<uint32_t> counters_ready; // NOLINT(build/unsigned)
111
112 // Wait for the endpoint to be happy
113 while (ms_since_start.count() < timeout) {
114 auto now = std::chrono::high_resolution_clock::now();
115 ms_since_start = std::chrono::duration_cast<std::chrono::milliseconds>(now - start);
116
117 millisleep(10);
118
119 counters_ready = getNode("csr.stat.ctrs_rdy").read();
120 getClient().dispatch();
121
122 TLOG_DEBUG(6) << "counters ready: 0x" << counters_ready.value();
123
124 if (counters_ready.value()) {
125 TLOG_DEBUG(4) << "Master command counters ready!";
126 return;
127 }
128 }
129
130 if (!counters_ready.value()) {
131 // TODO throw something
132 TLOG() << "Command counters did not become ready";
133 } else {
134 TLOG_DEBUG(4) << "Command counters ready";
135 }
136}
137//-----------------------------------------------------------------------------
138
139//-----------------------------------------------------------------------------
140bool
142{
143 auto counters_ready = getNode("csr.stat.ctrs_rdy").read();
144 getClient().dispatch();
145 return counters_ready.value();
146}
147//-----------------------------------------------------------------------------
148
149} // namespace timing
150} // namespace dunedaq
#define ERS_HERE
Class for master global node.
bool read_counters_ready() const
Enable the upstream endpoint.
void enable_upstream_endpoint(uint32_t timeout=500) const
Enable the upstream endpoint.
void reset_command_counters(uint32_t timeout=500) const
Enable the upstream endpoint.
bool read_upstream_endpoint_ready() const
Read the upstream endpoint ready reg.
std::string get_status(bool print_out=false) const override
Get status string, optionally print.
Base class for timing nodes.
std::map< std::string, uhal::ValWord< uint32_t > > read_sub_nodes(const uhal::Node &node, bool dispatch=true) const
Read subnodes.
static int64_t now()
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
#define TLOG(...)
Definition macro.hpp:22
std::string format_reg_table(T data, std::string title, std::vector< std::string > headers)
Format reg-value table.
Definition toolbox.hxx:166
void millisleep(const double &time_in_milliseconds)
Definition toolbox.cpp:83
Including Qt Headers.