otsdaq-mu2e-stm  5.02.01
fw_config.hh
1 #ifndef FW_CONFIG_HH_
2 #define FW_CONFIG_HH_
3 
4 // Include config file
5 #include "Mu2e-STMDAQ/config/config.hh"
6 
7 // Parameters to load firmware
8 struct load_fw_{
9  const std::string script; // Bash script to call to load firmware
10  const std::string petalinux_user; // Petalinux OS user
11  const std::string petalinux_ip; // Petalinux OS interface IP
12  const std::string bitfile; // Bitfile to load
13 
14  // Constructor
15  load_fw_(std::string script_,
16  std::string petalinux_user_,
17  std::string petalinux_ip_,
18  std::string bitfile_)
19  : script(script_),
20  petalinux_user(petalinux_user_),
21  petalinux_ip(petalinux_ip_),
22  bitfile(bitfile_) {}
23 };
24 
25 
26 // Python scripts to call by hw_manager
28  const std::pair<std::string,std::string> pybind; // Pybind adaptor & execute function
29  const std::pair<std::string,std::string> check_fpga; // Check FPGA script & return variable
30  const std::pair<std::string,std::string> check_adc; // Check ADC script & return variable
31  const std::pair<std::string,std::string> init_adc; // Initialise ADC script & return variable
32  const std::pair<std::string,std::string> adc_temp; // Check adc temperature script & return variable
33  const std::pair<std::string,std::string> check_ps; // Check PS memory script & return variable
34  const std::pair<std::string,std::string> reset_readout; // Reset readout script
35  const std::pair<std::string,std::string> dtc_sim; // DTC simulation script
36  const std::pair<std::string,std::string> dtc_set_real; // DTC set real script
37  // Constructor
38  python_scripts(std::string pybind_,
39  std::string pybind_func_,
40  std::string check_fpga_,
41  std::string check_fpga_var_,
42  std::string check_adc_,
43  std::string check_adc_var_,
44  std::string init_adc_,
45  std::string init_adc_var_,
46  std::string adc_temp_,
47  std::string adc_temp_var_,
48  std::string check_ps_,
49  std::string check_ps_var_,
50  std::string reset_readout_,
51  std::string dtc_sim_,
52  std::string dtc_set_real_)
53  : pybind(pybind_,pybind_func_)
54  , check_fpga(check_fpga_,check_fpga_var_)
55  , check_adc(check_adc_,check_adc_var_)
56  , init_adc(init_adc_,init_adc_var_)
57  , adc_temp(adc_temp_,adc_temp_var_)
58  , check_ps(check_ps_,check_ps_var_)
59  , reset_readout(reset_readout_,"")
60  , dtc_sim(dtc_sim_,"")
61  , dtc_set_real(dtc_set_real_,"") {}
62  // Get all python scripts as tuple
63  auto as_tuple() const {
64  return std::tie(
65  pybind,
66  check_fpga,
67  check_adc,
68  init_adc,
69  adc_temp,
70  check_ps,
71  reset_readout,
72  dtc_sim,
73  dtc_set_real
74  );
75  }
76 };
77 
78 
79 // Firmware configurable variables
80 struct fw_info{
81 
82  // The control server
83  const std::string ctrl_srvr;
84  // Hardware dirrectory
85  const std::string hw_dir;
86  // Hardware device
87  const std::string device;
88  // Python scripts
89  struct python_scripts python;
90  // Parameters to remotely load firmware
91  struct load_fw_ load_fw;
92  // The ADC sampling frequency
93  const double fADC;
94  // The ADC sampling period
95  const double tADC;
96  // Use DTC simulation?
97  const int use_dtc_sim;
98 
99  // Constructor
100  fw_info(Config& cfg, const std::shared_ptr<AsyncLogger> logger) :
101  ctrl_srvr(cfg.getValue<std::string>("stm.fw.ctrl_srvr")), // Control server
102  hw_dir(cfg.getValue<std::string>("stm.fw.dir")), // Hardware directory
103  device(cfg.getValue<std::string>("stm.fw.device")), // Hardware device
104  python(cfg.getValue<std::string>("stm.fw.python.pybind"),
105  cfg.getValue<std::string>("stm.fw.python.pybind.exec_func"),
106  cfg.getValue<std::string>("stm.fw.python.check_fpga"),
107  cfg.getValue<std::string>("stm.fw.python.check_fpga.retvar"),
108  cfg.getValue<std::string>("stm.fw.python.check_adc"),
109  cfg.getValue<std::string>("stm.fw.python.check_adc.retvar"),
110  cfg.getValue<std::string>("stm.fw.python.init_adc"),
111  cfg.getValue<std::string>("stm.fw.python.init_adc.retvar"),
112  cfg.getValue<std::string>("stm.fw.python.adc_temp"),
113  cfg.getValue<std::string>("stm.fw.python.adc_temp.retvar"),
114  cfg.getValue<std::string>("stm.fw.python.check_ps"),
115  cfg.getValue<std::string>("stm.fw.python.check_ps.retvar"),
116  cfg.getValue<std::string>("stm.fw.python.reset_readout"),
117  cfg.getValue<std::string>("stm.fw.python.dtc_sim"),
118  cfg.getValue<std::string>("stm.fw.python.dtc_set_real")
119  ),
120  load_fw(cfg.getValue<std::string>("stm.fw.load_fw.script"),
121  cfg.getValue<std::string>("stm.fw.load_fw.petalinux_user"),
122  cfg.getValue<std::string>("stm.fw.load_fw.petalinux_ip"),
123  cfg.getValue<std::string>("stm.fw.load_fw.bitfile")
124  ),
125  fADC(cfg.getValue<double>("stm.fw.fADC")), // fADC in MHz
126  tADC(1.0/fADC), // tADC in µs per value
127  use_dtc_sim(cfg.getValue<int>("stm.fw.use_dtc_sim")) // Use DTC simulation
128  {
129 
130  // Notify user
131  if(logger){
132  logger->log("Config:fw_info: Control server = " +
133  ctrl_srvr + ".",1);
134  logger->log("Config:fw_info: Hardware directory = " +
135  hw_dir + ".",1);
136  logger->log("Config:fw_info: Hardware device = " +
137  device + ".",1);
138  logger->log("Config:fw_info: ADC sampling frequency = " +
139  std::to_string(fADC) +
140  " MHz (" + std::to_string(tADC*1e3) +
141  " ns per ADC value).",1);
142  std::apply([&](const auto&... elems) {
143  ((logger->log(
144  std::string("Config:fw_info: Using python script: ") +
145  hw_dir + "/" + elems.first + ".py: " + elems.second,1)
146  ), ...);
147  }, python.as_tuple());
148  logger->log("Config:fw_info: Script to remotely load firmware = " +
149  load_fw.script + ".",1);
150  logger->log("Config:fw_info: Petalinux OS user = " +
151  load_fw.petalinux_user + ", interface IP = " +
152  load_fw.petalinux_ip + ".",1);
153  logger->log("Config:fw_info: Firmware bitfile to load = " +
154  load_fw.bitfile + ".",1);
155  std::string ON = "ON";
156  std::string OFF = "OFF";
157  logger->log("Config:fw_info: Data source: DTC Simulation = " + (use_dtc_sim ? ON : OFF) + ".",1);
158 
159  }
160  }
161 
162 };
163 
164 #endif
Definition: config.hh:19