Line data Source code
1 : /**
2 : * @file IRIGTimestampNode.cpp
3 : *
4 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "timing/IRIGTimestampNode.hpp"
10 :
11 : #include "timing/toolbox.hpp"
12 : #include "logging/Logging.hpp"
13 :
14 : #include <string>
15 :
16 : namespace dunedaq {
17 : namespace timing {
18 :
19 0 : UHAL_REGISTER_DERIVED_NODE(IRIGTimestampNode)
20 :
21 : //-----------------------------------------------------------------------------
22 0 : IRIGTimestampNode::IRIGTimestampNode(const uhal::Node& node)
23 0 : : TimingNode(node)
24 0 : {}
25 : //-----------------------------------------------------------------------------
26 :
27 : //-----------------------------------------------------------------------------
28 0 : IRIGTimestampNode::~IRIGTimestampNode() {}
29 : //-----------------------------------------------------------------------------
30 :
31 : //-----------------------------------------------------------------------------
32 : std::string
33 0 : IRIGTimestampNode::get_status(bool print_out) const
34 : {
35 0 : std::stringstream status;
36 0 : status << "Timestamp: 0x" << std::hex << read_timestamp() << std::endl;
37 :
38 0 : auto ctrl_subnodes = read_sub_nodes(getNode("csr.ctrl"));
39 0 : status << format_reg_table(ctrl_subnodes, "IRIG ts ctrl");
40 :
41 0 : auto stat_subnodes = read_sub_nodes(getNode("csr.stat"));
42 0 : status << format_reg_table(stat_subnodes, "IRIG ts state");
43 :
44 0 : auto date_subnodes = read_sub_nodes(getNode("csr.irig_date"));
45 0 : status << format_reg_table(date_subnodes, "IRIG date");
46 :
47 0 : auto time_subnodes = read_sub_nodes(getNode("csr.irig_time"));
48 0 : status << format_reg_table(time_subnodes, "IRIG time");
49 :
50 0 : auto sbs_subnodes = read_sub_nodes(getNode("csr.irig_sbs"));
51 0 : status << format_reg_table(sbs_subnodes, "IRIG SBS");
52 :
53 0 : status << "PPS counter: 0x" << std::hex << read_pps_counter() << std::endl;
54 :
55 0 : status << "Seconds since epoch: 0x" << std::hex << read_seconds_since_epoch() << std::endl;
56 :
57 0 : if (print_out)
58 0 : TLOG() << status.str();
59 0 : return status.str();
60 0 : }
61 : //-----------------------------------------------------------------------------
62 :
63 : //-----------------------------------------------------------------------------
64 : uhal::ValVector<uint32_t> // NOLINT(build/unsigned)
65 0 : IRIGTimestampNode::read_raw_timestamp(bool dispatch) const
66 : {
67 0 : auto timestamp = getNode("tstamp").readBlock(2);
68 0 : if (dispatch)
69 0 : getClient().dispatch();
70 0 : return timestamp;
71 0 : }
72 : //-----------------------------------------------------------------------------
73 :
74 : //-----------------------------------------------------------------------------
75 : uint64_t // NOLINT(build/unsigned)
76 0 : IRIGTimestampNode::read_timestamp() const
77 : {
78 0 : return tstamp2int(read_raw_timestamp());
79 : }
80 : //-----------------------------------------------------------------------------
81 :
82 : //-----------------------------------------------------------------------------
83 : void
84 0 : IRIGTimestampNode::set_ts_timebase(TimestampTimebase timebase) const // NOLINT(build/unsigned)
85 : {
86 0 : getNode("csr.ctrl.ts_timebase").write(timebase);
87 0 : getClient().dispatch();
88 0 : }
89 : //-----------------------------------------------------------------------------
90 :
91 : //-----------------------------------------------------------------------------
92 : void
93 0 : IRIGTimestampNode::set_ts_epoch(TimestampEpoch epoch) const // NOLINT(build/unsigned)
94 : {
95 0 : getNode("csr.ctrl.ts_epoch").write(epoch);
96 0 : getClient().dispatch();
97 0 : }
98 : //-----------------------------------------------------------------------------
99 :
100 : //-----------------------------------------------------------------------------
101 : void
102 0 : IRIGTimestampNode::set_ts_epoch_value(uint64_t epoch_to_2000_seconds_tai, uint8_t epoch_to_2000_leap_seconds) const // NOLINT(build/unsigned)
103 : {
104 0 : uint32_t epoch_l = epoch_to_2000_seconds_tai;
105 0 : uint32_t epoch_h = epoch_to_2000_seconds_tai >> 32;
106 0 : getNode("csr.seconds_from_sw_epoch_l").write(epoch_l);
107 0 : getNode("csr.seconds_from_sw_epoch_h").write(epoch_h);
108 0 : getNode("csr.offsets.leap_seconds_from_sw_epoch").write(epoch_to_2000_leap_seconds);
109 0 : getClient().dispatch();
110 0 : }
111 : //-----------------------------------------------------------------------------
112 :
113 : //-----------------------------------------------------------------------------
114 : uint32_t // NOLINT(build/unsigned)
115 0 : IRIGTimestampNode::read_pps_counter() const
116 : {
117 0 : auto counter = getNode("pps_ctr").read();
118 0 : getClient().dispatch();
119 0 : return counter.value();
120 0 : }
121 : //-----------------------------------------------------------------------------
122 :
123 : //-----------------------------------------------------------------------------
124 : uint64_t // NOLINT(build/unsigned)
125 0 : IRIGTimestampNode::read_seconds_since_epoch() const
126 : {
127 0 : auto seconds_since_epoch = getNode("seconds_since_epoch").readBlock(2);
128 0 : getClient().dispatch();
129 0 : return tstamp2int(seconds_since_epoch);
130 0 : }
131 : //-----------------------------------------------------------------------------
132 :
133 : //-----------------------------------------------------------------------------
134 : void
135 0 : IRIGTimestampNode::set_ts_seconds_offset(int8_t seconds_offset) const // NOLINT(build/signed)
136 : {
137 : // cast to uint8_t to avoid erroneous auto conversion
138 0 : getNode("csr.offsets.seconds_offset").write((uint8_t)seconds_offset);
139 0 : getClient().dispatch();
140 0 : }
141 : //-----------------------------------------------------------------------------
142 :
143 : //-----------------------------------------------------------------------------
144 : void
145 0 : IRIGTimestampNode::set_ts_ticks_offset(int16_t ticks_offset) const // NOLINT(build/signed)
146 : {
147 : // cast to uint16_t to avoid erroneous auto conversion
148 0 : getNode("csr.offsets.ticks_offset").write((uint16_t)ticks_offset); // NOLINT(build/unsigned)
149 0 : getClient().dispatch();
150 0 : }
151 : //-----------------------------------------------------------------------------
152 :
153 : } // namespace timing
154 : } // namespace dunedaq
|