LCOV - code coverage report
Current view: top level - wibmod/plugins - WIBModule.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 144 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 29 0

            Line data    Source code
       1              : /**
       2              :  * @file WIBModule.cpp WIBModule class implementation
       3              :  *
       4              :  * Based on DataGenerator by Kurt Biery
       5              :  *
       6              :  * This is part of the DUNE DAQ Software Suite, copyright 2020.
       7              :  * Licensing/copyright details are in the COPYING file that you should have
       8              :  * received with this code.
       9              :  */
      10              : 
      11              : #include "WIBModule.hpp"
      12              : 
      13              : #include "appmodel/ColdADCSettings.hpp"
      14              : #include "appmodel/FEMBSettings.hpp"
      15              : #include "appmodel/NetworkConnectionDescriptor.hpp"
      16              : #include "appmodel/NetworkConnectionRule.hpp"
      17              : #include "appmodel/WIBModule.hpp"
      18              : #include "appmodel/WIBModuleConf.hpp"
      19              : #include "appmodel/WIBPulserSettings.hpp"
      20              : #include "appmodel/WIBSettings.hpp"
      21              : 
      22              : #include "wibmod/Issues.hpp"
      23              : 
      24              : #include "logging/Logging.hpp"
      25              : 
      26              : #include <string>
      27              : 
      28              : /**
      29              :  * @brief Name used by TRACE TLOG calls from this source file
      30              :  */
      31              : #define TRACE_NAME "WIBModule" // NOLINT
      32              : 
      33              : namespace dunedaq {
      34              : namespace wibmod {
      35              : 
      36            0 : WIBModule::WIBModule(const std::string& name)
      37            0 :   : dunedaq::appfwk::DAQModule(name)
      38              : {
      39            0 :   register_command("conf", &WIBModule::do_conf);
      40              :   // register_command("settings", &WIBModule::do_settings);
      41            0 :   register_command("start", &WIBModule::do_start);
      42            0 :   register_command("stop", &WIBModule::do_stop);
      43            0 :   register_command("scrap", &WIBModule::do_scrap);
      44            0 : }
      45              : 
      46              : void
      47            0 : WIBModule::init(std::shared_ptr<appfwk::ConfigurationManager> mcfg)
      48              : {
      49            0 :   m_wib_conf = mcfg->get_dal<appmodel::WIBModule>(get_name());
      50            0 :   if (!m_wib_conf) {
      51            0 :     throw appfwk::CommandFailed(ERS_HERE, "init", get_name(), "Unable to retrieve configuration object");
      52              :   }
      53            0 :   m_wib_settings = m_wib_conf->get_conf();
      54            0 : }
      55              : 
      56              : const appmodel::FEMBSettings*
      57            0 : WIBModule::femb_conf_i(size_t i)
      58              : {
      59            0 :   switch (i) {
      60            0 :     case 0:
      61            0 :       return m_wib_settings->get_femb0();
      62            0 :     case 1:
      63            0 :       return m_wib_settings->get_femb1();
      64            0 :     case 2:
      65            0 :       return m_wib_settings->get_femb2();
      66            0 :     case 3:
      67            0 :       return m_wib_settings->get_femb3();
      68            0 :     default:
      69            0 :       throw UnreachableError(ERS_HERE, get_name());
      70              :   }
      71              : }
      72              : 
      73              : bool
      74            0 : WIBModule::femb_enabled_i(size_t i)
      75              : {
      76            0 :   switch (i) {
      77            0 :     case 0:
      78            0 :       return m_wib_conf->get_enabled_femb0();
      79            0 :     case 1:
      80            0 :       return m_wib_conf->get_enabled_femb1();
      81            0 :     case 2:
      82            0 :       return m_wib_conf->get_enabled_femb2();
      83            0 :     case 3:
      84            0 :       return m_wib_conf->get_enabled_femb3();
      85            0 :     default:
      86            0 :       throw UnreachableError(ERS_HERE, get_name());
      87              :   }
      88              : }
      89              : 
      90              : void
      91            0 : WIBModule::populate_femb_conf(wib::ConfigureWIB::ConfigureFEMB* femb_conf, const appmodel::FEMBSettings* conf)
      92              : {
      93            0 :   femb_conf->set_enabled(conf->get_enabled());
      94              : 
      95            0 :   femb_conf->set_test_cap(conf->get_test_cap() != 0);
      96            0 :   femb_conf->set_gain(conf->get_gain());
      97            0 :   femb_conf->set_peak_time(conf->get_peak_time());
      98            0 :   femb_conf->set_baseline(conf->get_baseline());
      99            0 :   femb_conf->set_pulse_dac(conf->get_pulse_dac());
     100            0 :   femb_conf->set_gain_match(conf->get_gain_match());
     101              : 
     102            0 :   femb_conf->set_leak(conf->get_leak());
     103            0 :   femb_conf->set_leak_10x(conf->get_leak_10x() != 0);
     104            0 :   femb_conf->set_ac_couple(conf->get_ac_couple());
     105            0 :   femb_conf->set_buffer(conf->get_buffering());
     106              : 
     107            0 :   femb_conf->set_strobe_skip(conf->get_strobe_skip());
     108            0 :   femb_conf->set_strobe_delay(conf->get_strobe_delay());
     109            0 :   femb_conf->set_strobe_length(conf->get_strobe_length());
     110              : 
     111            0 :   for (int i = 0; i < conf->get_line_driver().size(); i++) {
     112            0 :     if (i >= 2) {
     113            0 :       TLOG() << "Warning: tried to pass more than 2 line driver values to FEMB configuration";
     114            0 :       break;
     115              :     }
     116            0 :     femb_conf->add_line_driver(conf->get_line_driver().at(i));
     117              :   }
     118              : 
     119            0 :   for (int i = 0; i < conf->get_pulse_channels().size(); i++) {
     120            0 :     if (i > 15) {
     121            0 :       TLOG() << "Warning: tried to pass more than 16 pulse_channel values to FEMB configuration";
     122            0 :       break;
     123              :     }
     124            0 :     femb_conf->add_pulse_channels(conf->get_pulse_channels().at(i));
     125              :   }
     126            0 : }
     127              : 
     128              : void
     129            0 : WIBModule::do_conf(const CommandData_t& /*conf_as_json*/)
     130              : {
     131            0 :   TLOG() << "WIBModule " << get_name() << " is " << m_wib_conf->get_wib_addr();
     132              : 
     133            0 :   wib = std::unique_ptr<WIBCommon>(new WIBCommon(m_wib_conf->get_wib_addr()));
     134              : 
     135            0 :   TLOG() << get_name() << " successfully initialized";
     136              : 
     137            0 :   check_timing();
     138              : 
     139            0 :   do_settings();
     140              : 
     141            0 :   check_timing();
     142            0 : }
     143              : 
     144              : void
     145            0 : WIBModule::check_timing()
     146              : {
     147              : 
     148            0 :   TLOG_DEBUG(0) << get_name() << " Checking timing status";
     149            0 :   wib::GetTimingStatus req;
     150            0 :   wib::GetTimingStatus::TimingStatus rep;
     151            0 :   wib->send_command(req, rep);
     152              : 
     153            0 :   int endpoint_status = rep.ept_status() & 0xf;
     154            0 :   if (endpoint_status == 0x8) {
     155            0 :     TLOG_DEBUG(0) << get_name() << " timing status correct as " << endpoint_status;
     156            0 :     return;
     157              :   }
     158              : 
     159            0 :   TLOG_DEBUG(0) << get_name() << " timing status incorrect as " << endpoint_status;
     160              : 
     161            0 :   wib::ResetTiming req2;
     162            0 :   wib::GetTimingStatus::TimingStatus rep2;
     163            0 :   wib->send_command(req2, rep2);
     164              : 
     165            0 :   endpoint_status = rep2.ept_status() & 0xf;
     166            0 :   if (endpoint_status == 0x8) {
     167            0 :     TLOG_DEBUG(0) << get_name() << " timing status correct as " << endpoint_status;
     168            0 :     return;
     169              :   } else {
     170            0 :     TLOG_DEBUG(0) << get_name() << " timing status incorrect as " << endpoint_status;
     171            0 :     throw ConfigurationFailed(ERS_HERE, get_name(), std::to_string(endpoint_status));
     172              :   }
     173            0 : }
     174              : void
     175            0 : WIBModule::do_settings()
     176              : {
     177            0 :   TLOG() << "Building WIB config for " << get_name();
     178              : 
     179            0 :   wib::ConfigureWIB req;
     180            0 :   req.set_cold(m_wib_settings->get_cold());
     181            0 :   req.set_pulser(m_wib_settings->get_pulser());
     182            0 :   req.set_adc_test_pattern(m_wib_settings->get_adc_test_pattern());
     183            0 :   req.set_detector_type(m_wib_settings->get_detector_type());
     184              : 
     185            0 :   wib::ConfigureWIB::ConfigureCOLDADC* coldadc_conf = new wib::ConfigureWIB::ConfigureCOLDADC();
     186            0 :   auto coldadc_settings = m_wib_settings->get_coldadc_settings();
     187            0 :   coldadc_conf->set_reg_0(coldadc_settings->get_reg_0());
     188            0 :   coldadc_conf->set_reg_4(coldadc_settings->get_reg_4());
     189            0 :   coldadc_conf->set_reg_24(coldadc_settings->get_reg_24());
     190            0 :   coldadc_conf->set_reg_25(coldadc_settings->get_reg_25());
     191            0 :   coldadc_conf->set_reg_26(coldadc_settings->get_reg_26());
     192            0 :   coldadc_conf->set_reg_27(coldadc_settings->get_reg_27());
     193            0 :   coldadc_conf->set_reg_29(coldadc_settings->get_reg_29());
     194            0 :   coldadc_conf->set_reg_30(coldadc_settings->get_reg_30());
     195            0 :   req.set_allocated_adc_conf(coldadc_conf);
     196              : 
     197            0 :   wib::ConfigureWIB::ConfigureWIBPulser* wib_pulser_conf = new wib::ConfigureWIB::ConfigureWIBPulser();
     198            0 :   auto wib_pulser = m_wib_settings->get_wib_pulser();
     199            0 :   wib_pulser_conf->add_femb_en(wib_pulser->get_enabled_0());
     200            0 :   wib_pulser_conf->add_femb_en(wib_pulser->get_enabled_1());
     201            0 :   wib_pulser_conf->add_femb_en(wib_pulser->get_enabled_2());
     202            0 :   wib_pulser_conf->add_femb_en(wib_pulser->get_enabled_3());
     203            0 :   wib_pulser_conf->set_pulse_dac(wib_pulser->get_pulse_dac());
     204            0 :   wib_pulser_conf->set_pulse_period(wib_pulser->get_pulse_period());
     205            0 :   wib_pulser_conf->set_pulse_phase(wib_pulser->get_pulse_phase());
     206            0 :   wib_pulser_conf->set_pulse_duration(wib_pulser->get_pulse_duration());
     207            0 :   req.set_allocated_wib_pulser(wib_pulser_conf);
     208              : 
     209            0 :   for (size_t iFEMB = 0; iFEMB < 4; iFEMB++) {
     210            0 :     TLOG() << "Building FEMB " << iFEMB << " config for " << get_name();
     211            0 :     wib::ConfigureWIB::ConfigureFEMB* femb_conf = req.add_fembs();
     212            0 :     populate_femb_conf(femb_conf, femb_conf_i(iFEMB));
     213            0 :     femb_conf->set_enabled(femb_conf->enabled() and this->femb_enabled_i(iFEMB));
     214              :   }
     215              : 
     216            0 :   TLOG() << "Sending WIB configuration to " << get_name();
     217            0 :   wib::Status rep;
     218            0 :   wib->send_command(req, rep);
     219              : 
     220            0 :   if (rep.success()) {
     221            0 :     TLOG() << get_name() << " successfully configured";
     222              :   } else {
     223            0 :     TLOG() << get_name() << " failed to configure";
     224            0 :     throw ConfigurationFailed(ERS_HERE, get_name(), rep.extra());
     225              :   }
     226            0 : }
     227              : 
     228              : void
     229            0 : WIBModule::do_start(const CommandData_t&)
     230              : {
     231            0 :   TLOG_DEBUG(0) << get_name() << " successfully started";
     232            0 : }
     233              : 
     234              : void
     235            0 : WIBModule::do_stop(const CommandData_t&)
     236              : {
     237            0 :   TLOG_DEBUG(0) << get_name() << " successfully stopped";
     238            0 : }
     239              : 
     240              : void
     241            0 : WIBModule::do_scrap(const CommandData_t&)
     242              : {
     243            0 :   wib = NULL;
     244            0 :   TLOG_DEBUG(0) << get_name() << " successfully scrapped";
     245            0 : }
     246              : 
     247              : } // namespace wibmod
     248              : } // namespace dunedaq
     249              : 
     250            0 : DEFINE_DUNE_DAQ_MODULE(dunedaq::wibmod::WIBModule)
        

Generated by: LCOV version 2.0-1