6#include <boost/make_shared.hpp>
20 std::cout <<
"XDMA: opening dev: " << _devicePath << std::endl;
28 _ctrlIntf.emplace(_devicePath);
30 std::for_each(_eventFiles.begin(), _eventFiles.end(), [](
auto& eventFile) { eventFile = nullptr; });
34 for(
size_t i = 0; i < _maxDmaChannels; i++) {
36 _dmaChannels.emplace_back(_devicePath, i);
44 std::cout <<
"XDMA: opened interface with " << _dmaChannels.size() <<
" DMA channels and " << _eventFiles.size()
45 <<
" interrupt sources\n";
51 std::for_each(_eventFiles.begin(), _eventFiles.end(), [](
auto& eventFile) { eventFile = nullptr; });
62 if(bar == 0 && _ctrlIntf.has_value()) {
63 return _ctrlIntf.value();
68 const size_t dmaChIdx = bar - 13;
69 if(dmaChIdx < _dmaChannels.size()) {
70 return _dmaChannels[dmaChIdx];
78 constexpr size_t wordsPerLine = 8;
80 for(n = 0; n < (nbytes /
sizeof(*data)) && n < 64; n++) {
81 if(!(n % wordsPerLine)) {
82 std::cout << std::hex << std::setw(4) << std::setfill(
'0') << n *
sizeof(*data) <<
":";
84 std::cout <<
" " << std::hex << std::setw(8) << std::setfill(
'0') << data[n];
85 if((n % wordsPerLine) == wordsPerLine - 1) {
89 if((n % wordsPerLine) != wordsPerLine) {
97 std::cout <<
"XDMA: read " << sizeInBytes <<
" bytes @ BAR" << bar <<
", 0x" << std::hex << address << std::endl;
99 auto& intf = _intfFromBar(bar);
100 intf.read(address, data, sizeInBytes);
102 dump(data, sizeInBytes);
108 std::cout <<
"XDMA: write " << sizeInBytes <<
" bytes @ BAR" << bar <<
", 0x" << std::hex << address << std::endl;
110 auto& intf = _intfFromBar(bar);
111 intf.write(address, data, sizeInBytes);
113 dump(data, sizeInBytes);
119 std::promise<void> subscriptionDonePromise;
120 auto subscriptionDoneFuture = subscriptionDonePromise.get_future();
121 if(interruptNumber >= _maxInterrupts) {
124 subscriptionDonePromise.set_value();
125 return subscriptionDoneFuture;
128 if(!_eventFiles[interruptNumber]) {
129 _eventFiles[interruptNumber] = std::make_unique<EventFile>(
this, _devicePath, interruptNumber, asyncDomain);
130 _eventFiles[interruptNumber]->startThread(std::move(subscriptionDonePromise));
134 subscriptionDonePromise.set_value();
136 return subscriptionDoneFuture;
140 std::string result =
"XDMA backend: Device path = " + _devicePath +
", number of DMA channels = ";
145 result +=
"unknown (device closed)";
153 std::string address, std::map<std::string, std::string> parameters) {
154 if(address.empty()) {
158 return boost::make_shared<XdmaBackend>(
"/dev/" + address, parameters[
"map"]);
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)
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.
XdmaBackend(std::string devicePath, std::string mapFileName="")
Exception thrown when a logic error has occured.
Exception thrown when a runtime error has occured.
std::string to_string(const std::string &v)