ChimeraTK-DeviceAccess 03.26.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"
7#include "DeviceBackendImpl.h"
9
10#include <boost/pointer_cast.hpp>
11
12#include <mutex>
13#include <string>
14
15namespace ChimeraTK {
16
17 class NumericAddressedLowLevelTransferElement;
18 class TriggeredPollDistributor;
19
22 public:
23 explicit NumericAddressedBackend(const std::string& mapFileName = "",
24 std::unique_ptr<NumericAddressedRegisterCatalogue> registerMapPointer =
25 std::make_unique<NumericAddressedRegisterCatalogue>(),
26 const std::string& dataConsistencyKeyDescriptor = "");
27
28 ~NumericAddressedBackend() override = default;
29
35 virtual void read(uint64_t bar, uint64_t address, int32_t* data, size_t sizeInBytes);
36
42 virtual void write(uint64_t bar, uint64_t address, int32_t const* data, size_t sizeInBytes);
43
51 [[deprecated]] virtual void read([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address,
52 [[maybe_unused]] int32_t* data, [[maybe_unused]] size_t sizeInBytes);
53
61 [[deprecated]] virtual void write([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address,
62 [[maybe_unused]] int32_t const* data, [[maybe_unused]] size_t sizeInBytes);
63
67 virtual bool barIndexValid(uint64_t bar);
68
78 virtual bool canMergeRequests() const { return true; }
79
92 virtual size_t minimumTransferAlignment([[maybe_unused]] uint64_t bar) const { return 1; }
93
95
97
107
108 void activateAsyncRead() noexcept override;
109
113 void close() final;
114
119 virtual void closeImpl() {}
120
133 virtual std::future<void> activateSubscription(
134 uint32_t interruptNumber, boost::shared_ptr<async::DomainImpl<std::nullptr_t>> asyncDomain);
135
137 void setExceptionImpl() noexcept override;
138
146 template<typename BackendSpecificUserType>
147 std::pair<BackendSpecificUserType, VersionNumber> getAsyncDomainInitialValue(size_t asyncDomainId);
148
149 protected:
150 /*
151 * Register catalogue. A reference is used here which is filled from _registerMapPointer in the constructor to allow
152 * backend implementations to provide their own type based on the NumericAddressedRegisterCatalogue.
153 */
156
159
162
165
166 template<class UserType>
168
169 private:
170 template<typename UserType>
171 boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(
172 const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
173
174 // internal helper function to get the a synchronous accessor, which is also needed by the asynchronous version
175 // internally, but is not given out
176 template<typename UserType>
177 boost::shared_ptr<NDRegisterAccessor<UserType>> getSyncRegisterAccessor(
178 const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
179
181 std::atomic_bool _asyncIsActive{false};
182
183 std::unordered_map<std::string, std::shared_ptr<detail::CountedRecursiveMutex>> _doubleBufferMutexMap;
184 };
185
186 /********************************************************************************************************************/
187
188 template<typename BackendSpecificUserType>
189 std::pair<BackendSpecificUserType, VersionNumber> NumericAddressedBackend::getAsyncDomainInitialValue(
190 [[maybe_unused]] size_t asyncDomainId) {
191 static_assert(std::is_same<BackendSpecificUserType, std::nullptr_t>::value,
192 "NumericAddressedBackend only supports async::Domain<nullptr_t>.");
193 return {nullptr, VersionNumber{nullptr}};
194 }
195
196} // 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.