DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::flxlibs::CardControllerWrapper Class Reference

#include <CardControllerWrapper.hpp>

Inheritance diagram for dunedaq::flxlibs::CardControllerWrapper:
[legend]
Collaboration diagram for dunedaq::flxlibs::CardControllerWrapper:
[legend]

Public Types

using data_t = nlohmann::json
 
- Public Types inherited from dunedaq::opmonlib::MonitorableObject
using NodePtr = std::weak_ptr<MonitorableObject>
 
using NewNodePtr = std::shared_ptr<MonitorableObject>
 
using ElementId = std::string
 

Public Member Functions

 CardControllerWrapper (uint32_t device_id, const appmodel::FelixInterface *flx_cfg, const std::vector< const appmodel::FelixDataSender * > &flx_senders)
 CardControllerWrapper Constructor.
 
 ~CardControllerWrapper ()
 
 CardControllerWrapper (const CardControllerWrapper &)=delete
 Not copy-constructible.
 
CardControllerWrapperoperator= (const CardControllerWrapper &)=delete
 Not copy-assignable.
 
 CardControllerWrapper (CardControllerWrapper &&)=delete
 Not move-constructible.
 
CardControllerWrapperoperator= (CardControllerWrapper &&)=delete
 Not move-assignable.
 
void init ()
 
void configure (uint16_t super_chunk_size, bool emu_fanout)
 
uint64_t get_register (std::string key)
 
void set_register (std::string key, uint64_t value)
 
uint64_t get_bitfield (std::string key)
 
void set_bitfield (std::string key, uint64_t value)
 
void gth_reset ()
 
void check_alignment (uint64_t aligned)
 
- Public Member Functions inherited from dunedaq::opmonlib::MonitorableObject
 MonitorableObject (const MonitorableObject &)=delete
 
MonitorableObjectoperator= (const MonitorableObject &)=delete
 
 MonitorableObject (MonitorableObject &&)=delete
 
MonitorableObjectoperator= (MonitorableObject &&)=delete
 
virtual ~MonitorableObject ()=default
 
auto get_opmon_id () const noexcept
 
auto get_opmon_level () const noexcept
 

Protected Member Functions

void generate_opmon_data () override
 
- Protected Member Functions inherited from dunedaq::opmonlib::MonitorableObject
 MonitorableObject ()=default
 
void register_node (ElementId name, NewNodePtr)
 
void publish (google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
 

Private Types

using UniqueFlxCard = std::unique_ptr<FlxCard>
 

Private Member Functions

void open_card ()
 
void close_card ()
 

Private Attributes

uint32_t m_device_id
 
const appmodel::FelixInterfacem_flx_cfg
 
const std::vector< const appmodel::FelixDataSender * > m_flx_senders
 
UniqueFlxCard m_flx_card
 
std::mutex m_card_mutex
 

Additional Inherited Members

- Static Public Member Functions inherited from dunedaq::opmonlib::MonitorableObject
static bool publishable_metric (OpMonLevel entry, OpMonLevel system) noexcept
 

Detailed Description

Definition at line 27 of file CardControllerWrapper.hpp.

Member Typedef Documentation

◆ data_t

Definition at line 40 of file CardControllerWrapper.hpp.

◆ UniqueFlxCard

using dunedaq::flxlibs::CardControllerWrapper::UniqueFlxCard = std::unique_ptr<FlxCard>
private

Definition at line 64 of file CardControllerWrapper.hpp.

Constructor & Destructor Documentation

◆ CardControllerWrapper() [1/3]

dunedaq::flxlibs::CardControllerWrapper::CardControllerWrapper ( uint32_t device_id,
const appmodel::FelixInterface * flx_cfg,
const std::vector< const appmodel::FelixDataSender * > & flx_senders )

CardControllerWrapper Constructor.

Definition at line 40 of file CardControllerWrapper.cpp.

40 :
41m_device_id(device_id),
42m_flx_cfg(flx_cfg),
43m_flx_senders(flx_senders)
44{
45
47 << "CardControllerWrapper constructor called. Open card " << m_device_id;
48
49 m_flx_card = std::make_unique<FlxCard>();
50 if (m_flx_card == nullptr) {
51 ers::fatal(flxlibs::CardError(ERS_HERE, "Couldn't create FlxCard object."));
52 }
53 open_card();
54 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "CardControllerWrapper constructed.";
55
56}
#define ERS_HERE
const std::vector< const appmodel::FelixDataSender * > m_flx_senders
const appmodel::FelixInterface * m_flx_cfg
#define TLVL_ENTER_EXIT_METHODS
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
void fatal(const Issue &issue)
Definition ers.hpp:88

◆ ~CardControllerWrapper()

dunedaq::flxlibs::CardControllerWrapper::~CardControllerWrapper ( )

Definition at line 58 of file CardControllerWrapper.cpp.

59{
61 << "CardControllerWrapper destructor called. First stop check, then closing card.";
62 close_card();
63 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "CardControllerWrapper destroyed.";
64}

◆ CardControllerWrapper() [2/3]

dunedaq::flxlibs::CardControllerWrapper::CardControllerWrapper ( const CardControllerWrapper & )
delete

Not copy-constructible.

◆ CardControllerWrapper() [3/3]

dunedaq::flxlibs::CardControllerWrapper::CardControllerWrapper ( CardControllerWrapper && )
delete

Not move-constructible.

Member Function Documentation

◆ check_alignment()

void dunedaq::flxlibs::CardControllerWrapper::check_alignment ( uint64_t aligned)

Definition at line 200 of file CardControllerWrapper.cpp.

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}
uint16_t get_slr() const
Get "slr" attribute value. Super logic region of a FLX card.
void error(const Issue &issue)
Definition ers.hpp:81

