ChimeraTK-DeviceAccess  03.18.00
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 
14 namespace 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 
26  ~NumericAddressedBackend() override = default;
27 
33  virtual void read(uint64_t bar, uint64_t address, int32_t* data, size_t sizeInBytes);
34 
40  virtual void write(uint64_t bar, uint64_t address, int32_t const* data, size_t sizeInBytes);
41 
49  [[deprecated]] virtual void read([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address,
50  [[maybe_unused]] int32_t* data, [[maybe_unused]] size_t sizeInBytes);
51 
59  [[deprecated]] virtual void write([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address,
60  [[maybe_unused]] int32_t const* data, [[maybe_unused]] size_t sizeInBytes);
61 
65  virtual bool barIndexValid(uint64_t bar);
66 
76  virtual bool canMergeRequests() const { return true; }
77 
90  virtual size_t minimumTransferAlignment([[maybe_unused]] uint64_t bar) const { return 1; }
91 
92  RegisterCatalogue getRegisterCatalogue() const override;
93 
94  MetadataCatalogue getMetadataCatalogue() const override;
95 
105 
106  void activateAsyncRead() noexcept override;
107 
111  void close() final;
112 
117  virtual void closeImpl() {}
118 
131  virtual std::future<void> activateSubscription(
132  uint32_t interruptNumber, boost::shared_ptr<async::DomainImpl<std::nullptr_t>> asyncDomain);
133 
135  void setExceptionImpl() noexcept override;
136 
144  template<typename BackendSpecificUserType>
145  std::pair<BackendSpecificUserType, VersionNumber> getAsyncDomainInitialValue(size_t asyncDomainId);
146 
147  protected:
148  /*
149  * Register catalogue. A reference is used here which is filled from _registerMapPointer in the constructor to allow
150  * backend implementations to provide their own type based on the NumericAddressedRegisterCatalogue.
151  */
154 
157 
159  std::mutex _unalignedAccess;
160 
163 
164  template<class UserType, class ConverterType>
166 
167  private:
168  template<typename UserType>
169  boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(
170  const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
171 
172  // internal helper function to get the a synchronous accessor, which is also needed by the asynchronous version
173  // internally, but is not given out
174  template<typename UserType>
175  boost::shared_ptr<NDRegisterAccessor<UserType>> getSyncRegisterAccessor(
176  const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
177 
179  std::atomic_bool _asyncIsActive{false};
180  };
181 
182  /********************************************************************************************************************/
183 
184  template<typename BackendSpecificUserType>
185  std::pair<BackendSpecificUserType, VersionNumber> NumericAddressedBackend::getAsyncDomainInitialValue(
186  [[maybe_unused]] size_t asyncDomainId) {
187  static_assert(std::is_same<BackendSpecificUserType, std::nullptr_t>::value,
188  "NumericAddressedBackend only supports async::Domain<nullptr_t>.");
189  return {nullptr, VersionNumber{nullptr}};
190  }
191 
192 } // namespace ChimeraTK
ChimeraTK::NumericAddressedBackend::_metadataCatalogue
MetadataCatalogue _metadataCatalogue
metadata catalogue
Definition: NumericAddressedBackend.h:156
ChimeraTK::NumericAddressedBackend::closeImpl
virtual void closeImpl()
All backends derrived from NumericAddressedBackend must implement closeImpl() instead of close.
Definition: NumericAddressedBackend.h:117
ChimeraTK::NumericAddressedBackend::close
void close() final
Deactivates all asynchronous accessors and calls closeImpl().
Definition: NumericAddressedBackend.cc:220
ChimeraTK::NumericAddressedRegisterInfo
Definition: NumericAddressedRegisterCatalogue.h:15
ChimeraTK::NumericAddressedBackend::_unalignedAccess
std::mutex _unalignedAccess
mutex for protecting unaligned access
Definition: NumericAddressedBackend.h:159
ChimeraTK::MetadataCatalogue
Container for backend metadata.
Definition: MetadataCatalogue.h:17
ChimeraTK::NumericAddressedBackend::getAsyncDomainInitialValue
std::pair< BackendSpecificUserType, VersionNumber > getAsyncDomainInitialValue(size_t asyncDomainId)
Get the initial value for a certain async::Domain.
DeviceBackendImpl.h
DomainImpl.h
ChimeraTK::RegisterCatalogue
Catalogue of register information.
Definition: RegisterCatalogue.h:20
ChimeraTK::NumericAddressedBackend::write
virtual void write(uint64_t bar, uint64_t address, int32_t const *data, size_t sizeInBytes)
Write function to be implemented by backends.
Definition: NumericAddressedBackend.cc:85
ChimeraTK::NumericAddressedBackend::read
virtual void read(uint64_t bar, uint64_t address, int32_t *data, size_t sizeInBytes)
Read function to be implemented by backends.
Definition: NumericAddressedBackend.cc:76
ChimeraTK::NumericAddressedBackend::activateAsyncRead
void activateAsyncRead() noexcept override
Activate asyncronous read for all transfer elements where AccessMode::wait_for_new_data is set.
Definition: NumericAddressedBackend.cc:190
ChimeraTK::NumericAddressedBackend::_registerMap
NumericAddressedRegisterCatalogue & _registerMap
Definition: NumericAddressedBackend.h:153
ChimeraTK::NumericAddressedBackend
Base class for address-based device backends (e.g.
Definition: NumericAddressedBackend.h:20
ChimeraTK::NumericAddressedBackend::~NumericAddressedBackend
~NumericAddressedBackend() override=default
ChimeraTK::NumericAddressedBackend::canMergeRequests
virtual bool canMergeRequests() const
Determines whether the backend supports merging of requests (read or write)
Definition: NumericAddressedBackend.h:76
ChimeraTK::NumericAddressedBackend::minimumTransferAlignment
virtual size_t minimumTransferAlignment([[maybe_unused]] uint64_t bar) const
Determines the supported minimum alignment for any read/write requests.
Definition: NumericAddressedBackend.h:90
ChimeraTK::NumericAddressedBackend::getRegisterCatalogue
RegisterCatalogue getRegisterCatalogue() const override
Return the register catalogue with detailed information on all registers.
Definition: NumericAddressedBackend.cc:230
NumericAddressedRegisterCatalogue.h
ChimeraTK::async::DomainImpl
Definition: DomainImpl.h:15
ChimeraTK::NumericAddressedBackend::barIndexValid
virtual bool barIndexValid(uint64_t bar)
Function to be implemented by the backends.
Definition: NumericAddressedBackend.cc:95
ChimeraTK::NumericAddressedBackend::getRegisterInfo
NumericAddressedRegisterInfo getRegisterInfo(const RegisterPath &registerPathName)
getRegisterInfo returns a NumericAddressedRegisterInfo object for the given register.
Definition: NumericAddressedBackend.cc:31
ChimeraTK::NumericAddressedBackend::_registerMapPointer
std::unique_ptr< NumericAddressedRegisterCatalogue > _registerMapPointer
Definition: NumericAddressedBackend.h:152
ChimeraTK::NumericAddressedBackend::TriggeredPollDistributor
friend TriggeredPollDistributor
Definition: NumericAddressedBackend.h:162
ChimeraTK::NumericAddressedLowLevelTransferElement
Implementation of the NDRegisterAccessor for NumericAddressedBackends, responsible for the underlying...
Definition: NumericAddressedLowLevelTransferElement.h:30
ChimeraTK::DeviceBackendImpl
DeviceBackendImpl implements some basic functionality which should be available for all backends.
Definition: DeviceBackendImpl.h:25
ChimeraTK::NumericAddressedBackend::NumericAddressedBackend
NumericAddressedBackend(const std::string &mapFileName="", std::unique_ptr< NumericAddressedRegisterCatalogue > registerMapPointer=std::make_unique< NumericAddressedRegisterCatalogue >())
Definition: NumericAddressedBackend.cc:19
ChimeraTK::RegisterPath
Class to store a register path name.
Definition: RegisterPath.h:16
ChimeraTK::NumericAddressedRegisterCatalogue
Definition: NumericAddressedRegisterCatalogue.h:136
ChimeraTK::NumericAddressedBackend::getMetadataCatalogue
MetadataCatalogue getMetadataCatalogue() const override
Return the device metadata catalogue.
Definition: NumericAddressedBackend.cc:236
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
ChimeraTK::NumericAddressedBackend::setExceptionImpl
void setExceptionImpl() noexcept override
Turn off the internal variable which remembers that async is active.
Definition: NumericAddressedBackend.cc:242
ChimeraTK::AccessModeFlags
Set of AccessMode flags with additional functionality for an easier handling.
Definition: AccessMode.h:48
ChimeraTK::NumericAddressedBackend::activateSubscription
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...
Definition: NumericAddressedBackend.cc:211
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::NDRegisterAccessor
N-dimensional register accessor.
Definition: ForwardDeclarations.h:17
ChimeraTK::NumericAddressedBackendMuxedRegisterAccessor
Implementation of the NDRegisterAccessor for NumericAddressedBackends for multiplexd 2D registers.
Definition: NumericAddressedBackendMuxedRegisterAccessor.h:73