Line data Source code
1 : /**
2 : * @file DaphneV2ControllerModule.hpp
3 : *
4 : * Developer(s) of this DAQModule have yet to replace this line with a brief description of the DAQModule.
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 : #ifndef DAPHNEMODULES_PLUGINS_DAPHNEV2CONTROLLERMODULE_HPP_
12 : #define DAPHNEMODULES_PLUGINS_DAPHNEV2CONTROLLERMODULE_HPP_
13 :
14 :
15 : #include "DaphneV2ControllerModule.hpp"
16 : #include "appfwk/DAQModule.hpp"
17 :
18 : #include "DaphneV2Interface.hpp"
19 : #include "daphnemodules/CommonIssues.hpp"
20 :
21 : #include "daphnemodules/opmon/DaphneControllerModule.pb.h"
22 :
23 : #include <appmodel/DaphneV2BoardConf.hpp>
24 : #include <appmodel/DaphneV2ControllerModule.hpp>
25 :
26 : #include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
27 :
28 : #include <atomic>
29 : #include <limits>
30 : #include <string>
31 : #include <array>
32 : #include <mutex>
33 : #include <memory>
34 :
35 :
36 : namespace dunedaq {
37 :
38 0 : ERS_DECLARE_ISSUE( daphnemodules,
39 : WrongMonitoringString,
40 : "Board " << id
41 : << ": response from board was not parsed correctly for "
42 : << counter << " times. Last Rseponse: " << response,
43 : ((std::string)id)((uint16_t)counter)((std::string)response)
44 : )
45 :
46 0 : ERS_DECLARE_ISSUE( daphnemodules,
47 : FailedStringConversion,
48 : "String " << str << " failed to be converted into a number",
49 : ((std::string)str)
50 : )
51 :
52 0 : ERS_DECLARE_ISSUE( daphnemodules,
53 : InvalidSlot,
54 : "Invalid slot " << slot << " obtained from IP " << ip,
55 : ((uint16_t)slot) ((std::string)ip)
56 : )
57 :
58 0 : ERS_DECLARE_ISSUE( daphnemodules,
59 : PLLNotLocked,
60 : "Board in slot " << slot << ": " << mm << " not locked",
61 : ((uint16_t)slot)((std::string)mm)
62 : )
63 :
64 0 : ERS_DECLARE_ISSUE( daphnemodules,
65 : TimingEndpointNotReady,
66 : "Board in slot " << slot << ": timing endpoint not ready, full status: " << status,
67 : ((uint16_t)slot)((std::string)status)
68 : )
69 :
70 0 : ERS_DECLARE_ISSUE( daphnemodules,
71 : InvalidBiasControl,
72 : bias << " bigger than 4095",
73 : ((uint64_t)bias)
74 : )
75 :
76 0 : ERS_DECLARE_ISSUE( daphnemodules,
77 : InvalidChannelId,
78 : "Channel " << id <<'/' << max << " not available",
79 : ((uint32_t)id)((uint32_t)max)
80 : )
81 :
82 0 : ERS_DECLARE_ISSUE( daphnemodules,
83 : InvalidAFEVoltage,
84 : "AFE " << id << " has invalid voltage, gain: " << gain << ", bias: " << bias,
85 : ((uint32_t)id)((uint32_t)gain)((uint32_t)bias)
86 : )
87 :
88 0 : ERS_DECLARE_ISSUE( daphnemodules,
89 : InvalidPGAConf,
90 : "AFE " << id << " has invalid PGA conf (reg51), cut selection: " << cut,
91 : ((uint32_t)id)((uint32_t)cut)
92 : )
93 :
94 0 : ERS_DECLARE_ISSUE( daphnemodules,
95 : InvalidLNAConf,
96 : "AFE " << id << " has invalid LNA conf (reg52), clamp: " << clamp
97 : << ", gain: " << gain,
98 : ((uint32_t)id)((uint32_t)clamp)((uint32_t)gain)
99 : )
100 :
101 0 : ERS_DECLARE_ISSUE( daphnemodules,
102 : InvalidThreshold,
103 : "Invalid threshold: " << threshold,
104 : ((uint32_t)threshold)
105 : )
106 :
107 0 : ERS_DECLARE_ISSUE( daphnemodules,
108 : InvalidBiasCtrlConfiguration,
109 : "Invalid BiasCtrl Configuration " << v_biasctrl,
110 : ((std::string)v_biasctrl)
111 : )
112 :
113 0 : ERS_DECLARE_ISSUE( daphnemodules,
114 : DDRNotAligned,
115 : "board in slot " << slot << ": AFE " << afe << " DDR not aligned, check value: " << check,
116 : ((uint16_t)slot)((uint16_t)afe)((uint64_t)check)
117 : )
118 :
119 : } // namespace dunedaq
120 :
121 : namespace dunedaq::daphnemodules {
122 :
123 : class DaphneV2ControllerModule : public dunedaq::appfwk::DAQModule
124 : {
125 : public:
126 : explicit DaphneV2ControllerModule(const std::string& name);
127 :
128 : void init(std::shared_ptr<appfwk::ConfigurationManager> cfgMgr) override;
129 :
130 : void generate_opmon_data() override;
131 :
132 : DaphneV2ControllerModule(const DaphneV2ControllerModule&) = delete;
133 : DaphneV2ControllerModule& operator=(const DaphneV2ControllerModule&) = delete;
134 : DaphneV2ControllerModule(DaphneV2ControllerModule&&) = delete;
135 : DaphneV2ControllerModule& operator=(DaphneV2ControllerModule&&) = delete;
136 :
137 0 : ~DaphneV2ControllerModule() = default;
138 :
139 : private:
140 :
141 : using ChannelId = uint8_t; // NOLINT
142 :
143 : // Commands DaphneV2ControllerModule can receive
144 : void do_conf(const CommandData_t&);
145 : void do_start(const CommandData_t&);
146 : void do_scrap(const CommandData_t&);
147 : // void dump_buffers(const CommandData_t&);
148 :
149 : // specific actions
150 : void create_interface( const std::string & ip,
151 : std::chrono::milliseconds timeout ) ;
152 : void validate_configuration(const appmodel::DaphneV2BoardConf &) const;
153 : void configure_timing_endpoints();
154 : void configure_analog_chain(bool intial_config);
155 : void align_DDR();
156 : void configure_trigger_mode();
157 : void disable_links();
158 : void reset_counters();
159 :
160 : std::unique_ptr<DaphneV2Interface> m_interface;
161 : std::mutex m_mutex; // mutex for interface
162 : std::atomic<bool> m_scrap_called = false;
163 :
164 : static const ChannelId s_max_channels = 40;
165 : static const ChannelId s_max_afes = 5;
166 : using conf_t = appmodel::DaphneV2ControllerModule;
167 : const conf_t* m_module_config = nullptr;
168 :
169 : static const uint16_t s_frame_alignment_good = 0x3f80;
170 :
171 : uint16_t m_error_counter = 0; // NOLINT
172 : // counter use to see how many times we failed the parsing of the monitoing
173 :
174 : //monitoring
175 : using const_metric_counter_t = std::invoke_result<decltype(&dunedaq::daphnemodules::opmon::ChannelInfo::total_triggers),
176 : dunedaq::daphnemodules::opmon::ChannelInfo>::type;
177 : using counter_t = std::remove_const<const_metric_counter_t>::type;
178 : struct Counters {
179 : std::atomic<counter_t> triggers = 0;
180 : std::atomic<counter_t> packets = 0;
181 : };
182 : std::array<Counters, s_max_channels> m_channel_counters;
183 : std::atomic<counter_t> m_last_package_counter = 0;
184 : std::atomic<counter_t> m_last_unsent_counter = 0;
185 :
186 : };
187 :
188 : } // namespace dunedaq::daphnemodules
189 :
190 : #endif // DAPHNEMODULES_PLUGINS_DAPHNEV2CONTROLLERMODULE_HPP_
|