◆ close_card()

void dunedaq::flxlibs::CardControllerWrapper::close_card ( )
private

Definition at line 143 of file CardControllerWrapper.cpp.

144{
145 TLOG_DEBUG(TLVL_WORK_STEPS) << "Closing FELIX card " << m_device_id;
146 try {
147 const std::lock_guard<std::mutex> lock(m_card_mutex);
148 m_flx_card->card_close();
149 } catch (FlxException& ex) {
150 ers::error(flxlibs::CardError(ERS_HERE, ex.what()));
151 exit(EXIT_FAILURE);
152 }
153}

◆ configure()

void dunedaq::flxlibs::CardControllerWrapper::configure ( uint16_t super_chunk_size,
bool emu_fanout )

Definition at line 89 of file CardControllerWrapper.cpp.

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 }
110 else {
111 //set_register("FE_EMU_LOGIC_ENA", 0);
112 //set_register("FE_EMU_LOGIC_L1A_TRIGGERED", 0);
113 //set_register("FE_EMU_LOGIC_IDLES", 0);
114 //set_register("FE_EMU_LOGIC_CHUNK_LENGTH", 0);
115
116 set_bitfield("FE_EMU_ENA_EMU_TOFRONTEND", 0);
117 set_bitfield("FE_EMU_ENA_EMU_TOHOST", 0);
118 set_bitfield("GBT_TOFRONTEND_FANOUT_SEL", 0);
119 set_bitfield("GBT_TOHOST_FANOUT_SEL", 0);
120 }
121 // Enable and configure the right links
122
123 for(auto s : m_flx_senders) {
124 set_bitfield(fmt::format("SUPER_CHUNK_FACTOR_LINK_{:02}",s->get_link()), super_chunk_size);
125 set_bitfield(fmt::format("DECODING_LINK{:02}_EGROUP0_CTRL_EPATH_ENA",s->get_link()), 1);
126 }
127}
void set_bitfield(std::string key, uint64_t value)

◆ generate_opmon_data()

void dunedaq::flxlibs::CardControllerWrapper::generate_opmon_data ( )
overrideprotectedvirtual

Hook for customisable pubblication. The function can throw, exception will be caught by the monitoring thread

Reimplemented from dunedaq::opmonlib::MonitorableObject.

Definition at line 225 of file CardControllerWrapper.cpp.

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) },
241 {"link", fmt::format("{}", s->get_link()) } });
242
243 } // loop over links
244}
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept

◆ get_bitfield()

uint64_t dunedaq::flxlibs::CardControllerWrapper::get_bitfield ( std::string key)

Definition at line 173 of file CardControllerWrapper.cpp.

174{
175 TLOG_DEBUG(TLVL_WORK_STEPS) << "Reading value of bitfield " << key;
176 const std::lock_guard<std::mutex> lock(m_card_mutex);
177 auto bf_val = m_flx_card->cfg_get_option(key.c_str(), false);
178 return bf_val;
179}

◆ get_register()

uint64_t dunedaq::flxlibs::CardControllerWrapper::get_register ( std::string key)

Definition at line 156 of file CardControllerWrapper.cpp.

157{
158 TLOG_DEBUG(TLVL_WORK_STEPS) << "Reading value of register " << key;
159 const std::lock_guard<std::mutex> lock(m_card_mutex);
160 auto reg_val = m_flx_card->cfg_get_reg(key.c_str());
161 return reg_val;
162}

