6#include <boost/make_shared.hpp>
15 std::string devicePath,
const std::string& mapFileName,
const std::string& dataConsistencyKeyDescriptor)
18 _devicePath(
std::move(devicePath)) {}
22 std::cout <<
"XDMA: opening dev: " << _devicePath << std::endl;
30 _ctrlIntf.emplace(_devicePath);
32 std::ranges::for_each(_eventFiles, [](
auto& eventFile) { eventFile =
nullptr; });
36 for(
size_t i = 0; i < _maxDmaChannels; i++) {
38 _dmaChannels.emplace_back(_devicePath, i);
46 std::cout <<
"XDMA: opened interface with " << _dmaChannels.size() <<
" DMA channels and " << _eventFiles.size()
47 <<
" interrupt sources\n";
53 std::ranges::for_each(_eventFiles, [](
auto& eventFile) { eventFile =
nullptr; });
64 if(bar == 0 && _ctrlIntf.has_value()) {
65 return _ctrlIntf.value();
70 const size_t dmaChIdx = bar - 13;
71 if(dmaChIdx < _dmaChannels.size()) {
72 return _dmaChannels[dmaChIdx];
80 constexpr size_t wordsPerLine = 8;
82 for(n = 0; n < (nbytes /
sizeof(*data)) && n < 64; n++) {
83 if(!(n % wordsPerLine)) {
84 std::cout << std::hex << std::setw(4) << std::setfill(
'0') << n *
sizeof(*data) <<
":";
86 std::cout <<
" " << std::hex << std::setw(8) << std::setfill(
'0') << data[n];
87 if((n % wordsPerLine) == wordsPerLine - 1) {
91 if((n % wordsPerLine) != wordsPerLine) {
99 std::cout <<
"XDMA: read " << sizeInBytes <<
" bytes @ BAR" << bar <<
", 0x" << std::hex << address << std::endl;
101 auto& intf = intfFromBar(bar);
102 intf.read(address, data, sizeInBytes);
104 dump(data, sizeInBytes);
110 std::cout <<
"XDMA: write " << sizeInBytes <<
" bytes @ BAR" << bar <<
", 0x" << std::hex << address << std::endl;
112 auto& intf = intfFromBar(bar);
113 intf.write(address, data, sizeInBytes);
115 dump(data, sizeInBytes);
121 std::promise<void> subscriptionDonePromise;
122 auto subscriptionDoneFuture = subscriptionDonePromise.get_future();
123 if(interruptNumber >= _maxInterrupts) {
126 subscriptionDonePromise.set_value();
127 return subscriptionDoneFuture;
130 if(!_eventFiles[interruptNumber]) {
131 _eventFiles[interruptNumber] = std::make_unique<EventFile>(
this, _devicePath, interruptNumber, asyncDomain);
132 _eventFiles[interruptNumber]->startThread(std::move(subscriptionDonePromise));
136 subscriptionDonePromise.set_value();
138 return subscriptionDoneFuture;
142 std::string result =
"XDMA backend: Device path = " + _devicePath +
", number of DMA channels = ";
147 result +=
"unknown (device closed)";
157 std::string address, std::map<std::string, std::string> parameters) {
158 if(address.empty()) {
162 if(parameters[
"map"].empty()) {
166 return boost::make_shared<XdmaBackend>(
"/dev/" + address, parameters[
"map"], parameters[
"DataConsistencyKeys"]);
bool isFunctional() const noexcept final
Return whether a device is working as intended, usually this means it is opened and does not have any...
void setOpenedAndClearException() noexcept
Backends should call this function at the end of a (successful) open() call.
void setException(const std::string &message) noexcept final
Set the backend into an exception state.
std::atomic< bool > _opened
flag if backend is opened
Base class for address-based device backends (e.g.
void dump(const int32_t *data, size_t nbytes)
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
XdmaBackend(std::string devicePath, const std::string &mapFileName="", const std::string &dataConsistencyKeyDescriptor="")
void write(uint64_t bar, uint64_t address, const int32_t *data, size_t sizeInBytes) override
Write function to be implemented by backends.
void open() override
Open the device.
void closeImpl() override
All backends derrived from NumericAddressedBackend must implement closeImpl() instead of close.
void read(uint64_t bar, uint64_t address, int32_t *data, size_t sizeInBytes) override
Read function to be implemented by backends.
std::string readDeviceInfo() override
Return a device information string containing hardware details like the firmware version number or th...
std::future< void > activateSubscription(uint32_t interruptNumber, boost::shared_ptr< async::DomainImpl< std::nullptr_t > > asyncDomain) override
Activate/create the subscription for a given interrupt (for instance by starting the according interr...
bool isOpen() override
Return whether a device has been opened or not.
Exception thrown when a logic error has occured.
Exception thrown when a runtime error has occured.
std::string to_string(const std::string &v)