Line data Source code
1 : /**
2 : * @file GIBV3IONode.cpp
3 : *
4 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "timing/GIBV3IONode.hpp"
10 :
11 : #include <string>
12 : #include <math.h>
13 :
14 : namespace dunedaq {
15 : namespace timing {
16 :
17 0 : UHAL_REGISTER_DERIVED_NODE(GIBV3IONode)
18 :
19 : //-----------------------------------------------------------------------------
20 0 : GIBV3IONode::GIBV3IONode(const uhal::Node& node)
21 0 : : GIBV2IONode(node)
22 : {
23 0 : }
24 : //-----------------------------------------------------------------------------
25 :
26 : //-----------------------------------------------------------------------------
27 0 : GIBV3IONode::~GIBV3IONode() {}
28 : //-----------------------------------------------------------------------------
29 :
30 : //-----------------------------------------------------------------------------
31 : std::string
32 0 : GIBV3IONode::get_status(bool print_out) const
33 : {
34 0 : std::stringstream status;
35 :
36 0 : auto subnodes = read_sub_nodes(getNode("csr.stat"));
37 0 : status << format_reg_table(subnodes, "GIB IO state");
38 :
39 0 : auto subnodes_2 = read_sub_nodes(getNode("csr.ctrl"));
40 0 : status << format_reg_table(subnodes_2, "GIB IO control");
41 :
42 0 : uint8_t sfp_los = read_sfps_los();
43 0 : uint8_t sfp_fault = read_sfps_fault();
44 :
45 0 : std::vector<std::string> sfp_vec;
46 0 : std::vector<uint8_t> los_vec;
47 0 : std::vector<uint8_t> fault_vec;
48 :
49 0 : for (int i=0; i<get_num_sfps(); i++) {
50 0 : sfp_vec.push_back(to_string(i));
51 : // L is 0x4C, H is L - 4
52 0 : los_vec.push_back(0x4C - 4*((sfp_los >> i) & 1));
53 0 : fault_vec.push_back(0x4C - 4*((sfp_fault >> i) & 1));
54 : }
55 :
56 0 : status << "-----IO expander------" << std::endl;
57 0 : status << "SFP: " << vec_fmt(sfp_vec) << std::endl;
58 0 : status << "LOS: " << vec_fmt(los_vec) << std::endl;
59 0 : status << "Fault: " << vec_fmt(fault_vec) << std::endl;
60 :
61 : // removed temperature readout
62 :
63 0 : if (print_out)
64 0 : TLOG() << std::endl << status.str();
65 0 : return status.str();
66 0 : }
67 : //-----------------------------------------------------------------------------
68 :
69 : //-----------------------------------------------------------------------------
70 : uint32_t
71 0 : GIBV3IONode::read_io_expanders() const { // NOLINT(build/unsigned)
72 0 : auto sfp_expander_0 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander0");
73 :
74 0 : uint32_t expander_bits = sfp_expander_0->read_inputs(1);
75 0 : expander_bits = (expander_bits << 8) + sfp_expander_0->read_inputs(0);
76 :
77 0 : return expander_bits;
78 0 : }
79 : //-----------------------------------------------------------------------------
80 :
81 : //-----------------------------------------------------------------------------
82 : uint8_t
83 0 : GIBV3IONode::read_sfps_los() const { // NOLINT(build/unsigned)
84 0 : uint32_t expander_bits = read_io_expanders();
85 :
86 : // A-CLK LOS is 1st bit
87 0 : uint8_t los_bits = static_cast<uint8_t>(expander_bits & 1);
88 :
89 0 : uint32_t los_bitmask = 0x003f;
90 :
91 0 : uhal::ValWord<uint32_t> los_reg_data = getNode("csr.stat.sfp_los").read();
92 0 : getClient().dispatch();
93 :
94 0 : los_bits = (los_bits << 6) + static_cast<uint8_t>(los_reg_data & los_bitmask);
95 :
96 0 : return los_bits;
97 0 : }
98 : //-----------------------------------------------------------------------------
99 :
100 : //-----------------------------------------------------------------------------
101 : uint8_t
102 0 : GIBV3IONode::read_sfps_fault() const { // NOLINT(build/unsigned)
103 0 : uint32_t expander_bits = read_io_expanders();
104 :
105 : // A-CLK fault is 2nd bit
106 0 : uint8_t fault_bits = static_cast<uint8_t>((expander_bits >> 1) & 1);
107 :
108 0 : for (uint8_t sfp = 0; sfp<6; sfp++) {
109 : // SFP faults are 0-5 on second bus of first expander
110 : // Adds the SFPs in reverse order
111 0 : fault_bits = (fault_bits << 1) + ((expander_bits >> (8 + 5 - sfp)) & 1);
112 : }
113 :
114 0 : return fault_bits;
115 : }
116 : //-----------------------------------------------------------------------------
117 :
118 : } // namespace timing
119 : } // namespace dunedaq
|