DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::timing::MasterGlobalNode Class Reference

Class for master global node. More...

#include <MasterGlobalNode.hpp>

Inheritance diagram for dunedaq::timing::MasterGlobalNode:
[legend]
Collaboration diagram for dunedaq::timing::MasterGlobalNode:
[legend]

Public Member Functions

 MasterGlobalNode (const uhal::Node &node)
 
virtual ~MasterGlobalNode ()
 
void enable_upstream_endpoint (uint32_t timeout=500) const
 Enable the upstream endpoint.
 
bool read_upstream_endpoint_ready () const
 Read the upstream endpoint ready reg.
 
void reset_command_counters (uint32_t timeout=500) const
 Enable the upstream endpoint.
 
bool read_counters_ready () const
 Enable the upstream endpoint.
 
std::string get_status (bool print_out=false) const override
 Get status string, optionally print.
 
- Public Member Functions inherited from dunedaq::timing::TimingNode
 TimingNode (const uhal::Node &node)
 
virtual ~TimingNode ()
 
std::map< std::string, uhal::ValWord< uint32_t > > read_sub_nodes (const uhal::Node &node, bool dispatch=true) const
 Read subnodes.
 
void reset_sub_nodes (const uhal::Node &node, uint32_t aValue=0x0, bool dispatch=true) const
 Reset subnodes.
 

Detailed Description

Class for master global node.

Definition at line 29 of file MasterGlobalNode.hpp.

Constructor & Destructor Documentation

◆ MasterGlobalNode()

dunedaq::timing::MasterGlobalNode::MasterGlobalNode ( const uhal::Node & node)
explicit

Definition at line 21 of file MasterGlobalNode.cpp.

22 : TimingNode(node)
23{}
TimingNode(const uhal::Node &node)

◆ ~MasterGlobalNode()

dunedaq::timing::MasterGlobalNode::~MasterGlobalNode ( )
virtual

Definition at line 27 of file MasterGlobalNode.cpp.

27{}

Member Function Documentation

◆ enable_upstream_endpoint()

void dunedaq::timing::MasterGlobalNode::enable_upstream_endpoint ( uint32_t timeout = 500) const

Enable the upstream endpoint.

Definition at line 48 of file MasterGlobalNode.cpp.

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}
#define ERS_HERE
static int64_t now()
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112

◆ get_status()

std::string dunedaq::timing::MasterGlobalNode::get_status ( bool print_out = false) const
overridevirtual

Get status string, optionally print.

Implements dunedaq::timing::TimingNode.

Definition at line 32 of file MasterGlobalNode.cpp.

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}
std::map< std::string, uhal::ValWord< uint32_t > > read_sub_nodes(const uhal::Node &node, bool dispatch=true) const
Read subnodes.
#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

◆ read_counters_ready()

bool dunedaq::timing::MasterGlobalNode::read_counters_ready ( ) const

Enable the upstream endpoint.

Definition at line 141 of file MasterGlobalNode.cpp.

142{
143 auto counters_ready = getNode("csr.stat.ctrs_rdy").read();
144 getClient().dispatch();
145 return counters_ready.value();
146}

◆ read_upstream_endpoint_ready()

bool dunedaq::timing::MasterGlobalNode::read_upstream_endpoint_ready ( ) const

Read the upstream endpoint ready reg.

Definition at line 89 of file MasterGlobalNode.cpp.

90{
91 auto rx_ready = getNode("csr.stat.rx_rdy").read();
92 getClient().dispatch();
93 return rx_ready.value();
94}

◆ reset_command_counters()

void dunedaq::timing::MasterGlobalNode::reset_command_counters ( uint32_t timeout = 500) const

Enable the upstream endpoint.

Definition at line 99 of file MasterGlobalNode.cpp.

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}
void millisleep(const double &time_in_milliseconds)
Definition toolbox.cpp:83

The documentation for this class was generated from the following files: