21UHAL_REGISTER_DERIVED_NODE(EndpointNode)
37 getNode(
"csr.ctrl.addr").write(
address);
39 getNode(
"csr.ctrl.ep_en").write(0x1);
40 getClient().dispatch();
42 auto start = std::chrono::high_resolution_clock::now();
44 std::chrono::milliseconds ms_since_start(0);
46 uhal::ValWord<uint32_t> counters_ready;
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);
55 counters_ready = getNode(
"csr.stat.ctrs_rdy").read();
56 getClient().dispatch();
57 TLOG_DEBUG(1) <<
"counters_ready: 0x" << std::hex << counters_ready.value();
65 if (!counters_ready) {
75 getNode(
"csr.ctrl.ep_en").write(0x0);
77 getClient().dispatch();
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();
102 std::stringstream status;
104 std::vector<std::pair<std::string, std::string>> ept_summary;
106 auto ept_timestamp = getNode(
"tstamp").readBlock(2);
109 getNode(
"cmd_ctrs.addr").write(0x0);
110 auto counters = getNode(
"cmd_ctrs.data").readBlock(0xff);
111 getClient().dispatch();
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())));
117 ept_summary.push_back(std::make_pair(
"Timestamp",
format_timestamp(ept_timestamp,62500000)));
119 status << std::endl <<
format_reg_table(ept_summary,
"Endpoint summary", {
"",
"" }) << std::endl;
123 std::vector<uint32_t> non_zero_counters;
124 std::vector<std::string> counter_labels;
126 for (uint i=0; i < counters.size(); ++i)
128 auto counter = counters.at(i);
132 non_zero_counters.push_back(counter);
135 std::vector<std::vector<uint32_t>> counters_container = { non_zero_counters };
137 status <<
format_counters_table(counters_container, {
"Received cmd counters" },
"Endpoint cmd counters (>0)", counter_labels);
141 TLOG() << status.str();
150 auto timestamp = getNode(
"tstamp").readBlock(2);
151 getClient().dispatch();
160 auto timestamp = getNode(
"tstamp").readBlock(2);
161 auto endpoint_control =
read_sub_nodes(getNode(
"csr.ctrl"),
false);
163 getClient().dispatch();
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();
Base class for timing IO nodes.
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.
#define TLOG_DEBUG(lvl,...)
std::string format_reg_table(T data, std::string title, std::vector< std::string > headers)
Format reg-value table.
std::string format_timestamp(uhal::ValVector< uint32_t > raw_timestamp, uint32_t clock_frequency_hz)
uint64_t tstamp2int(uhal::ValVector< uint32_t > raw_timestamp)
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.
std::string format_reg_value(T reg_value, uint32_t base)
void millisleep(const double &time_in_milliseconds)
void warning(const Issue &issue)