LCOV - code coverage report
Current view: top level - timing/src - GIBIONode.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 165 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 28 0

            Line data    Source code
       1              : /**
       2              :  * @file GIBIONode.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/GIBIONode.hpp"
      10              : #include "timing/LM75Node.hpp"
      11              : 
      12              : #include <string>
      13              : #include <math.h>
      14              : 
      15              : namespace dunedaq {
      16              : namespace timing {
      17              : 
      18            0 : UHAL_REGISTER_DERIVED_NODE(GIBIONode)
      19              : 
      20              : //-----------------------------------------------------------------------------
      21            0 : GIBIONode::GIBIONode(const uhal::Node& node)
      22            0 :   : IONode(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" })
      23              : {
      24            0 : }
      25              : //-----------------------------------------------------------------------------
      26              : 
      27              : //-----------------------------------------------------------------------------
      28            0 : GIBIONode::GIBIONode(const uhal::Node& node,
      29              :                std::string uid_i2c_bus,
      30              :                std::string pll_i2c_bus,
      31              :                std::string pll_i2c_device,
      32              :                std::vector<std::string> clock_names,
      33            0 :                std::vector<std::string> sfp_i2c_buses)
      34            0 :   : IONode(node, uid_i2c_bus, pll_i2c_bus, pll_i2c_device, clock_names, sfp_i2c_buses)
      35              : {
      36            0 : }
      37              : //-----------------------------------------------------------------------------
      38              : 
      39              : //-----------------------------------------------------------------------------
      40            0 : GIBIONode::~GIBIONode() {}
      41              : //-----------------------------------------------------------------------------
      42              : 
      43              : //-----------------------------------------------------------------------------
      44              : std::string
      45            0 : GIBIONode::get_uid_address_parameter_name() const
      46              : {
      47            0 :   return "UID_PROM";
      48              : }
      49              : //-----------------------------------------------------------------------------
      50              : 
      51              : //-----------------------------------------------------------------------------
      52              : std::string
      53            0 : GIBIONode::get_status(bool print_out) const
      54              : {
      55            0 :   std::stringstream status;
      56              : 
      57            0 :   auto subnodes = read_sub_nodes(getNode("csr.stat"));
      58            0 :   status << format_reg_table(subnodes, "GIB IO state");
      59              : 
      60            0 :   auto subnodes_2 = read_sub_nodes(getNode("csr.ctrl"));
      61            0 :   status << format_reg_table(subnodes_2, "GIB IO control");
      62              : 
      63            0 :   uint8_t sfp_los = read_sfps_los();
      64            0 :   uint8_t sfp_fault = read_sfps_fault();
      65              : 
      66            0 :   std::vector<std::string> sfp_vec;
      67            0 :   std::vector<uint8_t> los_vec;
      68            0 :   std::vector<uint8_t> fault_vec;
      69              : 
      70            0 :   for (int i=0; i<get_num_sfps(); i++) {
      71            0 :     sfp_vec.push_back(to_string(i));
      72              :     // L is 0x4C, H is L - 4
      73            0 :     los_vec.push_back(0x4C - 4*((sfp_los >> i) & 1));
      74            0 :     fault_vec.push_back(0x4C - 4*((sfp_fault >> i) & 1));
      75              :   }
      76              :   
      77            0 :   status << "------IO expander----" << std::endl;
      78            0 :   status << "SFP:   " << vec_fmt(sfp_vec) << std::endl;
      79            0 :   status << "LOS:   " << vec_fmt(los_vec) << std::endl;
      80            0 :   status << "Fault: " << vec_fmt(fault_vec) << std::endl;
      81              : 
      82            0 :   status << "Board temperature: " << read_board_temperature() << " [C]" << std::endl;
      83              : 
      84            0 :   if (print_out)
      85            0 :     TLOG() << std::endl << status.str();
      86            0 :   return status.str();
      87            0 : }
      88              : //-----------------------------------------------------------------------------
      89              : 
      90              : //-----------------------------------------------------------------------------
      91              : std::unique_ptr<const SI534xSlave>
      92            0 : GIBIONode::get_pll() const
      93              : {
      94              :   // enable pll channel 0 only
      95            0 :   set_i2c_mux_channels(0x1);
      96            0 :   return get_i2c_device<SI534xSlave>(m_pll_i2c_bus, m_pll_i2c_device);
      97              : }
      98              : //-----------------------------------------------------------------------------
      99              : 
     100              : //-----------------------------------------------------------------------------
     101              : std::string
     102            0 : GIBIONode::get_hardware_info(bool print_out) const
     103              : {
     104              :   // enable pll/uid channel 0 only
     105            0 :   set_i2c_mux_channels(0x1);
     106            0 :   return IONode::get_hardware_info(print_out);
     107              : }
     108              : //-----------------------------------------------------------------------------
     109              : 
     110              : //-----------------------------------------------------------------------------
     111              : void
     112            0 : GIBIONode::set_up_io_infrastructure() const
     113              : {
     114              :   // enclustra i2c switch stuff
     115            0 :   CarrierType carrier_type = convert_value_to_carrier_type(read_carrier_type());
     116            0 :   if (carrier_type == kCarrierEnclustraA35) {
     117            0 :     try {
     118            0 :       getNode<I2CMasterNode>(m_uid_i2c_bus).get_slave("AX3_Switch").write_i2c(0x01, 0x7f);
     119            0 :     } catch (const std::exception& e) {
     120            0 :       ers::warning(EnclustraSwitchFailure(ERS_HERE, e));
     121            0 :     }
     122              :   }
     123              : 
     124              :   // Reset I2C switch and expander, active low
     125            0 :   getNode("csr.ctrl.i2c_sw_rst").write(0x0);
     126            0 :   getNode("csr.ctrl.i2c_exten_rst").write(0x0);
     127            0 :   getNode("csr.ctrl.clk_gen_rst").write(0x0);
     128            0 :   getClient().dispatch();
     129              : 
     130            0 :   millisleep(1);
     131              : 
     132              :   // End reset 
     133            0 :   getNode("csr.ctrl.i2c_sw_rst").write(0x1);
     134            0 :   getNode("csr.ctrl.i2c_exten_rst").write(0x1);
     135            0 :   getNode("csr.ctrl.clk_gen_rst").write(0x1);
     136            0 :   getClient().dispatch();
     137              : 
     138            0 :   set_i2c_mux_channels(0x1);
     139            0 : }
     140              : //-----------------------------------------------------------------------------
     141              : 
     142              : //-----------------------------------------------------------------------------
     143              : void
     144            0 : GIBIONode::reset(const std::string& clock_config_file) const
     145              : {
     146            0 :   getNode("csr.ctrl.rst").write(0x1);
     147            0 :   getNode("csr.ctrl.rst").write(0x0);
     148            0 :   getClient().dispatch();
     149              : 
     150            0 :   set_up_io_infrastructure();
     151              : 
     152            0 :   getNode("csr.ctrl.gps_clk_en").write(0x0);
     153              : 
     154              :   // Set filter to full bandwidth mode A = B = 0x0
     155            0 :   getNode("csr.ctrl.gps_clk_fltr_a").write(0x0);
     156            0 :   getNode("csr.ctrl.gps_clk_fltr_b").write(0x0);
     157            0 :   getClient().dispatch();
     158              : 
     159              :   // Upload config file to PLL
     160            0 :   configure_pll(clock_config_file);
     161              : 
     162            0 :   configure_expander();
     163              : 
     164            0 :   TLOG() << "Reset done";
     165            0 : }
     166              : //-----------------------------------------------------------------------------
     167              : 
     168              : //-----------------------------------------------------------------------------
     169              : void
     170            0 : GIBIONode::configure_expander() const
     171              : {
     172            0 :   auto sfp_expander_0 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander0");
     173            0 :   auto sfp_expander_1 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander1");
     174              :   
     175              :   // Set invert registers to default for both (0,1) banks
     176            0 :   sfp_expander_0->set_inversion(0, 0x00);
     177            0 :   sfp_expander_0->set_inversion(1, 0x00);
     178            0 :   sfp_expander_1->set_inversion(0, 0x00);
     179            0 :   sfp_expander_1->set_inversion(1, 0x00);
     180              :   
     181              :   // 0: pin set as output, 1: pin set as input
     182            0 :   sfp_expander_0->set_io(0, 0xff); // set all pins of bank 0 as inputs
     183            0 :   sfp_expander_0->set_io(1, 0xff); // set all pins of bank 1 as inputs
     184              : 
     185            0 :   sfp_expander_1->set_io(0, 0xff); // set all pins of bank 0 as inputs
     186            0 :   sfp_expander_1->set_io(1, 0x00); // set all pins of bank 1 as outputs
     187              : 
     188              :   // Set SFP disable 
     189              :   // Set tx disable pins low, i.e. enable the pins given in the bitmap
     190              :   //   (different between v1 and v2/3)
     191            0 :   sfp_expander_1->set_outputs(1, get_sfp_tx_disable_bitmap());
     192            0 : }
     193              : //-----------------------------------------------------------------------------
     194              : 
     195              : //-----------------------------------------------------------------------------
     196              : void
     197            0 : GIBIONode::reset_pll() const
     198              : {
     199            0 :   getNode("csr.ctrl.clk_gen_rst").write(0x0);
     200            0 :   getNode("csr.ctrl.clk_gen_rst").write(0x1);
     201            0 : }
     202              : //-----------------------------------------------------------------------------
     203              : 
     204              : //-----------------------------------------------------------------------------
     205              : std::string
     206            0 : GIBIONode::get_sfp_status(uint32_t sfp_id, bool print_out) const { // NOLINT(build/unsigned)
     207            0 :   std::stringstream status;
     208              :   
     209            0 :   validate_sfp_id(sfp_id);
     210              : 
     211            0 :   uint8_t i2c_mux_bitmask = 1UL << (sfp_id+1);
     212              : 
     213            0 :   set_i2c_mux_channels(i2c_mux_bitmask);
     214              : 
     215            0 :   auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_id), "SFP_EEProm");
     216              : 
     217            0 :   status << "SFP " << sfp_id << ":" << std::endl;
     218            0 :   status << sfp->get_status();
     219              : 
     220            0 :   if (print_out)
     221            0 :     TLOG() << status.str();
     222              : 
     223            0 :   return status.str();
     224            0 : }
     225              : //-----------------------------------------------------------------------------
     226              : 
     227              : //-----------------------------------------------------------------------------
     228              : uint32_t
     229            0 : GIBIONode::read_io_expanders() const { // NOLINT(build/unsigned)
     230            0 :   auto sfp_expander_0 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander0");
     231            0 :   auto sfp_expander_1 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander1");
     232              : 
     233            0 :   uint32_t expander_bits = sfp_expander_1->read_inputs(0);
     234            0 :   expander_bits = (expander_bits << 8) + sfp_expander_0->read_inputs(1);
     235            0 :   expander_bits = (expander_bits << 8) + sfp_expander_0->read_inputs(0);
     236              : 
     237            0 :   return expander_bits;
     238            0 : }
     239              : //-----------------------------------------------------------------------------
     240              : 
     241              : //-----------------------------------------------------------------------------
     242              : uint8_t
     243            0 : GIBIONode::read_sfps_los() const { // NOLINT(build/unsigned)
     244            0 :   uint32_t expander_bits = read_io_expanders();
     245              : 
     246            0 :   uint8_t los_bits = 0x00;
     247              : 
     248            0 :   for (uint8_t sfp = 0; sfp<6; sfp++) {
     249              :     // Each SFP has 4 bits, the 3rd bit is the LOS
     250              :     // Adds the SFPs in inverse order
     251            0 :     los_bits = (los_bits << 1) + ((expander_bits >> (2 + 20 - 4*sfp)) & 1);
     252              :   }
     253              : 
     254            0 :   return los_bits;
     255              : }
     256              : //-----------------------------------------------------------------------------
     257              : 
     258              : //-----------------------------------------------------------------------------
     259              : uint8_t
     260            0 : GIBIONode::read_sfps_fault() const { // NOLINT(build/unsigned)
     261            0 :   uint32_t expander_bits = read_io_expanders();
     262              : 
     263            0 :   uint8_t fault_bits = 0x00;
     264              : 
     265            0 :   for (uint8_t sfp = 0; sfp<6; sfp++) {
     266              :     // Each SFP has 4 bits, the 4th bit is the fault
     267              :     // Adds the SFPs in inverse order
     268            0 :     fault_bits = (fault_bits << 1) + ((expander_bits >> (3 + 20 - 4*sfp)) & 1);
     269              :   }
     270              : 
     271            0 :   return fault_bits;
     272              : }
     273              : //-----------------------------------------------------------------------------
     274              : 
     275              : //-----------------------------------------------------------------------------
     276              : bool
     277            0 : GIBIONode::clocks_ok() const
     278              : {
     279            0 :   std::stringstream status;
     280              : 
     281            0 :   auto states = read_sub_nodes(getNode("csr.stat"));
     282            0 :   bool pll_lol = states.find("clk_gen_lol")->second.value();
     283            0 :   bool pll_interrupt = states.find("clk_gen_intr")->second.value();
     284            0 :   bool mmcm_ok = states.find("mmcm_ok")->second.value();
     285            0 :   bool mmcm_10_ok = states.find("mmcm_ok")->second.value();
     286              : 
     287            0 :   TLOG_DEBUG(5) << "pll lol: " << pll_lol << ", pll intr: " << pll_interrupt
     288            0 :                 << ", mmcm ok: " << mmcm_ok << ", mmcm 10MHz ok: " << mmcm_10_ok;
     289              : 
     290            0 :   return !pll_lol && mmcm_ok && mmcm_10_ok;
     291            0 : }
     292              : //-----------------------------------------------------------------------------
     293              : 
     294              : //-----------------------------------------------------------------------------
     295              : void
     296            0 : GIBIONode::switch_sfp_soft_tx_control_bit(uint32_t sfp_id, bool turn_on) const { // NOLINT(build/unsigned)
     297            0 :   validate_sfp_id(sfp_id);
     298              : 
     299            0 :   auto sfp = get_i2c_device<I2CSFPSlave>(m_sfp_i2c_buses.at(sfp_id), "SFP_EEProm");
     300            0 :   sfp->switch_soft_tx_control_bit(turn_on);
     301            0 : }
     302              : //-----------------------------------------------------------------------------
     303              : 
     304              : //-----------------------------------------------------------------------------
     305              : void
     306            0 : GIBIONode::switch_sfp_tx(uint32_t sfp_id, bool turn_on) const { // NOLINT(build/unsigned)
     307            0 :         validate_sfp_id(sfp_id);
     308              : 
     309            0 :   auto sfp_expander_1 = get_i2c_device<I2CExpanderSlave>(m_uid_i2c_bus, "SFPExpander1");
     310            0 :         uint8_t current_sfp_tx_control_flags = sfp_expander_1->read_outputs_config(1); // NOLINT(build/unsigned)
     311              : 
     312            0 :         uint8_t new_sfp_tx_control_flags; // NOLINT(build/unsigned)
     313            0 :         if (turn_on)
     314              :         {
     315            0 :                 new_sfp_tx_control_flags = current_sfp_tx_control_flags & ~(1UL << sfp_id);
     316              :         }
     317              :   else
     318              :   {
     319            0 :     new_sfp_tx_control_flags = current_sfp_tx_control_flags | (1UL << sfp_id);
     320              :   }
     321              : 
     322            0 :   sfp_expander_1->set_outputs(1, new_sfp_tx_control_flags);
     323            0 : }
     324              : //-----------------------------------------------------------------------------
     325              : 
     326              : //-----------------------------------------------------------------------------
     327              : //void
     328              : //GIBIONode::get_info(timinghardwareinfo::TimingGIBMonitorData& mon_data) const
     329              : //{
     330              :   // TODO
     331              : //}
     332              : //-----------------------------------------------------------------------------
     333              : 
     334              : //-----------------------------------------------------------------------------
     335              : // void
     336              : // GIBIONode::get_info(opmonlib::InfoCollector& /*ci*/, int /*level*/) const
     337              : // {
     338              : //   // TO DO
     339              : // }
     340              : //-----------------------------------------------------------------------------
     341              : 
     342              : //-----------------------------------------------------------------------------
     343              : uint8_t
     344            0 : GIBIONode::get_sfp_tx_disable_bitmap() const { // NOLINT(build/unsigned)
     345              :   // First 6 bits are tx disable on GIBv1
     346            0 :   return 0xC0;
     347              : }
     348              : //-----------------------------------------------------------------------------
     349              : 
     350              : //-----------------------------------------------------------------------------
     351              : uint8_t
     352            0 : GIBIONode::get_num_sfps() const { // NOLINT(build/unsigned)
     353              :   // 6 SFPs on GIBv1
     354            0 :   return 6;
     355              : }
     356              : //-----------------------------------------------------------------------------
     357              : 
     358              : //-----------------------------------------------------------------------------
     359              : void
     360            0 : GIBIONode::validate_sfp_id(uint32_t sfp_id) const { // NOLINT(build/unsigned)
     361              :   // number of sfps on board defined by get_num_sfps
     362            0 :   if (sfp_id >= get_num_sfps()) {
     363            0 :         throw InvalidSFPId(ERS_HERE, format_reg_value(sfp_id));
     364              :   }
     365            0 : }
     366              : //-----------------------------------------------------------------------------
     367              : 
     368              : //-----------------------------------------------------------------------------
     369              : void
     370            0 : GIBIONode::set_i2c_mux_channels(uint8_t mux_channel_bitmask) const { // NOLINT(build/unsigned)
     371              : 
     372            0 :   uint8_t mux_channel_config = mux_channel_bitmask & 0x7f;
     373              :   
     374            0 :   auto i2c_bus = getNode<I2CMasterNode>("i2c");
     375            0 :   i2c_bus.write_i2cPrimitive(0x70, {mux_channel_config});
     376            0 : }
     377              : //-----------------------------------------------------------------------------
     378              : 
     379              : //-----------------------------------------------------------------------------
     380              : float
     381            0 : GIBIONode::read_board_temperature() const
     382              : {
     383            0 :         auto temp_mon = get_i2c_device<LM75Node>(m_pll_i2c_bus, "TEMP_MON");
     384            0 :         return temp_mon->read_temperature();
     385            0 : }
     386              : //-----------------------------------------------------------------------------
     387              : } // namespace timing
     388              : } // namespace dunedaq
        

Generated by: LCOV version 2.0-1