DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
MIBV2IONode.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(MIBV2IONode)
18
19//-----------------------------------------------------------------------------
20MIBV2IONode::MIBV2IONode(const uhal::Node& node)
21 : IONode(node, "i2c", "i2c", { "PLL" }, { "OSC", "PLL", "EP 0", "EP 1", "EP 2" }, { "sfp0_i2c", "sfp1_i2c", "sfp2_i2c" })
22{
23}
24//-----------------------------------------------------------------------------
25
26//-----------------------------------------------------------------------------
28//-----------------------------------------------------------------------------
29
30//-----------------------------------------------------------------------------
31std::string
33{
34 return "UID_PROM";
35}
36//-----------------------------------------------------------------------------
37
38//-----------------------------------------------------------------------------
39std::string
40MIBV2IONode::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, "MIB IO state");
46
47 if (print_out)
48 TLOG() << std::endl << status.str();
49 return status.str();
50}
51//-----------------------------------------------------------------------------
52
53//-----------------------------------------------------------------------------
54void
55MIBV2IONode::reset(const std::string& clock_config_file) const
56{
58
59 millisleep(1000);
60
61 // Upload config file to PLL
62 configure_pll(clock_config_file);
63
64 // Reset mmcm
65 getNode("csr.ctrl.rst").write(0x1);
66 getNode("csr.ctrl.rst").write(0x0);
67
68 getClient().dispatch();
69
70 TLOG() << "Reset done";
71}
72//-----------------------------------------------------------------------------
73
74//-----------------------------------------------------------------------------
75void
76MIBV2IONode::reset(const ClockSource& clock_source) const
77{
78 IONode::reset(clock_source);
79
80 switch_clock_source(clock_source);
81}
82//-----------------------------------------------------------------------------
83
84//-----------------------------------------------------------------------------
85void
87{
88 if (clock_source != kFreeRun)
89 {
90 getNode("csr.ctrl.pll_in_sel").write(clock_source);
91 getClient().dispatch();
92 }
93}
94//-----------------------------------------------------------------------------
95
96//-----------------------------------------------------------------------------
97std::string
98MIBV2IONode::get_sfp_status(uint32_t sfp_id, bool print_out) const { // NOLINT(build/unsigned)
99 std::stringstream status;
100
101 validate_sfp_id(sfp_id);
102
103 auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_id), "SFP_EEProm");
104
105 status << "SFP " << sfp_id << ":" << std::endl;
106 status << sfp->get_status();
107
108 if (print_out)
109 TLOG() << status.str();
110
111 return status.str();
112}
113//-----------------------------------------------------------------------------
114
115//-----------------------------------------------------------------------------
116bool
118{
119 std::stringstream status;
120
121 auto states = read_sub_nodes(getNode("csr.stat"));
122 bool pll_ok = states.find("pll_ok")->second.value();
123 bool mmcm_ok = states.find("mmcm_ok")->second.value();
124
125 TLOG_DEBUG(5) << "pll ok: " << pll_ok << ", mmcm ok: " << mmcm_ok;
126
127 return pll_ok && mmcm_ok;
128}
129//-----------------------------------------------------------------------------
130
131//-----------------------------------------------------------------------------
132void
133MIBV2IONode::switch_sfp_soft_tx_control_bit(uint32_t sfp_id, bool turn_on) const { // NOLINT(build/unsigned)
134 validate_sfp_id(sfp_id);
135
136 auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_id), "SFP_EEProm");
137 sfp->switch_soft_tx_control_bit(turn_on);
138}
139//-----------------------------------------------------------------------------
140
141//-----------------------------------------------------------------------------
142void
143MIBV2IONode::switch_sfp_tx(uint32_t /*sfp_id*/, bool /*turn_on*/) const // NOLINT(build/unsigned)
144{
145 // TODO firmware support needed
146 //validate_sfp_id(sfp_id);
147
148 //uint8_t current_sfp_tx_control_flags = getNode("csr.ctrl.sfp_tx_disable").read(); // NOLINT(build/unsigned)
149 //getClient().dispatch();
150
151 //uint8_t new_sfp_tx_control_flags; // NOLINT(build/unsigned)
152 //if (turn_on)
153 //{
154 // new_sfp_tx_control_flags = current_sfp_tx_control_flags & ~(1UL << sfp_id);
155 //}
156 //else
157 //{
158 // new_sfp_tx_control_flags = current_sfp_tx_control_flags | (1UL << sfp_id);
159 //}
160
161 //getNode("csr.ctrl.sfp_tx_disable").write(new_sfp_tx_control_flags);
162 //getClient().dispatch();
163}
164//-----------------------------------------------------------------------------
165
166//-----------------------------------------------------------------------------
167//void
168//MIBV2IONode::get_info(timinghardwareinfo::TimingMIBV2MonitorData& mon_data) const
169//{
170 // TODO
171//}
172//-----------------------------------------------------------------------------
173
174//-----------------------------------------------------------------------------
175// void
176// MIBV2IONode::get_info(opmonlib::InfoCollector& /*ci*/, int /*level*/) const
177// {
178// // TO DO
179// }
180//-----------------------------------------------------------------------------
181
182//-----------------------------------------------------------------------------
183void
184MIBV2IONode::validate_sfp_id(uint32_t sfp_id) const { // NOLINT(build/unsigned)
185 // on this board we have 3 upstream SFPs
186 if (sfp_id > 2) {
187 throw InvalidSFPId(ERS_HERE, format_reg_value(sfp_id));
188 }
189}
190//-----------------------------------------------------------------------------
191
192//-----------------------------------------------------------------------------
193void
194MIBV2IONode::validate_amc_slot(uint32_t amc_slot) const { // NOLINT(build/unsigned)
195 if (amc_slot < 1 || amc_slot > 12) {
196 throw InvalidAMCSlot(ERS_HERE, format_reg_value(amc_slot, 10));
197 }
198}
199//-----------------------------------------------------------------------------
200} // namespace timing
201} // namespace dunedaq
#define ERS_HERE
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
virtual void reset(const std::string &clock_config_file) const =0
Reset timing node.
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
Class for the timing FMC board.
void validate_sfp_id(uint32_t sfp_id) const
Fill hardware monitoring structure.
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 reset(const std::string &clock_config_file) const override
Reset MIB v2 IO.
std::string get_sfp_status(uint32_t sfp_id, bool print_out=false) const override
Print status of on-board SFP.
void switch_clock_source(const ClockSource &clock_source) const
Switch clock input, with clock file look up and upload if necessary.
std::string get_status(bool print_out=false) const override
Get status string, optionally print.
void switch_sfp_tx(uint32_t sfp_id, bool turn_on) const override
control tx laser of on-board SFP
bool clocks_ok() const override
Clocks ready?
void validate_amc_slot(uint32_t amc_slot) const
std::string get_uid_address_parameter_name() const override
Get the UID address parameter name.
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.