DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
EndpointNode.cpp
Go to the documentation of this file.
1
10#include "timing/toolbox.hpp"
11
12#include "logging/Logging.hpp"
13
14#include <string>
15#include <utility>
16#include <vector>
17
18namespace dunedaq {
19namespace timing {
20
21UHAL_REGISTER_DERIVED_NODE(EndpointNode)
22
23//-----------------------------------------------------------------------------
24EndpointNode::EndpointNode(const uhal::Node& node)
26{}
27//-----------------------------------------------------------------------------
28
29//-----------------------------------------------------------------------------
31//-----------------------------------------------------------------------------
32
33//-----------------------------------------------------------------------------
34void
35EndpointNode::enable(uint32_t address, uint32_t /*partition*/) const // NOLINT(build/unsigned)
36{
37 getNode("csr.ctrl.addr").write(address);
38
39 getNode("csr.ctrl.ep_en").write(0x1);
40 getClient().dispatch();
41
42 auto start = std::chrono::high_resolution_clock::now();
43
44 std::chrono::milliseconds ms_since_start(0);
45
46 uhal::ValWord<uint32_t> counters_ready;
47
48 // Wait for the endpoint to be happy
49 while (ms_since_start.count() < 500) {
50 auto now = std::chrono::high_resolution_clock::now();
51 ms_since_start = std::chrono::duration_cast<std::chrono::milliseconds>(now - start);
52
53 millisleep(10);
54
55 counters_ready = getNode("csr.stat.ctrs_rdy").read();
56 getClient().dispatch();
57 TLOG_DEBUG(1) << "counters_ready: 0x" << std::hex << counters_ready.value();
58
59 if (counters_ready) {
60 TLOG_DEBUG(1) << "counters ready";
61 break;
62 }
63 }
64
65 if (!counters_ready) {
66 ers::warning(EndpointBroadcastMessageCountersNotReady(ERS_HERE));
67 }
68}
69//-----------------------------------------------------------------------------
70
71//-----------------------------------------------------------------------------
72void
74{
75 getNode("csr.ctrl.ep_en").write(0x0);
76// getNode("csr.ctrl.buf_en").write(0x0);
77 getClient().dispatch();
78}
79//-----------------------------------------------------------------------------
80
81//-----------------------------------------------------------------------------
82void
83EndpointNode::reset(uint32_t address, uint32_t /*partition*/) const // NOLINT(build/unsigned)
84{
85
86 getNode("csr.ctrl.ep_en").write(0x0);
87 getNode("csr.ctrl.ctr_rst").write(0x1);
88 getNode("csr.ctrl.ctr_rst").write(0x0);
89 getClient().dispatch();
90
91 //getNode("csr.ctrl.buf_en").write(0x0);
92
94}
95//-----------------------------------------------------------------------------
96
97//-----------------------------------------------------------------------------
98std::string
99EndpointNode::get_status(bool print_out) const
100{
101
102 std::stringstream status;
103
104 std::vector<std::pair<std::string, std::string>> ept_summary;
105
106 auto ept_timestamp = getNode("tstamp").readBlock(2);
107 auto ept_control = read_sub_nodes(getNode("csr.ctrl"), false);
108 auto ept_state = read_sub_nodes(getNode("csr.stat"), false);
109 getNode("cmd_ctrs.addr").write(0x0);
110 auto counters = getNode("cmd_ctrs.data").readBlock(0xff);
111 getClient().dispatch();
112
113 ept_summary.push_back(std::make_pair("Enabled", std::to_string(ept_control.find("ep_en")->second.value())));
114 ept_summary.push_back(std::make_pair("Address", std::to_string(ept_control.find("addr")->second.value())));
115 ept_summary.push_back(std::make_pair("State", get_endpoint_state_map().at(ept_state.find("ep_stat")->second.value())));
116 ept_summary.push_back(std::make_pair("Timestamp (hex)", format_reg_value(tstamp2int(ept_timestamp))));
117 ept_summary.push_back(std::make_pair("Timestamp", format_timestamp(ept_timestamp,62500000)));
118
119 status << std::endl << format_reg_table(ept_summary, "Endpoint summary", { "", "" }) << std::endl;
120// status << "Endpoint frequency: " << ept_clock_frequency << " MHz" << std::endl;
121 status << format_reg_table(ept_state, "Endpoint state") << std::endl;
122
123 std::vector<uint32_t> non_zero_counters;
124 std::vector<std::string> counter_labels;
125
126 for (uint i=0; i < counters.size(); ++i)
127 {
128 auto counter = counters.at(i);
129 if (counter > 0)
130 {
131 counter_labels.push_back(format_reg_value(i));
132 non_zero_counters.push_back(counter);
133 }
134 }
135 std::vector<std::vector<uint32_t>> counters_container = { non_zero_counters }; // NOLINT(build/unsigned)
136
137 status << format_counters_table(counters_container, { "Received cmd counters" }, "Endpoint cmd counters (>0)", counter_labels);
138 status << std::endl;
139
140 if (print_out)
141 TLOG() << status.str();
142 return status.str();
143}
144//-----------------------------------------------------------------------------
145
146//-----------------------------------------------------------------------------
147uint64_t // NOLINT(build/unsigned)
149{
150 auto timestamp = getNode("tstamp").readBlock(2);
151 getClient().dispatch();
152 return tstamp2int(timestamp);
153}
154//-----------------------------------------------------------------------------
155
156//-----------------------------------------------------------------------------
157void
159{
160 auto timestamp = getNode("tstamp").readBlock(2);
161 auto endpoint_control = read_sub_nodes(getNode("csr.ctrl"), false);
162 auto endpoint_state = read_sub_nodes(getNode("csr.stat"), false);
163 getClient().dispatch();
164
165 mon_data.state = endpoint_state.at("ep_stat").value();
166 mon_data.ready = endpoint_state.at("ep_rdy").value();
167 mon_data.address = endpoint_control.at("addr").value();
168 mon_data.timestamp = tstamp2int(timestamp);
169 mon_data.sfp_tx_disable = !endpoint_state.at("ep_txen").value();
170}
171//-----------------------------------------------------------------------------
172
173} // namespace timing
174} // namespace dunedaq
#define ERS_HERE
Base class for timing IO nodes.
void enable(uint32_t address=0, uint32_t partition=0) const override
Enable the endpoint.
virtual uint64_t read_timestamp() const
Read the current timestamp word.
void reset(uint32_t address=0, uint32_t partition=0) const override
Reset the endpoint.
void get_info(timingendpointinfo::TimingEndpointInfo &mon_data) const override
Read the endpoint clock frequency.
void disable() const override
Disable the endpoint.
static std::map< uint8_t, std::string > get_endpoint_state_map()
Get the states map.
std::string get_status(bool print_out=false) const override
Print the status of the timing node.
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
std::string format_timestamp(uhal::ValVector< uint32_t > raw_timestamp, uint32_t clock_frequency_hz)
Definition toolbox.cpp:233
uint64_t tstamp2int(uhal::ValVector< uint32_t > raw_timestamp)
Definition toolbox.cpp:175
std::string format_counters_table(std::vector< T > counter_nodes, std::vector< std::string > counter_node_titles, std::string table_title, std::vector< std::string > counter_labels, std::string counter_labels_header)
Format reg-value table.
Definition toolbox.hxx:216
std::string format_reg_value(T reg_value, uint32_t base)
Definition toolbox.hxx:117
void millisleep(const double &time_in_milliseconds)
Definition toolbox.cpp:83
Including Qt Headers.
void warning(const Issue &issue)
Definition ers.hpp:115