18UHAL_REGISTER_DERIVED_NODE(MasterGlobalNode)
34 std::stringstream status;
41 TLOG() << status.str();
50 getNode(
"csr.ctrl.resync_cdr").write(0x1);
51 getNode(
"csr.ctrl.resync").write(0x1);
52 getClient().dispatch();
54 getNode(
"csr.ctrl.resync_cdr").write(0x0);
55 getNode(
"csr.ctrl.resync").write(0x0);
56 getClient().dispatch();
58 TLOG_DEBUG(4) <<
"Upstream CDR reset, waiting for lock";
60 auto start = std::chrono::high_resolution_clock::now();
64 auto rx_ready = getNode(
"csr.stat.rx_rdy").read();
65 auto cdr_ready = getNode(
"csr.stat.cdr_locked").read();
66 getClient().dispatch();
68 TLOG_DEBUG(6) << std::hex <<
"rx ready: 0x" << rx_ready.value() <<
", cdr ready: " << cdr_ready.value();
70 if (rx_ready.value() && cdr_ready.value())
72 TLOG_DEBUG(4) <<
"Master CDR and rx block ready!";
76 auto now = std::chrono::high_resolution_clock::now();
77 auto ms_since_start = std::chrono::duration_cast<std::chrono::milliseconds>(
now - start);
79 if (ms_since_start.count() > timeout)
80 throw ReceiverNotReady(
ERS_HERE, cdr_ready.value(), rx_ready.value());
82 std::this_thread::sleep_for(std::chrono::microseconds(10));
91 auto rx_ready = getNode(
"csr.stat.rx_rdy").read();
92 getClient().dispatch();
93 return rx_ready.value();
101 getNode(
"csr.ctrl.clr_ctrs").write(0x1);
102 getClient().dispatch();
104 TLOG_DEBUG(1) <<
"Command counters reset, waiting for them to be ready";
106 auto start = std::chrono::high_resolution_clock::now();
108 std::chrono::milliseconds ms_since_start(0);
110 uhal::ValWord<uint32_t> counters_ready;
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);
119 counters_ready = getNode(
"csr.stat.ctrs_rdy").read();
120 getClient().dispatch();
122 TLOG_DEBUG(6) <<
"counters ready: 0x" << counters_ready.value();
124 if (counters_ready.value()) {
125 TLOG_DEBUG(4) <<
"Master command counters ready!";
130 if (!counters_ready.value()) {
132 TLOG() <<
"Command counters did not become ready";
143 auto counters_ready = getNode(
"csr.stat.ctrs_rdy").read();
144 getClient().dispatch();
145 return counters_ready.value();
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.
virtual ~MasterGlobalNode()
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.
#define TLOG_DEBUG(lvl,...)
std::string format_reg_table(T data, std::string title, std::vector< std::string > headers)
Format reg-value table.
void millisleep(const double &time_in_milliseconds)