DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
GIBV2IONode.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(GIBV2IONode)
18
19//-----------------------------------------------------------------------------
20GIBV2IONode::GIBV2IONode(const uhal::Node& node)
21 : GIBIONode(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", "i2c" })
22{
23}
24//-----------------------------------------------------------------------------
25
26//-----------------------------------------------------------------------------
28//-----------------------------------------------------------------------------
29
30//-----------------------------------------------------------------------------
31uint8_t
32GIBV2IONode::read_sfps_los() const { // NOLINT(build/unsigned)
33 uint32_t expander_bits = read_io_expanders();
34
35 // A-CLK LOS is 1st bit
36 uint8_t los_bits = static_cast<uint8_t>(expander_bits & 0b01);
37
38 for (uint8_t sfp = 0; sfp<6; sfp++) {
39 // Each SFP has 4 bits, the 3rd bit is the LOS
40 // Adds the SFPs in inverse order
41 los_bits = (los_bits << 1) + ((expander_bits >> (2 + 20 - 4*sfp)) & 1);
42 }
43
44 return los_bits;
45}
46//-----------------------------------------------------------------------------
47
48//-----------------------------------------------------------------------------
49uint8_t
50GIBV2IONode::read_sfps_fault() const { // NOLINT(build/unsigned)
51 uint32_t expander_bits = read_io_expanders();
52
53 // A-CLK fault is 2nd bit
54 uint8_t fault_bits = static_cast<uint8_t>(expander_bits & 0b10);
55
56 for (uint8_t sfp = 0; sfp<6; sfp++) {
57 // Each SFP has 4 bits, the 4th bit is the fault
58 // Adds the SFPs in inverse order
59 fault_bits = (fault_bits << 1) + ((expander_bits >> (3 + 20 - 4*sfp)) & 1);
60 }
61
62 return fault_bits;
63}
64//-----------------------------------------------------------------------------
65
66//-----------------------------------------------------------------------------
67bool
69{
70 std::stringstream status;
71
72 auto states = read_sub_nodes(getNode("csr.stat"));
73 bool pll_lol = states.find("clk_gen_lol")->second.value();
74 //bool pll_interrupt = states.find("clk_gen_intr")->second.value();
75 bool mmcm_ok = states.find("mmcm_ok")->second.value();
76
77 TLOG_DEBUG(5) << "pll lol: " << pll_lol << ", mmcm ok: " << mmcm_ok;
78
79 return !pll_lol && mmcm_ok;
80}
81//-----------------------------------------------------------------------------
82
83//-----------------------------------------------------------------------------
84void
85GIBV2IONode::switch_sfp_tx(uint32_t sfp_id, bool turn_on) const { // NOLINT(build/unsigned)
86 validate_sfp_id(sfp_id);
87
88 // A-CLK is the 7th SFP, but is in slot 7 not 6
89 // TODO make this a map dlindebaum 25/10/02
90 sfp_id = sfp_id + (sfp_id/6);
91
92 auto sfp_expander_1 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander1");
93 uint8_t current_sfp_tx_control_flags = sfp_expander_1->read_outputs_config(1); // NOLINT(build/unsigned)
94
95 uint8_t new_sfp_tx_control_flags; // NOLINT(build/unsigned)
96 if (turn_on)
97 {
98 new_sfp_tx_control_flags = current_sfp_tx_control_flags & ~(1UL << sfp_id);
99 }
100 else
101 {
102 new_sfp_tx_control_flags = current_sfp_tx_control_flags | (1UL << sfp_id);
103 }
104
105 sfp_expander_1->set_outputs(1, new_sfp_tx_control_flags);
106}
107//-----------------------------------------------------------------------------
108
109//-----------------------------------------------------------------------------
110uint8_t
111GIBV2IONode::get_sfp_tx_disable_bitmap() const { // NOLINT(build/unsigned)
112 // First 6 bits and the 8th bit are tx disable for GIBv2/3
113 return 0x40;
114}
115//-----------------------------------------------------------------------------
116
117//-----------------------------------------------------------------------------
118uint8_t
119GIBV2IONode::get_num_sfps() const { // NOLINT(build/unsigned)
120 // 7 SFPs on GIBv2/3
121 return 7;
122}
123//-----------------------------------------------------------------------------
124
125} // namespace timing
126} // namespace dunedaq
Class for the timing FMC board.
Definition GIBIONode.hpp:33
virtual uint32_t read_io_expanders() const
Read the contents of the IO expanders.
void validate_sfp_id(uint32_t sfp_id) const
Class for the timing FMC board.
uint8_t get_num_sfps() const override
uint8_t read_sfps_fault() const override
Retrive SFP fault status for all SFPs.
uint8_t read_sfps_los() const override
Retrive SFP LOS status for all SFPs.
bool clocks_ok() const override
Clocks ready?
uint8_t get_sfp_tx_disable_bitmap() const override
void switch_sfp_tx(uint32_t sfp_id, bool turn_on) const override
control tx laser of on-board SFP softly (I2C command)
const std::string m_uid_i2c_bus
Definition IONode.hpp:210
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
The DUNE-DAQ namespace.