DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
GIBIONode.cpp
Go to the documentation of this file.
1
10
11#include <string>
12#include <math.h>
13
14namespace dunedaq {
15namespace timing {
16
17UHAL_REGISTER_DERIVED_NODE(GIBIONode)
18
19//-----------------------------------------------------------------------------
20GIBIONode::GIBIONode(const uhal::Node& node)
21 : 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" })
22{
23}
24//-----------------------------------------------------------------------------
25
26//-----------------------------------------------------------------------------
28//-----------------------------------------------------------------------------
29
30//-----------------------------------------------------------------------------
31std::string
33{
34 return "UID_PROM";
35}
36//-----------------------------------------------------------------------------
37
38//-----------------------------------------------------------------------------
39std::string
40GIBIONode::get_status(bool print_out) const
41{
42 std::stringstream status;
43
44 auto subnodes = read_sub_nodes(getNode("csr.stat"));
45 status << format_reg_table(subnodes, "GIB IO state");
46
47 if (print_out)
48 TLOG() << std::endl << status.str();
49 return status.str();
50}
51//-----------------------------------------------------------------------------
52
53//-----------------------------------------------------------------------------
54std::unique_ptr<const SI534xSlave>
56{
57 // enable pll channel 0 only
60}
61//-----------------------------------------------------------------------------
62
63//-----------------------------------------------------------------------------
64std::string
65GIBIONode::get_hardware_info(bool print_out) const
66{
67 // enable pll/uid channel 0 only
69 return IONode::get_hardware_info(print_out);
70}
71//-----------------------------------------------------------------------------
72
73//-----------------------------------------------------------------------------
74void
75GIBIONode::reset(const std::string& clock_config_file) const
76{
77
79
80 // Reset I2C switch and expander, active low
81 getNode("csr.ctrl.i2c_sw_rst").write(0x0);
82 getNode("csr.ctrl.i2c_exten_rst").write(0x0);
83 getNode("csr.ctrl.clk_gen_rst").write(0x0);
84 getClient().dispatch();
85
86 millisleep(1);
87
88 // End reset
89 getNode("csr.ctrl.i2c_sw_rst").write(0x1);
90 getNode("csr.ctrl.i2c_exten_rst").write(0x1);
91 getNode("csr.ctrl.clk_gen_rst").write(0x1);
92 getClient().dispatch();
93
95
96 // enclustra i2c switch stuff
97 if (carrier_type == kCarrierEnclustraA35) {
98 try {
99 getNode<I2CMasterNode>(m_uid_i2c_bus).get_slave("AX3_Switch").write_i2c(0x01, 0x7f);
100 } catch (const std::exception& e) {
101 ers::warning(EnclustraSwitchFailure(ERS_HERE, e));
102 }
103 }
104
105 getNode("csr.ctrl.gps_clk_en").write(0x0);
106
107 // Set filter to full bandwidth mode A = B = 0x0
108 getNode("csr.ctrl.gps_clk_fltr_a").write(0x0);
109 getNode("csr.ctrl.gps_clk_fltr_b").write(0x0);
110 getClient().dispatch();
111
112 // Upload config file to PLL
113 configure_pll(clock_config_file);
114
115 getNode("csr.ctrl.rst").write(0x1);
116 getNode("csr.ctrl.rst").write(0x0);
117 getClient().dispatch();
118
119 auto sfp_expander_0 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander0");
120 auto sfp_expander_1 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander1");
121
122 // Set invert registers to default for both (0,1) banks
123 sfp_expander_0->set_inversion(0, 0x00);
124 sfp_expander_0->set_inversion(1, 0x00);
125 sfp_expander_1->set_inversion(0, 0x00);
126 sfp_expander_1->set_inversion(1, 0x00);
127
128 // 0: pin set as output, 1: pin set as input
129 sfp_expander_0->set_io(0, 0xff); // set all pins of bank 0 as inputs
130 sfp_expander_0->set_io(1, 0xff); // set all pins of bank 1 as inputs
131
132 sfp_expander_1->set_io(0, 0xff); // set all pins of bank 0 as inputs
133 sfp_expander_1->set_io(1, 0x00); // set all pins of bank 1 as outputs
134
135 // Set SFP disable
136 // Set pins 1-6 low, i.e. enable SFP 1-6 (pins 7,8 unused)
137 sfp_expander_1->set_outputs(1, 0xC0);
138
139 TLOG() << "Reset done";
140}
141//-----------------------------------------------------------------------------
142
143//-----------------------------------------------------------------------------
144std::string
145GIBIONode::get_sfp_status(uint32_t sfp_id, bool print_out) const { // NOLINT(build/unsigned)
146 std::stringstream status;
147
148 validate_sfp_id(sfp_id);
149
150 uint8_t i2c_mux_bitmask = 1UL << (sfp_id+1);
151
152 set_i2c_mux_channels(i2c_mux_bitmask);
153
154 auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_id), "SFP_EEProm");
155
156 status << "SFP " << sfp_id << ":" << std::endl;
157 status << sfp->get_status();
158
159 if (print_out)
160 TLOG() << status.str();
161
162 return status.str();
163}
164//-----------------------------------------------------------------------------
165
166//-----------------------------------------------------------------------------
167bool
169{
170 std::stringstream status;
171
172 auto states = read_sub_nodes(getNode("csr.stat"));
173 bool pll_lol = states.find("clk_gen_lol")->second.value();
174 bool pll_interrupt = states.find("clk_gen_intr")->second.value();
175 bool mmcm_ok = states.find("mmcm_ok")->second.value();
176 bool mmcm_10_ok = states.find("mmcm_ok")->second.value();
177
178 TLOG_DEBUG(5) << "pll lol: " << pll_lol << ", pll intr: " << pll_interrupt
179 << ", mmcm ok: " << mmcm_ok << ", mmcm 10MHz ok: " << mmcm_10_ok;
180
181 return !pll_lol && mmcm_ok && mmcm_10_ok;
182}
183//-----------------------------------------------------------------------------
184
185//-----------------------------------------------------------------------------
186void
187GIBIONode::switch_sfp_soft_tx_control_bit(uint32_t sfp_id, bool turn_on) const { // NOLINT(build/unsigned)
188 validate_sfp_id(sfp_id);
189
190 auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_id), "SFP_EEProm");
191 sfp->switch_soft_tx_control_bit(turn_on);
192}
193//-----------------------------------------------------------------------------
194
195//-----------------------------------------------------------------------------
196void
197GIBIONode::switch_sfp_tx(uint32_t sfp_id, bool turn_on) const { // NOLINT(build/unsigned)
198 validate_sfp_id(sfp_id);
199
200 auto sfp_expander_1 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander1");
201 uint8_t current_sfp_tx_control_flags = sfp_expander_1->read_outputs_config(1); // NOLINT(build/unsigned)
202
203 uint8_t new_sfp_tx_control_flags; // NOLINT(build/unsigned)
204 if (turn_on)
205 {
206 new_sfp_tx_control_flags = current_sfp_tx_control_flags & ~(1UL << sfp_id);
207 }
208 else
209 {
210 new_sfp_tx_control_flags = current_sfp_tx_control_flags | (1UL << sfp_id);
211 }
212
213 sfp_expander_1->set_outputs(1, new_sfp_tx_control_flags);
214}
215//-----------------------------------------------------------------------------
216
217//-----------------------------------------------------------------------------
218//void
219//GIBIONode::get_info(timinghardwareinfo::TimingGIBMonitorData& mon_data) const
220//{
221 // TODO
222//}
223//-----------------------------------------------------------------------------
224
225//-----------------------------------------------------------------------------
226// void
227// GIBIONode::get_info(opmonlib::InfoCollector& /*ci*/, int /*level*/) const
228// {
229// // TO DO
230// }
231//-----------------------------------------------------------------------------
232
233//-----------------------------------------------------------------------------
234void
235GIBIONode::validate_sfp_id(uint32_t sfp_id) const { // NOLINT(build/unsigned)
236 // on this board we have 6 SFPs
237 if (sfp_id > 5) {
238 throw InvalidSFPId(ERS_HERE, format_reg_value(sfp_id));
239 }
240}
241//-----------------------------------------------------------------------------
242
243//-----------------------------------------------------------------------------
244void
245GIBIONode::set_i2c_mux_channels(uint8_t mux_channel_bitmask) const { // NOLINT(build/unsigned)
246
247 uint8_t mux_channel_config = mux_channel_bitmask & 0x7f;
248
249 auto i2c_bus = getNode<I2CMasterNode>("i2c");
250 i2c_bus.write_i2cPrimitive(0x70, {mux_channel_config});
251}
252//-----------------------------------------------------------------------------
253
254} // namespace timing
255} // 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)
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.
Definition GIBIONode.cpp:75
std::unique_ptr< const SI534xSlave > get_pll() const override
GET PLL I2C interface.
Definition GIBIONode.cpp:55
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)
void validate_sfp_id(uint32_t sfp_id) const
std::string get_hardware_info(bool print_out) const override
Print hardware information.
Definition GIBIONode.cpp:65
std::string get_uid_address_parameter_name() const override
Get the UID address parameter name.
Definition GIBIONode.cpp:32
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:40
bool clocks_ok() const override
Clocks ready?
Base class for timing IO nodes.
Definition IONode.hpp:44
virtual void write_soft_reset_register() const
Write soft reset register.
Definition IONode.cpp:296
const std::string m_pll_i2c_bus
Definition IONode.hpp:201
const std::string m_pll_i2c_device
Definition IONode.hpp:202
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:200
const std::vector< std::string > m_sfp_i2c_buses
Definition IONode.hpp:204
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
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 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