DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
PC059IONode.cpp
Go to the documentation of this file.
1
10
11#include "logging/Logging.hpp"
12
13#include <string>
14
15namespace dunedaq {
16namespace timing {
17
18UHAL_REGISTER_DERIVED_NODE(PC059IONode)
19
20//-----------------------------------------------------------------------------
21PC059IONode::PC059IONode(const uhal::Node& node)
22 : SFPMuxIONode(node, "i2c", "i2c", "SI5345", { "PLL", "CDR" }, { "usfp_i2c", "i2c" })
23{}
24//-----------------------------------------------------------------------------
25
26//-----------------------------------------------------------------------------
28//-----------------------------------------------------------------------------
29
30//-----------------------------------------------------------------------------
31std::string
33{
34 return "FMC_UID_PROM";
35}
36//-----------------------------------------------------------------------------
37
38//-----------------------------------------------------------------------------
39std::string
40PC059IONode::get_status(bool print_out) const
41{
42 std::stringstream status;
43 auto subnodes = read_sub_nodes(getNode("csr.stat"));
44 status << format_reg_table(subnodes, "PC059 IO state");
45
46 if (print_out)
47 TLOG() << std::endl << status.str();
48 return status.str();
49}
50//-----------------------------------------------------------------------------
51
52//-----------------------------------------------------------------------------
53void
54PC059IONode::reset(const std::string& clock_config_file) const
55{
56 // Soft reset
58
59 millisleep(1000);
60
61 // Reset PLL and I2C
62 getNode("csr.ctrl.pll_rst").write(0x1);
63 getNode("csr.ctrl.pll_rst").write(0x0);
64
65 getNode("csr.ctrl.rst_i2c").write(0x1);
66 getNode("csr.ctrl.rst_i2c").write(0x0);
67
68 getNode("csr.ctrl.rst_i2cmux").write(0x1);
69 getNode("csr.ctrl.rst_i2cmux").write(0x0);
70
71 getClient().dispatch();
72
73 // enclustra i2c switch stuff
74 try {
75 getNode<I2CMasterNode>(m_uid_i2c_bus).get_slave("AX3_Switch").write_i2c(0x01, 0x7f);
76 } catch (const std::exception& e) {
77 ers::warning(EnclustraSwitchFailure(ERS_HERE, e));
78 }
79
80 // Upload config file to PLL
81 configure_pll(clock_config_file);
82
83 // Reset mmcm
84 getNode("csr.ctrl.rst").write(0x1);
85 getNode("csr.ctrl.rst").write(0x0);
86 getClient().dispatch();
87
88 getNode("csr.ctrl.mux").write(0);
89 getClient().dispatch();
90
91 auto sfp_expander = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander");
92
93 // Set invert registers to default for both banks
94 sfp_expander->set_inversion(0, 0x00);
95 sfp_expander->set_inversion(1, 0x00);
96
97 // Bank 0 output, bank 1 input
98 sfp_expander->set_io(0, 0x00);
99 sfp_expander->set_io(1, 0xff);
100
101 // Bank 0 - enable all SFPGs (enable low)
102 sfp_expander->set_outputs(0, 0x00);
103 TLOG_DEBUG(0) << "SFPs 0-7 enabled";
104
105 // To be removed from firmware address maps also
106 //getNode("csr.ctrl.rst_lock_mon").write(0x1);
107 //getNode("csr.ctrl.rst_lock_mon").write(0x0);
108 //getClient().dispatch();
109
110 TLOG() << "Reset done";
111}
112//-----------------------------------------------------------------------------
113
114//-----------------------------------------------------------------------------
115void
116PC059IONode::switch_sfp_mux_channel(uint32_t mux_channel) const // NOLINT(build/unsigned)
117{
118 getNode("csr.ctrl.mux").write(mux_channel);
119 getClient().dispatch();
120
121 TLOG_DEBUG(3) << "SFP input mux set to " << format_reg_value(read_active_sfp_mux_channel());
122}
123//-----------------------------------------------------------------------------
124
125//-----------------------------------------------------------------------------
126uint32_t // NOLINT(build/unsigned)
128{
129 auto active_sfp_mux_channel = getNode("csr.ctrl.mux").read();
130 getClient().dispatch();
131 return active_sfp_mux_channel.value();
132}
133//-----------------------------------------------------------------------------
134
135//-----------------------------------------------------------------------------
136void
137PC059IONode::switch_sfp_i2c_mux_channel(uint32_t sfp_id) const // NOLINT(build/unsigned)
138{
139
140 getNode("csr.ctrl.rst_i2cmux").write(0x1);
141 getClient().dispatch();
142 getNode("csr.ctrl.rst_i2cmux").write(0x0);
143 getClient().dispatch();
144 millisleep(100);
145
146 uint8_t channel_select_byte = 1UL << sfp_id; // NOLINT(build/unsigned)
147 getNode<I2CMasterNode>(m_pll_i2c_bus).get_slave("SFP_Switch").write_i2cPrimitive({ channel_select_byte });
148 TLOG_DEBUG(3) << "PC059 SFP I2C mux set to " << format_reg_value(sfp_id);
149}
150//-----------------------------------------------------------------------------
151
152//-----------------------------------------------------------------------------
153std::string
154PC059IONode::get_sfp_status(uint32_t sfp_id, bool print_out) const // NOLINT(build/unsigned)
155{
156 // on this board the upstream sfp has its own i2c bus, and the 8 downstream sfps are muxed onto the main i2c bus
157 std::stringstream status;
158 uint32_t sfp_bus_index; // NOLINT(build/unsigned)
159 if (sfp_id == 0) {
160 sfp_bus_index = 0;
161 status << "Upstream SFP:" << std::endl;
162 } else if (sfp_id > 0 && sfp_id < 9) {
163 switch_sfp_i2c_mux_channel(sfp_id - 1);
164 status << "Fanout SFP " << sfp_id - 1 << ":" << std::endl;
165 sfp_bus_index = 1;
166 } else {
167 throw InvalidSFPId(ERS_HERE, format_reg_value(sfp_id));
168 }
169 auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_bus_index), "SFP_EEProm");
170
171 status << sfp->get_status();
172
173 if (print_out)
174 TLOG() << status.str();
175 return status.str();
176}
177//-----------------------------------------------------------------------------
178
179//-----------------------------------------------------------------------------
180bool
182{
183 std::stringstream status;
184
185 auto states = read_sub_nodes(getNode("csr.stat"));
186 bool pll_ok = states.find("pll_ok")->second.value();
187 bool mmcm_ok = states.find("mmcm_ok")->second.value();
188
189 TLOG_DEBUG(5) << "pll ok: " << pll_ok << ", mmcm ok: " << mmcm_ok;
190
191 return pll_ok && mmcm_ok;
192}
193//-----------------------------------------------------------------------------
194
195//-----------------------------------------------------------------------------
196void
197PC059IONode::switch_sfp_soft_tx_control_bit(uint32_t sfp_id, bool turn_on) const // NOLINT(build/unsigned)
198{
199 // on this board the upstream sfp has its own i2c bus, and the 8 downstream sfps are muxed onto the main i2c bus
200 uint32_t sfp_bus_index; // NOLINT(build/unsigned)
201 if (sfp_id == 0) {
202 sfp_bus_index = 0;
203 } else if (sfp_id > 0 && sfp_id < 9) {
204 switch_sfp_i2c_mux_channel(sfp_id - 1);
205 sfp_bus_index = 1;
206 } else {
207 throw InvalidSFPId(ERS_HERE, format_reg_value(sfp_id));
208 }
209 auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_bus_index), "SFP_EEProm");
210 sfp->switch_soft_tx_control_bit(turn_on);
211}
212//-----------------------------------------------------------------------------
213
214//-----------------------------------------------------------------------------
215void
216PC059IONode::switch_sfp_tx(uint32_t sfp_id, bool turn_on) const { // NOLINT(build/unsigned)
217
218 validate_sfp_id(sfp_id);
219
220 auto sfp_expander = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander");
221 uint8_t current_sfp_tx_control_flags = sfp_expander->read_outputs_config(0); // NOLINT(build/unsigned)
222
223 uint8_t new_sfp_tx_control_flags; // NOLINT(build/unsigned)
224 if (turn_on)
225 {
226 new_sfp_tx_control_flags = current_sfp_tx_control_flags & ~(1UL << sfp_id);
227 }
228 else
229 {
230 new_sfp_tx_control_flags = current_sfp_tx_control_flags | (1UL << sfp_id);
231 }
232
233 sfp_expander->set_outputs(0, new_sfp_tx_control_flags);
234}
235//-----------------------------------------------------------------------------
236
237//-----------------------------------------------------------------------------
238void
239PC059IONode::validate_sfp_id(uint32_t sfp_id) const // NOLINT(build/unsigned)
240{
241 // on this board we have 8 downstream SFPs
242 if (sfp_id > 7)
243 {
244 throw InvalidSFPId(ERS_HERE, format_reg_value(sfp_id));
245 }
246}
247//-----------------------------------------------------------------------------
248
249//-----------------------------------------------------------------------------
250// void
251// PC059IONode::get_info(timinghardwareinfo::TimingPC059MonitorData& mon_data) const
252// {
253// auto subnodes = read_sub_nodes(getNode("csr.stat"));
254
255// mon_data.cdr_lol = subnodes.at("cdr_lol").value();
256// mon_data.cdr_los = subnodes.at("cdr_los").value();
257
258// mon_data.mmcm_ok = subnodes.at("mmcm_ok").value();
259// mon_data.mmcm_sticky = subnodes.at("mmcm_sticky").value();
260
261// mon_data.pll_lol = subnodes.at("pll_lol").value();
262// mon_data.pll_ok = subnodes.at("pll_ok").value();
263// mon_data.pll_sticky = subnodes.at("pll_sticky").value();
264
265// mon_data.sfp_los = subnodes.at("sfp_los").value();
266
267// mon_data.ucdr_lol = subnodes.at("ucdr_lol").value();
268// mon_data.ucdr_los = subnodes.at("ucdr_los").value();
269
270// mon_data.usfp_flt = subnodes.at("usfp_flt").value();
271// mon_data.usfp_los = subnodes.at("usfp_los").value();
272// }
273//-----------------------------------------------------------------------------
274
275//-----------------------------------------------------------------------------
276// void
277// PC059IONode::get_info(opmonlib::InfoCollector& ci, int level) const
278// {
279// if (level >= 2)
280// {
281// timinghardwareinfo::TimingPLLMonitorData pll_mon_data;
282// this->get_pll()->get_info(pll_mon_data);
283// ci.add(pll_mon_data);
284
285// timinghardwareinfo::TimingSFPMonitorData upstream_sfp_mon_data;
286// auto upstream_sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(0), "SFP_EEProm");
287// try {
288// upstream_sfp->get_info(upstream_sfp_mon_data);
289// opmonlib::InfoCollector upstream_sfp_ic;
290// upstream_sfp_ic.add(upstream_sfp_mon_data);
291// ci.add("upstream_sfp", upstream_sfp_ic);
292// }
293// catch (timing::SFPUnreachable& e) {
294// // It is valid that an SFP may not be installed, currently no good way of knowing whether they it should be
295// TLOG_DEBUG(2) << "Failed to communicate with upstream SFP on i2c bus" << m_sfp_i2c_buses.at(0);
296// }
297
298
299// for (uint sfp_id=0; sfp_id < 8; ++sfp_id) {
300// TLOG_DEBUG(5) << "checking sfp: " << sfp_id;
301// switch_sfp_i2c_mux_channel(sfp_id);
302
303// auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(1), "SFP_EEProm");
304// timinghardwareinfo::TimingSFPMonitorData sfp_data;
305
306// try {
307// sfp->get_info(sfp_data);
308// } catch (timing::SFPUnreachable& e) {
309// // It is valid that an SFP may not be installed, currently no good way of knowing whether they it should be
310// TLOG_DEBUG(2) << "Failed to communicate with downstream SFP: " << sfp_id << " on i2c bus" << m_sfp_i2c_buses.at(1);
311// continue;
312// }
313
314// opmonlib::InfoCollector sfp_ic;
315// sfp_ic.add(sfp_data);
316// ci.add("sfp_"+std::to_string(sfp_id), sfp_ic);
317// }
318// }
319
320// if (level >= 1) {
321// timinghardwareinfo::TimingPC059MonitorData mon_data;
322// this->get_info(mon_data);
323// ci.add(mon_data);
324// }
325// }
326//-----------------------------------------------------------------------------
327
328} // namespace timing
329} // namespace dunedaq
#define ERS_HERE
virtual void write_soft_reset_register() const
Write soft reset register.
Definition IONode.cpp:296
const std::string m_uid_i2c_bus
Definition IONode.hpp:200
virtual void configure_pll(const std::string &clock_config_file="") const
Configure clock chip.
Definition IONode.cpp:247
std::unique_ptr< const T > get_i2c_device(const std::string &i2c_bus_name, const std::string &i2c_device_name) const
Get the an I2C chip.
Definition IONode.hxx:6
Class for the PC059 board.
uint32_t read_active_sfp_mux_channel() const override
Read the active SFP mux channel.
void switch_sfp_soft_tx_control_bit(uint32_t sfp_id, bool turn_on) const override
control tx laser of on-board SFP softly (I2C command)
bool clocks_ok() const override
Clocks ready?
void switch_sfp_mux_channel(uint32_t mux_channel) const override
Switch the SFP mux channel.
void validate_sfp_id(uint32_t sfp_id) const
Fill hardware monitoring structure.
std::string get_uid_address_parameter_name() const override
Get the UID address parameter name.
std::string get_sfp_status(uint32_t sfp_id, bool print_out=false) const override
Print status of on-board SFP.
std::string get_status(bool print_out=false) const override
Get status string, optionally print.
void switch_sfp_i2c_mux_channel(uint32_t sfp_id) const
Switch the SFP I2C mux channel.
void switch_sfp_tx(uint32_t sfp_id, bool turn_on) const override
control tx laser of on-board SFP softly (I2C command)
void reset(const std::string &clock_config_file) const override
Reset pc059 node.
Base class for boards which have a physical SFP mux.
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,...)
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_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