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