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//-----------------------------------------------------------------------------
86{
87}
88//-----------------------------------------------------------------------------
89
90//-----------------------------------------------------------------------------
91void
93{
94 if (clock_source != kFreeRun)
95 {
96 getNode("csr.ctrl.pll_in_sel").write(clock_source);
97 getClient().dispatch();
98 }
99}
100//-----------------------------------------------------------------------------
101
102//-----------------------------------------------------------------------------
103std::string
104MIBV2IONode::get_sfp_status(uint32_t sfp_id, bool print_out) const { // NOLINT(build/unsigned)
105 std::stringstream status;
106
107 validate_sfp_id(sfp_id);
108
109 auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_id), "SFP_EEProm");
110
111 status << "SFP " << sfp_id << ":" << std::endl;
112 status << sfp->get_status();
113
114 if (print_out)
115 TLOG() << status.str();
116
117 return status.str();
118}
119//-----------------------------------------------------------------------------
120
121//-----------------------------------------------------------------------------
122bool
124{
125 std::stringstream status;
126
127 auto states = read_sub_nodes(getNode("csr.stat"));
128 bool pll_ok = states.find("pll_ok")->second.value();
129 bool mmcm_ok = states.find("mmcm_ok")->second.value();
130
131 TLOG_DEBUG(5) << "pll ok: " << pll_ok << ", mmcm ok: " << mmcm_ok;
132
133 return pll_ok && mmcm_ok;
134}
135//-----------------------------------------------------------------------------
136
137//-----------------------------------------------------------------------------
138void
139MIBV2IONode::switch_sfp_soft_tx_control_bit(uint32_t sfp_id, bool turn_on) const { // NOLINT(build/unsigned)
140 validate_sfp_id(sfp_id);
141
142 auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_id), "SFP_EEProm");
143 sfp->switch_soft_tx_control_bit(turn_on);
144}
145//-----------------------------------------------------------------------------
146
147//-----------------------------------------------------------------------------
148void
149MIBV2IONode::switch_sfp_tx(uint32_t /*sfp_id*/, bool /*turn_on*/) const // NOLINT(build/unsigned)
150{
151 // TODO firmware support needed
152 //validate_sfp_id(sfp_id);
153
154 //uint8_t current_sfp_tx_control_flags = getNode("csr.ctrl.sfp_tx_disable").read(); // NOLINT(build/unsigned)
155 //getClient().dispatch();
156
157 //uint8_t new_sfp_tx_control_flags; // NOLINT(build/unsigned)
158 //if (turn_on)
159 //{
160 // new_sfp_tx_control_flags = current_sfp_tx_control_flags & ~(1UL << sfp_id);
161 //}
162 //else
163 //{
164 // new_sfp_tx_control_flags = current_sfp_tx_control_flags | (1UL << sfp_id);
165 //}
166
167 //getNode("csr.ctrl.sfp_tx_disable").write(new_sfp_tx_control_flags);
168 //getClient().dispatch();
169}
170//-----------------------------------------------------------------------------
171
172//-----------------------------------------------------------------------------
173//void
174//MIBV2IONode::get_info(timinghardwareinfo::TimingMIBV2MonitorData& mon_data) const
175//{
176 // TODO
177//}
178//-----------------------------------------------------------------------------
179
180//-----------------------------------------------------------------------------
181// void
182// MIBV2IONode::get_info(opmonlib::InfoCollector& /*ci*/, int /*level*/) const
183// {
184// // TO DO
185// }
186//-----------------------------------------------------------------------------
187
188//-----------------------------------------------------------------------------
189void
190MIBV2IONode::validate_sfp_id(uint32_t sfp_id) const { // NOLINT(build/unsigned)
191 // on this board we have 3 upstream SFPs
192 if (sfp_id > 2) {
193 throw InvalidSFPId(ERS_HERE, format_reg_value(sfp_id));
194 }
195}
196//-----------------------------------------------------------------------------
197
198//-----------------------------------------------------------------------------
199void
200MIBV2IONode::validate_amc_slot(uint32_t amc_slot) const { // NOLINT(build/unsigned)
201 if (amc_slot < 1 || amc_slot > 12) {
202 throw InvalidAMCSlot(ERS_HERE, format_reg_value(amc_slot, 10));
203 }
204}
205//-----------------------------------------------------------------------------
206} // namespace timing
207} // 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:287
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: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
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.
void reset_pll() const override
Reset PLL.
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
The DUNE-DAQ namespace.
Definition DataStore.hpp:57