ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
NumericAddressedBackend.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include "async/DomainImpl.h"
6#include "DeviceBackendImpl.h"
8
9#include <boost/pointer_cast.hpp>
10
11#include <mutex>
12#include <string>
13
14namespace ChimeraTK {
15
16 class NumericAddressedLowLevelTransferElement;
17 class TriggeredPollDistributor;
18
21 public:
22 explicit NumericAddressedBackend(const std::string& mapFileName = "",
23 std::unique_ptr<NumericAddressedRegisterCatalogue> registerMapPointer =
24 std::make_unique<NumericAddressedRegisterCatalogue>(),
25 const std::string& dataConsistencyKeyDescriptor = "");
26
27 ~NumericAddressedBackend() override = default;
28
34 virtual void read(uint64_t bar, uint64_t address, int32_t* data, size_t sizeInBytes);
35
41 virtual void write(uint64_t bar, uint64_t address, int32_t const* data, size_t sizeInBytes);
42
50 [[deprecated]] virtual void read([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address,
51 [[maybe_unused]] int32_t* data, [[maybe_unused]] size_t sizeInBytes);
52
60 [[deprecated]] virtual void write([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address,
61 [[maybe_unused]] int32_t const* data, [[maybe_unused]] size_t sizeInBytes);
62
66 virtual bool barIndexValid(uint64_t bar);
67
77 virtual bool canMergeRequests() const { return true; }
78
91 virtual size_t minimumTransferAlignment([[maybe_unused]] uint64_t bar) const { return 1; }
92
94
96
106
107 void activateAsyncRead() noexcept override;
108
112 void close() final;
113
118 virtual void closeImpl() {}
119
132 virtual std::future<void> activateSubscription(
133 uint32_t interruptNumber, boost::shared_ptr<async::DomainImpl<std::nullptr_t>> asyncDomain);
134
136 void setExceptionImpl() noexcept override;
137
145 template<typename BackendSpecificUserType>
146 std::pair<BackendSpecificUserType, VersionNumber> getAsyncDomainInitialValue(size_t asyncDomainId);
147
148 protected:
149 /*
150 * Register catalogue. A reference is used here which is filled from _registerMapPointer in the constructor to allow
151 * backend implementations to provide their own type based on the NumericAddressedRegisterCatalogue.
152 */
155
158
161
164
165 template<class UserType, class ConverterType>
167
168 private:
169 template<typename UserType>
170 boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(
171 const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
172
173 // internal helper function to get the a synchronous accessor, which is also needed by the asynchronous version
174 // internally, but is not given out
175 template<typename UserType>
176 boost::shared_ptr<NDRegisterAccessor<UserType>> getSyncRegisterAccessor(
177 const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
178
180 std::atomic_bool _asyncIsActive{false};
181 };
182
183 /********************************************************************************************************************/
184
185 template<typename BackendSpecificUserType>
186 std::pair<BackendSpecificUserType, VersionNumber> NumericAddressedBackend::getAsyncDomainInitialValue(
187 [[maybe_unused]] size_t asyncDomainId) {
188 static_assert(std::is_same<BackendSpecificUserType, std::nullptr_t>::value,
189 "NumericAddressedBackend only supports async::Domain<nullptr_t>.");
190 return {nullptr, VersionNumber{nullptr}};
191 }
192
193} // namespace ChimeraTK
Set of AccessMode flags with additional functionality for an easier handling.
Definition AccessMode.h:48
DeviceBackendImpl implements some basic functionality which should be available for all backends.
Container for backend metadata.
N-dimensional register accessor.
Base class for address-based device backends (e.g.
MetadataCatalogue _metadataCatalogue
metadata catalogue
RegisterCatalogue getRegisterCatalogue() const override
Return the register catalogue with detailed information on all registers.
std::unique_ptr< NumericAddressedRegisterCatalogue > _registerMapPointer
virtual bool barIndexValid(uint64_t bar)
Function to be implemented by the backends.
NumericAddressedRegisterCatalogue & _registerMap
NumericAddressedRegisterInfo getRegisterInfo(const RegisterPath &registerPathName)
getRegisterInfo returns a NumericAddressedRegisterInfo object for the given register.
void setExceptionImpl() noexcept override
Turn off the internal variable which remembers that async is active.
void close() final
Deactivates all asynchronous accessors and calls closeImpl().
virtual bool canMergeRequests() const
Determines whether the backend supports merging of requests (read or write)
MetadataCatalogue getMetadataCatalogue() const override
Return the device metadata catalogue.
void activateAsyncRead() noexcept override
Activate asyncronous read for all transfer elements where AccessMode::wait_for_new_data is set.
virtual size_t minimumTransferAlignment(uint64_t bar) const
Determines the supported minimum alignment for any read/write requests.
virtual void closeImpl()
All backends derrived from NumericAddressedBackend must implement closeImpl() instead of close.
~NumericAddressedBackend() override=default
virtual std::future< void > activateSubscription(uint32_t interruptNumber, boost::shared_ptr< async::DomainImpl< std::nullptr_t > > asyncDomain)
Activate/create the subscription for a given interrupt (for instance by starting the according interr...
std::mutex _unalignedAccess
mutex for protecting unaligned access
std::pair< BackendSpecificUserType, VersionNumber > getAsyncDomainInitialValue(size_t asyncDomainId)
Get the initial value for a certain async::Domain.
Implementation of the NDRegisterAccessor for NumericAddressedBackends for multiplexd 2D registers.
Implementation of the NDRegisterAccessor for NumericAddressedBackends, responsible for the underlying...
Catalogue of register information.
Class to store a register path name.
Class for generating and holding version numbers without exposing a numeric representation.
STL namespace.