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: 2025-12-21 13:07:08 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/NetworkConnectionDescriptor.hpp"
      14              : #include "appmodel/NetworkConnectionRule.hpp"
      15              : #include "appmodel/WIBModule.hpp"
      16              : #include "appmodel/WIBModuleConf.hpp"
      17              : #include "appmodel/WIBSettings.hpp"
      18              : #include "appmodel/WIBPulserSettings.hpp"
      19              : #include "appmodel/ColdADCSettings.hpp"
      20              : #include "appmodel/FEMBSettings.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              :   {
     156            0 :     TLOG_DEBUG(0) << get_name() << " timing status correct as " << endpoint_status;
     157            0 :     return;
     158              :   } 
     159              :   
     160            0 :   TLOG_DEBUG(0) << get_name() << " timing status incorrect as " << endpoint_status; 
     161              : 
     162            0 :   wib::ResetTiming req2;
     163            0 :   wib::GetTimingStatus::TimingStatus rep2;
     164            0 :   wib->send_command(req2,rep2);
     165              : 
     166            0 :   endpoint_status = rep2.ept_status() & 0xf;
     167            0 :   if (endpoint_status == 0x8)
     168              :   {
     169            0 :     TLOG_DEBUG(0) << get_name() << " timing status correct as " << endpoint_status;
     170            0 :     return;
     171              :   } 
     172              :   else
     173              :   {
     174            0 :     TLOG_DEBUG(0) << get_name() << " timing status incorrect as " << endpoint_status; 
     175            0 :     throw ConfigurationFailed(ERS_HERE, get_name(), std::to_string(endpoint_status));
     176              :   }
     177              : 
     178            0 : }
     179              : void
     180            0 : WIBModule::do_settings()
     181              : {
     182            0 :   TLOG() << "Building WIB config for " << get_name();
     183              :  
     184            0 :   wib::ConfigureWIB req;
     185            0 :   req.set_cold(m_wib_settings->get_cold());
     186            0 :   req.set_pulser(m_wib_settings->get_pulser());
     187            0 :   req.set_adc_test_pattern(m_wib_settings->get_adc_test_pattern());
     188            0 :   req.set_detector_type(m_wib_settings->get_detector_type());
     189              : 
     190            0 :   wib::ConfigureWIB::ConfigureCOLDADC* coldadc_conf = new wib::ConfigureWIB::ConfigureCOLDADC();
     191            0 :   auto coldadc_settings = m_wib_settings->get_coldadc_settings();
     192            0 :   coldadc_conf->set_reg_0(coldadc_settings->get_reg_0());
     193            0 :   coldadc_conf->set_reg_4(coldadc_settings->get_reg_4());
     194            0 :   coldadc_conf->set_reg_24(coldadc_settings->get_reg_24());
     195            0 :   coldadc_conf->set_reg_25(coldadc_settings->get_reg_25());
     196            0 :   coldadc_conf->set_reg_26(coldadc_settings->get_reg_26());
     197            0 :   coldadc_conf->set_reg_27(coldadc_settings->get_reg_27());
     198            0 :   coldadc_conf->set_reg_29(coldadc_settings->get_reg_29());
     199            0 :   coldadc_conf->set_reg_30(coldadc_settings->get_reg_30());
     200            0 :   req.set_allocated_adc_conf(coldadc_conf);
     201              :   
     202            0 :   wib::ConfigureWIB::ConfigureWIBPulser* wib_pulser_conf = new wib::ConfigureWIB::ConfigureWIBPulser();
     203            0 :   auto wib_pulser = m_wib_settings->get_wib_pulser();
     204            0 :   wib_pulser_conf->add_femb_en(wib_pulser->get_enabled_0());
     205            0 :   wib_pulser_conf->add_femb_en(wib_pulser->get_enabled_1());
     206            0 :   wib_pulser_conf->add_femb_en(wib_pulser->get_enabled_2());
     207            0 :   wib_pulser_conf->add_femb_en(wib_pulser->get_enabled_3());
     208            0 :   wib_pulser_conf->set_pulse_dac(wib_pulser->get_pulse_dac());
     209            0 :   wib_pulser_conf->set_pulse_period(wib_pulser->get_pulse_period());
     210            0 :   wib_pulser_conf->set_pulse_phase(wib_pulser->get_pulse_phase());
     211            0 :   wib_pulser_conf->set_pulse_duration(wib_pulser->get_pulse_duration());
     212            0 :   req.set_allocated_wib_pulser(wib_pulser_conf);
     213              : 
     214            0 :   for(size_t iFEMB = 0; iFEMB < 4; iFEMB++)
     215              :   {
     216            0 :     TLOG() << "Building FEMB " << iFEMB << " config for " << get_name();
     217            0 :     wib::ConfigureWIB::ConfigureFEMB *femb_conf = req.add_fembs();
     218            0 :     populate_femb_conf(femb_conf, femb_conf_i(iFEMB));
     219            0 :     femb_conf->set_enabled(femb_conf->enabled() and this->femb_enabled_i(iFEMB));
     220              :   }
     221              : 
     222              : 
     223            0 :   TLOG() << "Sending WIB configuration to " << get_name();
     224            0 :   wib::Status rep;
     225            0 :   wib->send_command(req,rep);
     226              :   
     227            0 :   if (rep.success())
     228              :   {
     229            0 :     TLOG() << get_name() << " successfully configured";
     230              :   }
     231              :   else
     232              :   {
     233            0 :     TLOG() << get_name() << " failed to configure";
     234            0 :     throw ConfigurationFailed(ERS_HERE, get_name(), rep.extra());
     235              :   }
     236            0 : }
     237              : 
     238              : void
     239            0 : WIBModule::do_start(const CommandData_t&)
     240              : {
     241            0 :   TLOG_DEBUG(0) << get_name() << " successfully started";
     242            0 : }
     243              : 
     244              : void
     245            0 : WIBModule::do_stop(const CommandData_t&)
     246              : {
     247            0 :   TLOG_DEBUG(0) << get_name() << " successfully stopped";
     248            0 : }
     249              : 
     250              : void
     251            0 : WIBModule::do_scrap(const CommandData_t&)
     252              : {
     253            0 :   wib = NULL;
     254            0 :   TLOG_DEBUG(0) << get_name() << " successfully scrapped";
     255            0 : }
     256              : 
     257              : 
     258              : } // namespace wibmod
     259              : } // namespace dunedaq
     260              : 
     261            0 : DEFINE_DUNE_DAQ_MODULE(dunedaq::wibmod::WIBModule)
        

Generated by: LCOV version 2.0-1