ChimeraTK-DeviceAccess  03.18.00
SubdeviceBackend.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 "DeviceBackendImpl.h"
7 
8 #include <mutex>
9 #include <string>
10 
11 namespace ChimeraTK {
12  class SubdeviceRegisterAccessor;
13 
58  public:
59  explicit SubdeviceBackend(std::map<std::string, std::string> parameters);
60 
61  void open() override;
62 
63  void close() override;
64 
65  std::string readDeviceInfo() override {
66  return "Subdevice";
67  }
68 
69  static boost::shared_ptr<DeviceBackend> createInstance(
70  std::string address, std::map<std::string, std::string> parameters);
71 
72  RegisterCatalogue getRegisterCatalogue() const override;
73 
74  MetadataCatalogue getMetadataCatalogue() const override;
75 
76  protected:
78 
79  enum class Type {
80  area, //< address space is visible as an area in the target device
81  threeRegisters, //< use three registers (address, data and status) in target
82  //< device. status must be 0 when idle
83  twoRegisters, //< same as three registers but without status
84  areaHandshake //< address space visible as an area in the target device, and wait on status 0
85  };
86 
88  std::mutex mutex;
89 
92 
94  size_t timeout{10000};
95 
97  std::string targetAlias;
98 
101  boost::shared_ptr<ChimeraTK::DeviceBackend> targetDevice;
102 
104  std::string targetArea;
105 
108 
110  size_t sleepTime{100};
111 
114 
118 
121  static void verifyRegisterAccessorSize(const NumericAddressedRegisterInfo& info, size_t& numberOfWords,
122  size_t wordOffsetInRegister, bool enforceAlignment);
123 
124  template<typename UserType>
125  boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(
126  const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
128 
130  template<typename UserType>
131  boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_area(
132  const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
133 
135  template<typename UserType>
136  boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_synchronized(
137  const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister,
138  const AccessModeFlags& flags);
139 
141  void obtainTargetBackend();
142 
143  void setExceptionImpl() noexcept override;
144 
145  void activateAsyncRead() noexcept override;
146 
149 
150  // helper for reducing code duplication among template specializations
151  boost::shared_ptr<SubdeviceRegisterAccessor> getRegisterAccessor_helper(const NumericAddressedRegisterInfo& info,
152  size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
153  };
154 
155 } // namespace ChimeraTK
ChimeraTK::SubdeviceBackend::timeout
size_t timeout
timeout (in milliseconds), used in threeRegisters to throw a runtime_error if status register stuck a...
Definition: SubdeviceBackend.h:94
ChimeraTK::SubdeviceBackend::Type::threeRegisters
@ threeRegisters
ChimeraTK::SubdeviceBackend::createInstance
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
Definition: SubdeviceBackend.cc:23
ChimeraTK::SubdeviceBackend::Type
Type
Definition: SubdeviceBackend.h:79
ChimeraTK::SubdeviceBackend
Backend for subdevices which are passed through some register or area of another device (subsequently...
Definition: SubdeviceBackend.h:57
ChimeraTK::SubdeviceBackend::setExceptionImpl
void setExceptionImpl() noexcept override
Function to be (optionally) implemented by backends if additional actions are needed when switching t...
Definition: SubdeviceBackend.cc:522
ChimeraTK::SubdeviceBackend::activateAsyncRead
void activateAsyncRead() noexcept override
Activate asyncronous read for all transfer elements where AccessMode::wait_for_new_data is set.
Definition: SubdeviceBackend.cc:529
ChimeraTK::SubdeviceBackend::targetAddress
std::string targetAddress
for type == threeRegisters or twoRegisters: the name of the target registers
Definition: SubdeviceBackend.h:107
ChimeraTK::NumericAddressedRegisterInfo
Definition: NumericAddressedRegisterCatalogue.h:15
ChimeraTK::SubdeviceBackend::targetAlias
std::string targetAlias
the target device name
Definition: SubdeviceBackend.h:97
ChimeraTK::SubdeviceBackend::close
void close() override
Close the device.
Definition: SubdeviceBackend.cc:189
ChimeraTK::MetadataCatalogue
Container for backend metadata.
Definition: MetadataCatalogue.h:17
ChimeraTK::SubdeviceBackend::targetControl
std::string targetControl
Definition: SubdeviceBackend.h:107
ChimeraTK::SubdeviceBackend::getMetadataCatalogue
MetadataCatalogue getMetadataCatalogue() const override
Return the device metadata catalogue.
Definition: SubdeviceBackend.cc:203
ChimeraTK::SubdeviceBackend::obtainTargetBackend
void obtainTargetBackend()
obtain the target backend if not yet done
Definition: SubdeviceBackend.cc:172
DeviceBackendImpl.h
ChimeraTK::SubdeviceBackend::needStatusParam
bool needStatusParam()
Definition: SubdeviceBackend.h:148
ChimeraTK::SubdeviceBackend::readDeviceInfo
std::string readDeviceInfo() override
Return a device information string containing hardware details like the firmware version number or th...
Definition: SubdeviceBackend.h:65
ChimeraTK::SubdeviceBackend::verifyRegisterAccessorSize
static void verifyRegisterAccessorSize(const NumericAddressedRegisterInfo &info, size_t &numberOfWords, size_t wordOffsetInRegister, bool enforceAlignment)
Check consistency of the passed sizes and offsets against the information in the map file Will adjust...
Definition: SubdeviceBackend.cc:330
ChimeraTK::SubdeviceBackend::_registerMap
NumericAddressedRegisterCatalogue _registerMap
map from register names to addresses
Definition: SubdeviceBackend.h:116
ChimeraTK::RegisterCatalogue
Catalogue of register information.
Definition: RegisterCatalogue.h:20
ChimeraTK::SubdeviceBackend::_metadataCatalogue
MetadataCatalogue _metadataCatalogue
Definition: SubdeviceBackend.h:117
ChimeraTK::SubdeviceBackend::getRegisterAccessor_area
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_area(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
getRegisterAccessor implemenation for area types
Definition: SubdeviceBackend.cc:375
ChimeraTK::SubdeviceBackend::targetData
std::string targetData
Definition: SubdeviceBackend.h:107
ChimeraTK::SubdeviceBackend::getRegisterAccessor_synchronized
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_synchronized(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, const AccessModeFlags &flags)
getRegisterAccessor implemenation for threeRegisters types
Definition: SubdeviceBackend.cc:448
ChimeraTK::SubdeviceBackend::getRegisterCatalogue
RegisterCatalogue getRegisterCatalogue() const override
Return the register catalogue with detailed information on all registers.
Definition: SubdeviceBackend.cc:197
ChimeraTK::SubdeviceBackend::sleepTime
size_t sleepTime
for type == threeRegisters or twoRegisters: sleep time of polling loop resp. between operations,...
Definition: SubdeviceBackend.h:110
NumericAddressedRegisterCatalogue.h
ChimeraTK::SubdeviceBackend::type
Type type
type of the subdeivce
Definition: SubdeviceBackend.h:91
ChimeraTK::SubdeviceBackend::Type::area
@ area
ChimeraTK::DeviceBackendImpl
DeviceBackendImpl implements some basic functionality which should be available for all backends.
Definition: DeviceBackendImpl.h:25
ChimeraTK::SubdeviceBackend::DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER
DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER(SubdeviceBackend, getRegisterAccessor_impl, 4)
ChimeraTK::SubdeviceBackend::getRegisterAccessor_helper
boost::shared_ptr< SubdeviceRegisterAccessor > getRegisterAccessor_helper(const NumericAddressedRegisterInfo &info, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
Definition: SubdeviceBackend.cc:405
ChimeraTK::RegisterPath
Class to store a register path name.
Definition: RegisterPath.h:16
ChimeraTK::SubdeviceBackend::Type::twoRegisters
@ twoRegisters
ChimeraTK::SubdeviceBackend::SubdeviceBackend
SubdeviceBackend(std::map< std::string, std::string > parameters)
Definition: SubdeviceBackend.cc:52
ChimeraTK::SubdeviceBackend::mutex
std::mutex mutex
Mutex to deal with concurrent access to the device.
Definition: SubdeviceBackend.h:88
ChimeraTK::NumericAddressedRegisterCatalogue
Definition: NumericAddressedRegisterCatalogue.h:136
ChimeraTK::SubdeviceBackend::Type::areaHandshake
@ areaHandshake
ChimeraTK::SubdeviceBackend::needAreaParam
bool needAreaParam()
Definition: SubdeviceBackend.h:147
ChimeraTK::AccessModeFlags
Set of AccessMode flags with additional functionality for an easier handling.
Definition: AccessMode.h:48
ChimeraTK::SubdeviceBackend::getRegisterAccessor_impl
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_impl(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
Definition: SubdeviceBackend.cc:309
ChimeraTK::SubdeviceBackend::targetDevice
boost::shared_ptr< ChimeraTK::DeviceBackend > targetDevice
The target device backend itself.
Definition: SubdeviceBackend.h:101
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::SubdeviceBackend::open
void open() override
Open the device.
Definition: SubdeviceBackend.cc:180
ChimeraTK::SubdeviceBackend::targetArea
std::string targetArea
for type == area: the name of the target register
Definition: SubdeviceBackend.h:104
ChimeraTK::SubdeviceRegisterAccessor
Definition: SubdeviceRegisterAccessor.h:14
ChimeraTK::SubdeviceBackend::addressToDataDelay
size_t addressToDataDelay
for type == threeRegisters or twoRegisters: sleep time between address and data write
Definition: SubdeviceBackend.h:113