DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CardWrapper.hpp
Go to the documentation of this file.
1
8#ifndef FLXLIBS_SRC_CARDWRAPPER_HPP_
9#define FLXLIBS_SRC_CARDWRAPPER_HPP_
10
11//#include "flxlibs/felixcardreader/Nljs.hpp"
12//#include "flxlibs/felixcardreader/Structs.hpp"
13
16
17#include "flxcard/FlxCard.h"
18#include "packetformat/block_format.hpp"
19
20#include <nlohmann/json.hpp>
21
22#include <atomic>
23#include <memory>
24#include <mutex>
25#include <string>
26
27namespace dunedaq::flxlibs {
28
30{
31public:
36 CardWrapper(const appmodel::FelixInterface * cfg, std::vector<unsigned int>);
38 CardWrapper(const CardWrapper&) = delete;
39 CardWrapper& operator=(const CardWrapper&) = delete;
42
43 void configure();
44 void start();
45 void stop();
46 void set_running(bool should_run);
47
48 void graceful_stop();
49
50 void set_block_addr_handler(std::function<void(uint64_t)>& handle) // NOLINT(build/unsigned)
51 { // NOLINT
52 m_handle_block_addr = std::bind(handle, std::placeholders::_1);
54 }
55
56private:
57
58 // Constants
59 static constexpr size_t m_max_links_per_card = 6;
60 // static constexpr size_t m_margin_blocks = 4;
61 // static constexpr size_t m_block_threshold = 256;
62 static constexpr size_t m_block_size = 4096; // felix::packetformat::BLOCKSIZE;
63 static constexpr size_t m_dma_wraparound = FLX_DMA_WRAPAROUND;
64
65 // Card
66 void open_card();
67 void close_card();
68
69 // DMA
70 int allocate_CMEM(uint8_t numa, u_long bsize, u_long* paddr, u_long* vaddr); // NOLINT
71 void init_DMA();
72 void start_DMA();
73 void stop_DMA();
74 uint64_t bytes_available(); // NOLINT
76
77 // Configuration and internals
78
79 std::atomic<bool> m_run_marker;
80 bool m_configured{ false };
81 uint8_t m_card_id; // NOLINT
82 uint8_t m_logical_unit; // NOLINT
83 std::string m_card_id_str;
84 uint8_t m_dma_id; // NOLINT
85 size_t m_margin_blocks; // NOLINT
86 size_t m_block_threshold; // NOLINT
87 bool m_interrupt_mode; // NOLINT
88 size_t m_poll_time; // NOLINT
89 uint8_t m_numa_id; // NOLINT
90 std::vector<unsigned int> m_links_enabled; // NOLINT
91 std::string m_info_str;
92
93 // Card object
94 using UniqueFlxCard = std::unique_ptr<FlxCard>;
96 std::mutex m_card_mutex;
97
98 // DMA: CMEM
99 std::size_t m_dma_memory_size; // size of CMEM (driver) memory to allocate
100 int m_cmem_handle; // handle to the DMA memory block
101 uint64_t m_virt_addr; // NOLINT virtual address of the DMA memory block
102 uint64_t m_phys_addr; // NOLINT physical address of the DMA memory block
103 uint64_t m_current_addr; // NOLINT pointer to the current write position for the card
104 unsigned m_read_index; // NOLINT
105 u_long m_destination; // u_long -> FlxCard.h
106
107 // Processor
108 inline static const std::string m_dma_processor_name = "flx-dma";
109 std::atomic<bool> m_run_lock;
111 std::function<void(uint64_t)> m_handle_block_addr; // NOLINT
113 void process_DMA();
114};
115
116} // namespace dunedaq::flxlibs
117
118#endif // FLXLIBS_SRC_CARDWRAPPER_HPP_
CardWrapper(const CardWrapper &)=delete
CardWrapper is not copy-constructible.
utilities::ReusableThread m_dma_processor
static constexpr size_t m_max_links_per_card
void set_running(bool should_run)
std::function< void(uint64_t)> m_handle_block_addr
CardWrapper(CardWrapper &&)=delete
CardWrapper is not move-constructible.
std::atomic< bool > m_run_lock
static constexpr size_t m_block_size
CardWrapper & operator=(const CardWrapper &)=delete
CardWrapper is not copy-assignable.
int allocate_CMEM(uint8_t numa, u_long bsize, u_long *paddr, u_long *vaddr)
std::atomic< bool > m_run_marker
std::vector< unsigned int > m_links_enabled
static constexpr size_t m_dma_wraparound
CardWrapper(const appmodel::FelixInterface *cfg, std::vector< unsigned int >)
CardWrapper Constructor.
CardWrapper & operator=(CardWrapper &&)=delete
CardWrapper is not move-assignable.
std::unique_ptr< FlxCard > UniqueFlxCard
void set_block_addr_handler(std::function< void(uint64_t)> &handle)
static const std::string m_dma_processor_name