◆ gth_reset()

void dunedaq::flxlibs::CardControllerWrapper::gth_reset ( )

Definition at line 190 of file CardControllerWrapper.cpp.

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}

◆ init()

void dunedaq::flxlibs::CardControllerWrapper::init ( )

Definition at line 67 of file CardControllerWrapper.cpp.

67 {
68
69 // Card initialization
70 // this is complicated....should we repeat all code in flx_init?
71 // For now do not do the configs of the clock chips
72 const std::lock_guard<std::mutex> lock(m_card_mutex);
73 m_flx_card->cfg_set_option( BF_MMCM_MAIN_LCLK_SEL, 1 ); // local clock
74 m_flx_card->soft_reset();
75 //si5328_configure();
76 //si5345_configure(0);
77 m_flx_card->cfg_set_option(BF_GBT_SOFT_RESET, 0xFFFFFFFFFFFF);
78 m_flx_card->cfg_set_option(BF_GBT_SOFT_RESET, 0);
79
80 int bad_channels = m_flx_card->gbt_setup( FLX_GBT_ALIGNMENT_ONE, FLX_GBT_TMODE_FEC ); //What does this do?
81 if(bad_channels) {
82 TLOG()<< bad_channels << " not aligned.";
83 }
84 m_flx_card->irq_disable( ALL_IRQS );
85
86}
#define TLOG(...)
Definition macro.hpp:22

◆ open_card()

void dunedaq::flxlibs::CardControllerWrapper::open_card ( )
private

Definition at line 130 of file CardControllerWrapper.cpp.

131{
132 TLOG_DEBUG(TLVL_WORK_STEPS) << "Opening FELIX card " << m_device_id;
133 try {
134 const std::lock_guard<std::mutex> lock(m_card_mutex);
135 m_flx_card->card_open(static_cast<int>(m_device_id), LOCK_NONE); // FlxCard.h
136 } catch (FlxException& ex) {
137 ers::error(flxlibs::CardError(ERS_HERE, ex.what()));
138 exit(EXIT_FAILURE);
139 }
140}

◆ operator=() [1/2]

CardControllerWrapper & dunedaq::flxlibs::CardControllerWrapper::operator= ( CardControllerWrapper && )
delete

Not move-assignable.

◆ operator=() [2/2]

CardControllerWrapper & dunedaq::flxlibs::CardControllerWrapper::operator= ( const CardControllerWrapper & )
delete

Not copy-assignable.

◆ set_bitfield()

void dunedaq::flxlibs::CardControllerWrapper::set_bitfield ( std::string key,
uint64_t value )

Definition at line 182 of file CardControllerWrapper.cpp.

183{
184 TLOG_DEBUG(TLVL_WORK_STEPS) << "Setting value of bitfield " << key << " to " << value;;
185 const std::lock_guard<std::mutex> lock(m_card_mutex);
186 m_flx_card->cfg_set_option(key.c_str(), value, false);
187}

◆ set_register()

void dunedaq::flxlibs::CardControllerWrapper::set_register ( std::string key,
uint64_t value )

Definition at line 165 of file CardControllerWrapper.cpp.

166{
167 TLOG_DEBUG(TLVL_WORK_STEPS) << "Setting value of register " << key << " to " << value;
168 const std::lock_guard<std::mutex> lock(m_card_mutex);
169 m_flx_card->cfg_set_reg(key.c_str(), value);
170}

Member Data Documentation

◆ m_card_mutex

std::mutex dunedaq::flxlibs::CardControllerWrapper::m_card_mutex
private

Definition at line 70 of file CardControllerWrapper.hpp.

◆ m_device_id

uint32_t dunedaq::flxlibs::CardControllerWrapper::m_device_id
private

Definition at line 61 of file CardControllerWrapper.hpp.

◆ m_flx_card

UniqueFlxCard dunedaq::flxlibs::CardControllerWrapper::m_flx_card
private

Definition at line 69 of file CardControllerWrapper.hpp.

◆ m_flx_cfg

const appmodel::FelixInterface* dunedaq::flxlibs::CardControllerWrapper::m_flx_cfg
private

Definition at line 66 of file CardControllerWrapper.hpp.

◆ m_flx_senders

const std::vector<const appmodel::FelixDataSender*> dunedaq::flxlibs::CardControllerWrapper::m_flx_senders
private

Definition at line 67 of file CardControllerWrapper.hpp.


The documentation for this class was generated from the following files: