DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
GIBIONode.cpp
Go to the documentation of this file.
1
10#include "timing/LM75Node.hpp"
11
12#include <string>
13#include <math.h>
14
15namespace dunedaq {
16namespace timing {
17
18UHAL_REGISTER_DERIVED_NODE(GIBIONode)
19
20//-----------------------------------------------------------------------------
21GIBIONode::GIBIONode(const uhal::Node& node)
22 : IONode(node, "i2c", "i2c", { "PLL" }, { "PLL", "SFP CDR 0", "SFP CDR 1", "SFP CDR 2", "SFP CDR 3", "SFP CDR 4", "SFP CDR 5", "10 MHz" }, { "i2c", "i2c", "i2c", "i2c", "i2c", "i2c" })
23{
24}
25//-----------------------------------------------------------------------------
26
27//-----------------------------------------------------------------------------
28GIBIONode::GIBIONode(const uhal::Node& node,
29 std::string uid_i2c_bus,
30 std::string pll_i2c_bus,
31 std::string pll_i2c_device,
32 std::vector<std::string> clock_names,
33 std::vector<std::string> sfp_i2c_buses)
34 : IONode(node, uid_i2c_bus, pll_i2c_bus, pll_i2c_device, clock_names, sfp_i2c_buses)
35{
36}
37//-----------------------------------------------------------------------------
38
39//-----------------------------------------------------------------------------
41//-----------------------------------------------------------------------------
42
43//-----------------------------------------------------------------------------
44std::string
46{
47 return "UID_PROM";
48}
49//-----------------------------------------------------------------------------
50
51//-----------------------------------------------------------------------------
52std::string
53GIBIONode::get_status(bool print_out) const
54{
55 std::stringstream status;
56
57 auto subnodes = read_sub_nodes(getNode("csr.stat"));
58 status << format_reg_table(subnodes, "GIB IO state");
59
60 auto subnodes_2 = read_sub_nodes(getNode("csr.ctrl"));
61 status << format_reg_table(subnodes_2, "GIB IO control");
62
63 uint8_t sfp_los = read_sfps_los();
64 uint8_t sfp_fault = read_sfps_fault();
65
66 std::vector<std::string> sfp_vec;
67 std::vector<uint8_t> los_vec;
68 std::vector<uint8_t> fault_vec;
69
70 for (int i=0; i<get_num_sfps(); i++) {
71 sfp_vec.push_back(to_string(i));
72 // L is 0x4C, H is L - 4
73 los_vec.push_back(0x4C - 4*((sfp_los >> i) & 1));
74 fault_vec.push_back(0x4C - 4*((sfp_fault >> i) & 1));
75 }
76
77 status << "------IO expander----" << std::endl;
78 status << "SFP: " << vec_fmt(sfp_vec) << std::endl;
79 status << "LOS: " << vec_fmt(los_vec) << std::endl;
80 status << "Fault: " << vec_fmt(fault_vec) << std::endl;
81
82 status << "Board temperature: " << read_board_temperature() << " [C]" << std::endl;
83
84 if (print_out)
85 TLOG() << std::endl << status.str();
86 return status.str();
87}
88//-----------------------------------------------------------------------------
89
90//-----------------------------------------------------------------------------
91std::unique_ptr<const SI534xSlave>
93{
94 // enable pll channel 0 only
97}
98//-----------------------------------------------------------------------------
99
100//-----------------------------------------------------------------------------
101std::string
102GIBIONode::get_hardware_info(bool print_out) const
103{
104 // enable pll/uid channel 0 only
106 return IONode::get_hardware_info(print_out);
107}
108//-----------------------------------------------------------------------------
109
110//-----------------------------------------------------------------------------
111void
113{
114 // enclustra i2c switch stuff
116 if (carrier_type == kCarrierEnclustraA35) {
117 try {
118 getNode<I2CMasterNode>(m_uid_i2c_bus).get_slave("AX3_Switch").write_i2c(0x01, 0x7f);
119 } catch (const std::exception& e) {
120 ers::warning(EnclustraSwitchFailure(ERS_HERE, e));
121 }
122 }
123
124 // Reset I2C switch and expander, active low
125 getNode("csr.ctrl.i2c_sw_rst").write(0x0);
126 getNode("csr.ctrl.i2c_exten_rst").write(0x0);
127 getNode("csr.ctrl.clk_gen_rst").write(0x0);
128 getClient().dispatch();
129
130 millisleep(1);
131
132 // End reset
133 getNode("csr.ctrl.i2c_sw_rst").write(0x1);
134 getNode("csr.ctrl.i2c_exten_rst").write(0x1);
135 getNode("csr.ctrl.clk_gen_rst").write(0x1);
136 getClient().dispatch();
137
139}
140//-----------------------------------------------------------------------------
141
142//-----------------------------------------------------------------------------
143void
144GIBIONode::reset(const std::string& clock_config_file) const
145{
146 getNode("csr.ctrl.rst").write(0x1);
147 getNode("csr.ctrl.rst").write(0x0);
148 getClient().dispatch();
149
151
152 getNode("csr.ctrl.gps_clk_en").write(0x0);
153
154 // Set filter to full bandwidth mode A = B = 0x0
155 getNode("csr.ctrl.gps_clk_fltr_a").write(0x0);
156 getNode("csr.ctrl.gps_clk_fltr_b").write(0x0);
157 getClient().dispatch();
158
159 // Upload config file to PLL
160 configure_pll(clock_config_file);
161
163
164 TLOG() << "Reset done";
165}
166//-----------------------------------------------------------------------------
167
168//-----------------------------------------------------------------------------
169void
171{
172 auto sfp_expander_0 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander0");
173 auto sfp_expander_1 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander1");
174
175 // Set invert registers to default for both (0,1) banks
176 sfp_expander_0->set_inversion(0, 0x00);
177 sfp_expander_0->set_inversion(1, 0x00);
178 sfp_expander_1->set_inversion(0, 0x00);
179 sfp_expander_1->set_inversion(1, 0x00);
180
181 // 0: pin set as output, 1: pin set as input
182 sfp_expander_0->set_io(0, 0xff); // set all pins of bank 0 as inputs
183 sfp_expander_0->set_io(1, 0xff); // set all pins of bank 1 as inputs
184
185 sfp_expander_1->set_io(0, 0xff); // set all pins of bank 0 as inputs
186 sfp_expander_1->set_io(1, 0x00); // set all pins of bank 1 as outputs
187
188 // Set SFP disable
189 // Set tx disable pins low, i.e. enable the pins given in the bitmap
190 // (different between v1 and v2/3)
191 sfp_expander_1->set_outputs(1, get_sfp_tx_disable_bitmap());
192}
193//-----------------------------------------------------------------------------
194
195//-----------------------------------------------------------------------------
196void
198{
199 getNode("csr.ctrl.clk_gen_rst").write(0x0);
200 getNode("csr.ctrl.clk_gen_rst").write(0x1);
201}
202//-----------------------------------------------------------------------------
203
204//-----------------------------------------------------------------------------
205std::string
206GIBIONode::get_sfp_status(uint32_t sfp_id, bool print_out) const { // NOLINT(build/unsigned)
207 std::stringstream status;
208
209 validate_sfp_id(sfp_id);
210
211 uint8_t i2c_mux_bitmask = 1UL << (sfp_id+1);
212
213 set_i2c_mux_channels(i2c_mux_bitmask);
214
215 auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_id), "SFP_EEProm");
216
217 status << "SFP " << sfp_id << ":" << std::endl;
218 status << sfp->get_status();
219
220 if (print_out)
221 TLOG() << status.str();
222
223 return status.str();
224}
225//-----------------------------------------------------------------------------
226
227//-----------------------------------------------------------------------------
228uint32_t
229GIBIONode::read_io_expanders() const { // NOLINT(build/unsigned)
230 auto sfp_expander_0 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander0");
231 auto sfp_expander_1 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander1");
232
233 uint32_t expander_bits = sfp_expander_1->read_inputs(0);
234 expander_bits = (expander_bits << 8) + sfp_expander_0->read_inputs(1);
235 expander_bits = (expander_bits << 8) + sfp_expander_0->read_inputs(0);
236
237 return expander_bits;
238}
239//-----------------------------------------------------------------------------
240
241//-----------------------------------------------------------------------------
242uint8_t
243GIBIONode::read_sfps_los() const { // NOLINT(build/unsigned)
244 uint32_t expander_bits = read_io_expanders();
245
246 uint8_t los_bits = 0x00;
247
248 for (uint8_t sfp = 0; sfp<6; sfp++) {
249 // Each SFP has 4 bits, the 3rd bit is the LOS
250 // Adds the SFPs in inverse order
251 los_bits = (los_bits << 1) + ((expander_bits >> (2 + 20 - 4*sfp)) & 1);
252 }
253
254 return los_bits;
255}
256//-----------------------------------------------------------------------------
257
258//-----------------------------------------------------------------------------
259uint8_t
260GIBIONode::read_sfps_fault() const { // NOLINT(build/unsigned)
261 uint32_t expander_bits = read_io_expanders();
262
263 uint8_t fault_bits = 0x00;
264
265 for (uint8_t sfp = 0; sfp<6; sfp++) {
266 // Each SFP has 4 bits, the 4th bit is the fault
267 // Adds the SFPs in inverse order
268 fault_bits = (fault_bits << 1) + ((expander_bits >> (3 + 20 - 4*sfp)) & 1);
269 }
270
271 return fault_bits;
272}
273//-----------------------------------------------------------------------------
274
275//-----------------------------------------------------------------------------
276bool
278{
279 std::stringstream status;
280
281 auto states = read_sub_nodes(getNode("csr.stat"));
282 bool pll_lol = states.find("clk_gen_lol")->second.value();
283 bool pll_interrupt = states.find("clk_gen_intr")->second.value();
284 bool mmcm_ok = states.find("mmcm_ok")->second.value();
285 bool mmcm_10_ok = states.find("mmcm_ok")->second.value();
286
287 TLOG_DEBUG(5) << "pll lol: " << pll_lol << ", pll intr: " << pll_interrupt
288 << ", mmcm ok: " << mmcm_ok << ", mmcm 10MHz ok: " << mmcm_10_ok;
289
290 return !pll_lol && mmcm_ok && mmcm_10_ok;
291}
292//-----------------------------------------------------------------------------
293
294//-----------------------------------------------------------------------------
295void
296GIBIONode::switch_sfp_soft_tx_control_bit(uint32_t sfp_id, bool turn_on) const { // NOLINT(build/unsigned)
297 validate_sfp_id(sfp_id);
298
299 auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_id), "SFP_EEProm");
300 sfp->switch_soft_tx_control_bit(turn_on);
301}
302//-----------------------------------------------------------------------------
303
304//-----------------------------------------------------------------------------
305void
306GIBIONode::switch_sfp_tx(uint32_t sfp_id, bool turn_on) const { // NOLINT(build/unsigned)
307 validate_sfp_id(sfp_id);
308
309 auto sfp_expander_1 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander1");
310 uint8_t current_sfp_tx_control_flags = sfp_expander_1->read_outputs_config(1); // NOLINT(build/unsigned)
311
312 uint8_t new_sfp_tx_control_flags; // NOLINT(build/unsigned)
313 if (turn_on)
314 {
315 new_sfp_tx_control_flags = current_sfp_tx_control_flags & ~(1UL << sfp_id);
316 }
317 else
318 {
319 new_sfp_tx_control_flags = current_sfp_tx_control_flags | (1UL << sfp_id);
320 }
321
322 sfp_expander_1->set_outputs(1, new_sfp_tx_control_flags);
323}
324//-----------------------------------------------------------------------------
325
326//-----------------------------------------------------------------------------
327//void
328//GIBIONode::get_info(timinghardwareinfo::TimingGIBMonitorData& mon_data) const
329//{
330 // TODO
331//}
332//-----------------------------------------------------------------------------
333
334//-----------------------------------------------------------------------------
335// void
336// GIBIONode::get_info(opmonlib::InfoCollector& /*ci*/, int /*level*/) const
337// {
338// // TO DO
339// }
340//-----------------------------------------------------------------------------
341
342//-----------------------------------------------------------------------------
343uint8_t
344GIBIONode::get_sfp_tx_disable_bitmap() const { // NOLINT(build/unsigned)
345 // First 6 bits are tx disable on GIBv1
346 return 0xC0;
347}
348//-----------------------------------------------------------------------------
349
350//-----------------------------------------------------------------------------
351uint8_t
352GIBIONode::get_num_sfps() const { // NOLINT(build/unsigned)
353 // 6 SFPs on GIBv1
354 return 6;
355}
356//-----------------------------------------------------------------------------
357
358//-----------------------------------------------------------------------------
359void
360GIBIONode::validate_sfp_id(uint32_t sfp_id) const { // NOLINT(build/unsigned)
361 // number of sfps on board defined by get_num_sfps
362 if (sfp_id >= get_num_sfps()) {
363 throw InvalidSFPId(ERS_HERE, format_reg_value(sfp_id));
364 }
365}
366//-----------------------------------------------------------------------------
367
368//-----------------------------------------------------------------------------
369void
370GIBIONode::set_i2c_mux_channels(uint8_t mux_channel_bitmask) const { // NOLINT(build/unsigned)
371
372 uint8_t mux_channel_config = mux_channel_bitmask & 0x7f;
373
374 auto i2c_bus = getNode<I2CMasterNode>("i2c");
375 i2c_bus.write_i2cPrimitive(0x70, {mux_channel_config});
376}
377//-----------------------------------------------------------------------------
378
379//-----------------------------------------------------------------------------
380float
382{
383 auto temp_mon = get_i2c_device<LM75Node>(m_pll_i2c_bus, "TEMP_MON");
384 return temp_mon->read_temperature();
385}
386//-----------------------------------------------------------------------------
387} // namespace timing
388} // namespace dunedaq
#define ERS_HERE
Class for the timing FMC board.
Definition GIBIONode.hpp:33
void switch_sfp_tx(uint32_t sfp_id, bool turn_on) const override
control tx laser of on-board SFP softly (I2C command)
virtual uint8_t read_sfps_fault() const
Retrive SFP fault status for all SFPs.
void set_i2c_mux_channels(uint8_t mux_channel_bitmask) const
Fill hardware monitoring structure.
void reset(const std::string &clock_config_file) const override
Reset GIB IO.
void set_up_io_infrastructure() const override
Set up i2c buses, enable ICs.
std::unique_ptr< const SI534xSlave > get_pll() const override
GET PLL I2C interface.
Definition GIBIONode.cpp:92
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)
virtual uint8_t get_num_sfps() const
virtual uint32_t read_io_expanders() const
Read the contents of the IO expanders.
void validate_sfp_id(uint32_t sfp_id) const
std::string get_hardware_info(bool print_out) const override
Print hardware information.
void reset_pll() const override
Reset PLL.
std::string get_uid_address_parameter_name() const override
Get the UID address parameter name.
Definition GIBIONode.cpp:45
GIBIONode(const uhal::Node &node)
Definition GIBIONode.cpp:21
void configure_expander() const
Configure the GIB expander.
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.
Definition GIBIONode.cpp:53
virtual uint8_t read_sfps_los() const
Retrive SFP LOS status for all SFPs.
bool clocks_ok() const override
Clocks ready?
virtual uint8_t get_sfp_tx_disable_bitmap() const
float read_board_temperature() const
Read board temp.
Base class for timing IO nodes.
Definition IONode.hpp:44
const std::string m_pll_i2c_bus
Definition IONode.hpp:211
const std::string m_pll_i2c_device
Definition IONode.hpp:212
virtual uint32_t read_carrier_type() const
Read the word identifying the FPFA carrier board.
Definition IONode.cpp:58
virtual std::string get_hardware_info(bool print_out=false) const
Print hardware information.
Definition IONode.cpp:118
const std::string m_uid_i2c_bus
Definition IONode.hpp:210
const std::vector< std::string > m_sfp_i2c_buses
Definition IONode.hpp:214
virtual void configure_pll(const std::string &clock_config_file="") const
Configure clock chip.
Definition IONode.cpp:238
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
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
CarrierType convert_value_to_carrier_type(uint32_t darrier_type)
Definition toolbox.cpp:287
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 vec_fmt(const std::vector< T > &vec)
Definition toolbox.hxx:382
std::string to_string(const T &v)
Definition toolbox.hxx:49
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
The DUNE-DAQ namespace.
void warning(const Issue &issue)
Definition ers.hpp:115