9 const std::string& deviceName,
const std::string& mapFileName,
const std::string& dataConsistencyKeyDescriptor)
12 _uioAccess = std::make_shared<UioAccess>(
"/dev/" + deviceName);
22 std::string address, std::map<std::string, std::string> parameters) {
27 if(parameters[
"map"].empty()) {
31 return boost::make_shared<UioBackend>(address, parameters[
"map"], parameters[
"DataConsistencyKeys"]);
48 if(_interruptWaitingThread.joinable()) {
49 _stopInterruptLoop =
true;
50 _interruptWaitingThread.join();
63 void UioBackend::read(uint64_t bar, uint64_t address, int32_t* data,
size_t sizeInBytes) {
67 _uioAccess->read(bar, address, data, sizeInBytes);
70 void UioBackend::write(uint64_t bar, uint64_t address, int32_t
const* data,
size_t sizeInBytes) {
74 _uioAccess->write(bar, address, data, sizeInBytes);
79 std::promise<void> subscriptionDonePromise;
81 if(interruptNumber != 0) {
82 setException(
"UIO: Backend only uses interrupt number 0");
83 subscriptionDonePromise.set_value();
84 return subscriptionDonePromise.get_future();
86 if(_interruptWaitingThread.joinable()) {
87 subscriptionDonePromise.set_value();
88 return subscriptionDonePromise.get_future();
91 _stopInterruptLoop =
false;
93 auto subscriptionDoneFuture = subscriptionDonePromise.get_future();
94 _interruptWaitingThread = std::thread(&UioBackend::waitForInterruptLoop,
this, std::move(subscriptionDonePromise));
95 return subscriptionDoneFuture;
99 std::string result = std::string(
"UIO backend: Device path = " + _uioAccess->getDeviceFilePath());
101 result +=
" (device closed)";
107 void UioBackend::waitForInterruptLoop(std::promise<void> subscriptionDonePromise) {
117 auto promiseFulfiller = cppext::finally([&]() { subscriptionDonePromise.set_value(); });
120 _uioAccess->clearInterrupts();
123 if(_uioAccess->waitForInterrupt(0) > 0) {
124 _uioAccess->clearInterrupts();
132 while(!_stopInterruptLoop) {
134 auto numberOfInterrupts = _uioAccess->waitForInterrupt(100);
136 if(numberOfInterrupts > 0) {
137 _uioAccess->clearInterrupts();
144 if(numberOfInterrupts > 1) {
145 std::cout <<
"UioBackend: Lost " << (numberOfInterrupts - 1) <<
" interrupts. " << std::endl;
147 std::cout <<
"dispatching interrupt " << std::endl;
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.
void checkActiveException() final
Function to be called by backends when needing to check for an active exception.
bool isOpen() override
Return whether a device has been opened or not.
std::atomic< bool > _opened
flag if backend is opened
Base class for address-based device backends (e.g.
void close() final
Deactivates all asynchronous accessors and calls closeImpl().
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
void write(uint64_t bar, uint64_t address, int32_t const *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::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...
std::string readDeviceInfo() override
Return a device information string containing hardware details like the firmware version number or th...
boost::shared_ptr< async::DomainImpl< std::nullptr_t > > _asyncDomain
UioBackend(const std::string &deviceName, const std::string &mapFileName, const std::string &dataConsistencyKeyDescriptor)
bool barIndexValid(uint64_t bar) override
Function to be implemented by the backends.
Exception thrown when a logic error has occured.
Exception thrown when a runtime error has occured.
const char * what() const noexcept override
Return the message describing what exactly went wrong.