DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
GIBV3IONode.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(GIBV3IONode)
18
19//-----------------------------------------------------------------------------
20GIBV3IONode::GIBV3IONode(const uhal::Node& node)
21 : GIBV2IONode(node)
22{
23}
24//-----------------------------------------------------------------------------
25
26//-----------------------------------------------------------------------------
28//-----------------------------------------------------------------------------
29
30//-----------------------------------------------------------------------------
31std::string
32GIBV3IONode::get_status(bool print_out) const
33{
34 std::stringstream status;
35
36 auto subnodes = read_sub_nodes(getNode("csr.stat"));
37 status << format_reg_table(subnodes, "GIB IO state");
38
39 auto subnodes_2 = read_sub_nodes(getNode("csr.ctrl"));
40 status << format_reg_table(subnodes_2, "GIB IO control");
41
42 uint8_t sfp_los = read_sfps_los();
43 uint8_t sfp_fault = read_sfps_fault();
44
45 std::vector<std::string> sfp_vec;
46 std::vector<uint8_t> los_vec;
47 std::vector<uint8_t> fault_vec;
48
49 for (int i=0; i<get_num_sfps(); i++) {
50 sfp_vec.push_back(to_string(i));
51 // L is 0x4C, H is L - 4
52 los_vec.push_back(0x4C - 4*((sfp_los >> i) & 1));
53 fault_vec.push_back(0x4C - 4*((sfp_fault >> i) & 1));
54 }
55
56 status << "-----IO expander------" << std::endl;
57 status << "SFP: " << vec_fmt(sfp_vec) << std::endl;
58 status << "LOS: " << vec_fmt(los_vec) << std::endl;
59 status << "Fault: " << vec_fmt(fault_vec) << std::endl;
60
61 // removed temperature readout
62
63 if (print_out)
64 TLOG() << std::endl << status.str();
65 return status.str();
66}
67//-----------------------------------------------------------------------------
68
69//-----------------------------------------------------------------------------
70uint32_t
71GIBV3IONode::read_io_expanders() const { // NOLINT(build/unsigned)
72 auto sfp_expander_0 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander0");
73
74 uint32_t expander_bits = sfp_expander_0->read_inputs(1);
75 expander_bits = (expander_bits << 8) + sfp_expander_0->read_inputs(0);
76
77 return expander_bits;
78}
79//-----------------------------------------------------------------------------
80
81//-----------------------------------------------------------------------------
82uint8_t
83GIBV3IONode::read_sfps_los() const { // NOLINT(build/unsigned)
84 uint32_t expander_bits = read_io_expanders();
85
86 // A-CLK LOS is 1st bit
87 uint8_t los_bits = static_cast<uint8_t>(expander_bits & 1);
88
89 uint32_t los_bitmask = 0x003f;
90
91 uhal::ValWord<uint32_t> los_reg_data = getNode("csr.stat.sfp_los").read();
92 getClient().dispatch();
93
94 los_bits = (los_bits << 6) + static_cast<uint8_t>(los_reg_data & los_bitmask);
95
96 return los_bits;
97}
98//-----------------------------------------------------------------------------
99
100//-----------------------------------------------------------------------------
101uint8_t
102GIBV3IONode::read_sfps_fault() const { // NOLINT(build/unsigned)
103 uint32_t expander_bits = read_io_expanders();
104
105 // A-CLK fault is 2nd bit
106 uint8_t fault_bits = static_cast<uint8_t>((expander_bits >> 1) & 1);
107
108 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 fault_bits = (fault_bits << 1) + ((expander_bits >> (8 + 5 - sfp)) & 1);
112 }
113
114 return fault_bits;
115}
116//-----------------------------------------------------------------------------
117
118} // namespace timing
119} // namespace dunedaq
Class for the timing FMC board.
uint8_t get_num_sfps() const override
Class for the timing FMC board.
uint32_t read_io_expanders() const override
Read the contents of the IO expanders.
uint8_t read_sfps_los() const override
Retrive SFP LOS status for all SFPs.
uint8_t read_sfps_fault() const override
Retrive SFP fault status for all SFPs.
std::string get_status(bool print_out=false) const override
Get status string, optionally print.
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(...)
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 vec_fmt(const std::vector< T > &vec)
Definition toolbox.hxx:382
std::string to_string(const T &v)
Definition toolbox.hxx:49
The DUNE-DAQ namespace.