DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
flxlibs
src
CardControllerWrapper.cpp
Go to the documentation of this file.
1
8
// From Module
9
#include "
CardControllerWrapper.hpp
"
10
#include "
FelixDefinitions.hpp
"
11
#include "
FelixIssues.hpp
"
12
#include "
flxlibs/opmon/CardControllerWrapper.pb.h
"
13
14
#include "
appmodel/FelixDataSender.hpp
"
15
#include "
appmodel/FelixInterface.hpp
"
16
#include "
logging/Logging.hpp
"
17
18
#include "flxcard/FlxException.h"
19
20
#include "fmt/core.h"
21
22
// From STD
23
#include <iomanip>
24
#include <memory>
25
#include <string>
26
30
enum
31
{
32
TLVL_ENTER_EXIT_METHODS
= 5,
33
TLVL_WORK_STEPS
= 10,
34
TLVL_BOOKKEEPING
= 15
35
};
36
37
namespace
dunedaq
{
38
namespace
flxlibs
{
39
40
CardControllerWrapper::CardControllerWrapper
(uint32_t device_id,
41
const
appmodel::FelixInterface
* flx_cfg,
42
const
std::vector<const appmodel::FelixDataSender*>& flx_senders)
43
:
m_device_id
(device_id)
44
,
m_flx_cfg
(flx_cfg)
45
,
m_flx_senders
(flx_senders)
46
{
47
48
TLOG_DEBUG
(
TLVL_ENTER_EXIT_METHODS
) <<
"CardControllerWrapper constructor called. Open card "
<<
m_device_id
;
49
50
m_flx_card
= std::make_unique<FlxCard>();
51
if
(
m_flx_card
==
nullptr
) {
52
ers::fatal
(flxlibs::CardError(
ERS_HERE
,
"Couldn't create FlxCard object."
));
53
}
54
open_card
();
55
TLOG_DEBUG
(
TLVL_ENTER_EXIT_METHODS
) <<
"CardControllerWrapper constructed."
;
56
}
57
58
CardControllerWrapper::~CardControllerWrapper
()
59
{
60
TLOG_DEBUG
(
TLVL_ENTER_EXIT_METHODS
)
61
<<
"CardControllerWrapper destructor called. First stop check, then closing card."
;
62
close_card
();
63
TLOG_DEBUG
(
TLVL_ENTER_EXIT_METHODS
) <<
"CardControllerWrapper destroyed."
;
64
}
65
66
void
67
CardControllerWrapper::init
()
68
{
69
70
// Card initialization
71
// this is complicated....should we repeat all code in flx_init?
72
// For now do not do the configs of the clock chips
73
const
std::lock_guard<std::mutex> lock(
m_card_mutex
);
74
m_flx_card
->cfg_set_option(BF_MMCM_MAIN_LCLK_SEL, 1);
// local clock
75
m_flx_card
->soft_reset();
76
// si5328_configure();
77
// si5345_configure(0);
78
m_flx_card
->cfg_set_option(BF_GBT_SOFT_RESET, 0xFFFFFFFFFFFF);
79
m_flx_card
->cfg_set_option(BF_GBT_SOFT_RESET, 0);
80
81
int
bad_channels =
m_flx_card
->gbt_setup(FLX_GBT_ALIGNMENT_ONE, FLX_GBT_TMODE_FEC);
// What does this do?
82
if
(bad_channels) {
83
TLOG
() << bad_channels <<
" not aligned."
;
84
}
85
m_flx_card
->irq_disable(ALL_IRQS);
86
}
87
88
void
89
CardControllerWrapper::configure
(uint16_t super_chunk_size,
bool
emu_fanout)
90
{
91
// Disable all links
92
for
(
size_t
i = 0; i < 12; ++i) {
93
// std::stringstream ss;
94
// ss << "DECODING_LINK" << std::setw(2) << std::setfill('0') << i << "_EGROUP0_CTRL_EPATH_ENA";
95
set_bitfield
(fmt::format(
"DECODING_LINK{:02}_EGROUP0_CTRL_EPATH_ENA"
, i), 0);
96
}
97
98
// Enable/disable emulation
99
if
(emu_fanout) {
100
// set_bitfield("FE_EMU_LOGIC_IDLES", 0); // FIXME
101
// set_bitfield("FE_EMU_LOGIC_CHUNK_LENGTH", 0);
102
// set_bitfield("FE_EMU_LOGIC_ENA", 0);
103
// set_bitfield("FE_EMU_LOGIC_L1A_TRIGGERED", 0);
104
105
set_bitfield
(
"GBT_TOFRONTEND_FANOUT_SEL"
, 0);
106
set_bitfield
(
"GBT_TOHOST_FANOUT_SEL"
, 0xffffff);
107
set_bitfield
(
"FE_EMU_ENA_EMU_TOFRONTEND"
, 0);
108
set_bitfield
(
"FE_EMU_ENA_EMU_TOHOST"
, 1);
109
}
else
{
110
// set_register("FE_EMU_LOGIC_ENA", 0);
111
// set_register("FE_EMU_LOGIC_L1A_TRIGGERED", 0);
112
// set_register("FE_EMU_LOGIC_IDLES", 0);
113
// set_register("FE_EMU_LOGIC_CHUNK_LENGTH", 0);
114
115
set_bitfield
(
"FE_EMU_ENA_EMU_TOFRONTEND"
, 0);
116
set_bitfield
(
"FE_EMU_ENA_EMU_TOHOST"
, 0);
117
set_bitfield
(
"GBT_TOFRONTEND_FANOUT_SEL"
, 0);
118
set_bitfield
(
"GBT_TOHOST_FANOUT_SEL"
, 0);
119
}
120
// Enable and configure the right links
121
122
for
(
auto
s :
m_flx_senders
) {
123
set_bitfield
(fmt::format(
"SUPER_CHUNK_FACTOR_LINK_{:02}"
, s->get_link()), super_chunk_size);
124
set_bitfield
(fmt::format(
"DECODING_LINK{:02}_EGROUP0_CTRL_EPATH_ENA"
, s->get_link()), 1);
125
}
126
}
127
128
void
129
CardControllerWrapper::open_card
()
130
{
131
TLOG_DEBUG
(
TLVL_WORK_STEPS
) <<
"Opening FELIX card "
<<
m_device_id
;
132
try
{
133
const
std::lock_guard<std::mutex> lock(
m_card_mutex
);
134
m_flx_card
->card_open(
static_cast<
int
>
(
m_device_id
), LOCK_NONE);
// FlxCard.h
135
}
catch
(FlxException& ex) {
136
ers::error
(flxlibs::CardError(
ERS_HERE
, ex.what()));
137
exit(EXIT_FAILURE);
138
}
139
}
140
141
void
142
CardControllerWrapper::close_card
()
143
{
144
TLOG_DEBUG
(
TLVL_WORK_STEPS
) <<
"Closing FELIX card "
<<
m_device_id
;
145
try
{
146
const
std::lock_guard<std::mutex> lock(
m_card_mutex
);
147
m_flx_card
->card_close();
148
}
catch
(FlxException& ex) {
149
ers::error
(flxlibs::CardError(
ERS_HERE
, ex.what()));
150
exit(EXIT_FAILURE);
151
}
152
}
153
154
uint64_t
// NOLINT(build/unsigned)
155
CardControllerWrapper::get_register
(std::string key)
156
{
157
TLOG_DEBUG
(
TLVL_WORK_STEPS
) <<
"Reading value of register "
<< key;
158
const
std::lock_guard<std::mutex> lock(
m_card_mutex
);
159
auto
reg_val =
m_flx_card
->cfg_get_reg(key.c_str());
160
return
reg_val;
161
}
162
163
void
164
CardControllerWrapper::set_register
(std::string key, uint64_t value)
// NOLINT(build/unsigned)
165
{
166
TLOG_DEBUG
(
TLVL_WORK_STEPS
) <<
"Setting value of register "
<< key <<
" to "
<< value;
167
const
std::lock_guard<std::mutex> lock(
m_card_mutex
);
168
m_flx_card
->cfg_set_reg(key.c_str(), value);
169
}
170
171
uint64_t
// NOLINT(build/unsigned)
172
CardControllerWrapper::get_bitfield
(std::string key)
173
{
174
TLOG_DEBUG
(
TLVL_WORK_STEPS
) <<
"Reading value of bitfield "
<< key;
175
const
std::lock_guard<std::mutex> lock(
m_card_mutex
);
176
auto
bf_val =
m_flx_card
->cfg_get_option(key.c_str(),
false
);
177
return
bf_val;
178
}
179
180
void
181
CardControllerWrapper::set_bitfield
(std::string key, uint64_t value)
// NOLINT(build/unsigned)
182
{
183
TLOG_DEBUG
(
TLVL_WORK_STEPS
) <<
"Setting value of bitfield "
<< key <<
" to "
<< value;
184
;
185
const
std::lock_guard<std::mutex> lock(
m_card_mutex
);
186
m_flx_card
->cfg_set_option(key.c_str(), value,
false
);
187
}
188
189
void
190
CardControllerWrapper::gth_reset
()
191
{
192
TLOG_DEBUG
(
TLVL_WORK_STEPS
) <<
"Resetting GTH"
;
193
const
std::lock_guard<std::mutex> lock(
m_card_mutex
);
194
for
(
auto
i = 0; i < 6; ++i) {
195
m_flx_card
->gth_rx_reset(i);
196
}
197
}
198
199
void
200
CardControllerWrapper::check_alignment
(uint64_t aligned)
201
{
202
TLOG_DEBUG
(
TLVL_WORK_STEPS
) <<
"Checking link alignment for "
<<
m_flx_cfg
->
get_slr
();
203
204
bool
emu_fanout =
get_bitfield
(
"FE_EMU_ENA_EMU_TOHOST"
);
205
// check the alingment on a logical unit
206
for
(
auto
s :
m_flx_senders
) {
207
// here we want to print out a log message when the links do not appear to be aligned.
208
// for WIB readout link_id 5 is always reserved for tp links, so alignemnt is not expected fort these
209
#warning FIXME: Horrible remapping workaround. Temporary fix only!
210
auto
id_to_check =
m_flx_cfg
->
get_slr
() * 6 + s->get_link();
211
bool
is_aligned = aligned & (1 << id_to_check);
212
// auto found_link = std::find(std::begin(alignment_mask), std::end(alignment_mask), li.link_id);
213
// if(found_link == std::end(alignment_mask)) {
214
// if(!lu_cfg.emu_fanout && !is_aligned) {
215
// ers::error(flxlibs::ChannelAlignment(ERS_HERE, li.link_id));
216
// }
217
// }
218
if
(!emu_fanout && !is_aligned) {
219
ers::error
(flxlibs::ChannelAlignment(
ERS_HERE
, s->get_link()));
220
}
221
}
222
}
223
224
void
225
CardControllerWrapper::generate_opmon_data
()
226
{
227
TLOG_DEBUG
(
TLVL_WORK_STEPS
) <<
"Monitoring link alignment for "
<<
m_flx_cfg
->
get_slr
();
228
229
uint64_t aligned =
get_register
(REG_GBT_ALIGNMENT_DONE);
230
231
for
(
auto
s :
m_flx_senders
) {
232
233
opmon::LinkInfo
i;
234
i.
set_enabled
(
true
);
235
#warning FIXME: Horrible remapping workaround. Temporary fix only!
236
auto
id_to_check =
m_flx_cfg
->
get_slr
() * 6 + s->get_link();
237
bool
is_aligned = aligned & (1 << id_to_check);
238
i.
set_aligned
(is_aligned);
239
publish
(std::move(i),
240
{ {
"device"
, fmt::format(
"{}"
,
m_device_id
) }, {
"link"
, fmt::format(
"{}"
, s->get_link()) } });
241
242
}
// loop over links
243
}
244
245
}
// namespace flxlibs
246
}
// namespace dunedaq
TLVL_BOOKKEEPING
@ TLVL_BOOKKEEPING
Definition
CardControllerWrapper.cpp:34
TLVL_WORK_STEPS
@ TLVL_WORK_STEPS
Definition
CardControllerWrapper.cpp:33
CardControllerWrapper.hpp
CardControllerWrapper.pb.h
FelixDefinitions.hpp
FelixIssues.hpp
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:127
dunedaq::appmodel::FelixInterface
Definition
FelixInterface.hpp:27
dunedaq::appmodel::FelixInterface::get_slr
uint16_t get_slr() const
Get "slr" attribute value. Super logic region of a FLX card.
Definition
FelixInterface.hpp:161
dunedaq::flxlibs::CardControllerWrapper::gth_reset
void gth_reset()
Definition
CardControllerWrapper.cpp:190
dunedaq::flxlibs::CardControllerWrapper::m_device_id
uint32_t m_device_id
Definition
CardControllerWrapper.hpp:62
dunedaq::flxlibs::CardControllerWrapper::check_alignment
void check_alignment(uint64_t aligned)
Definition
CardControllerWrapper.cpp:200
dunedaq::flxlibs::CardControllerWrapper::get_register
uint64_t get_register(std::string key)
Definition
CardControllerWrapper.cpp:155
dunedaq::flxlibs::CardControllerWrapper::configure
void configure(uint16_t super_chunk_size, bool emu_fanout)
Definition
CardControllerWrapper.cpp:89
dunedaq::flxlibs::CardControllerWrapper::close_card
void close_card()
Definition
CardControllerWrapper.cpp:142
dunedaq::flxlibs::CardControllerWrapper::init
void init()
Definition
CardControllerWrapper.cpp:67
dunedaq::flxlibs::CardControllerWrapper::m_flx_card
UniqueFlxCard m_flx_card
Definition
CardControllerWrapper.hpp:69
dunedaq::flxlibs::CardControllerWrapper::open_card
void open_card()
Definition
CardControllerWrapper.cpp:129
dunedaq::flxlibs::CardControllerWrapper::~CardControllerWrapper
~CardControllerWrapper()
Definition
CardControllerWrapper.cpp:58
dunedaq::flxlibs::CardControllerWrapper::m_flx_senders
const std::vector< const appmodel::FelixDataSender * > m_flx_senders
Definition
CardControllerWrapper.hpp:67
dunedaq::flxlibs::CardControllerWrapper::CardControllerWrapper
CardControllerWrapper(uint32_t device_id, const appmodel::FelixInterface *flx_cfg, const std::vector< const appmodel::FelixDataSender * > &flx_senders)
CardControllerWrapper Constructor.
Definition
CardControllerWrapper.cpp:40
dunedaq::flxlibs::CardControllerWrapper::m_flx_cfg
const appmodel::FelixInterface * m_flx_cfg
Definition
CardControllerWrapper.hpp:66
dunedaq::flxlibs::CardControllerWrapper::set_register
void set_register(std::string key, uint64_t value)
Definition
CardControllerWrapper.cpp:164
dunedaq::flxlibs::CardControllerWrapper::set_bitfield
void set_bitfield(std::string key, uint64_t value)
Definition
CardControllerWrapper.cpp:181
dunedaq::flxlibs::CardControllerWrapper::m_card_mutex
std::mutex m_card_mutex
Definition
CardControllerWrapper.hpp:70
dunedaq::flxlibs::CardControllerWrapper::get_bitfield
uint64_t get_bitfield(std::string key)
Definition
CardControllerWrapper.cpp:172
dunedaq::flxlibs::CardControllerWrapper::generate_opmon_data
void generate_opmon_data() override
Definition
CardControllerWrapper.cpp:225
dunedaq::flxlibs::opmon::LinkInfo
Definition
CardControllerWrapper.pb.h:80
dunedaq::flxlibs::opmon::LinkInfo::set_aligned
void set_aligned(bool value)
Definition
CardControllerWrapper.pb.h:295
dunedaq::flxlibs::opmon::LinkInfo::set_enabled
void set_enabled(bool value)
Definition
CardControllerWrapper.pb.h:273
dunedaq::opmonlib::MonitorableObject::publish
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
Definition
MonitorableObject.cpp:59
TLVL_ENTER_EXIT_METHODS
#define TLVL_ENTER_EXIT_METHODS
Definition
TimingIssues.hpp:22
FelixDataSender.hpp
FelixInterface.hpp
Logging.hpp
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:116
TLOG
#define TLOG(...)
Definition
macro.hpp:21
dunedaq::flxlibs
Definition
AvailableParserOperations.hpp:27
dunedaq
The DUNE-DAQ namespace.
Definition
cib_utilities.cpp:5
ers::fatal
void fatal(const Issue &issue)
Definition
ers.hpp:111
ers::error
void error(const Issue &issue)
Definition
ers.hpp:101
Generated on
for DUNE-DAQ by
1.18.0