ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
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
11namespace 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
73
75
76 std::set<DeviceBackend::BackendID> getInvolvedBackendIDs() override;
77
78 protected:
80
81 enum class Type {
82 area, //< address space is visible as an area in the target device
83 threeRegisters, //< use three registers (address, data and status) in target
84 //< device. status must be 0 when idle
85 twoRegisters, //< same as three registers but without status
86 areaHandshake //< address space visible as an area in the target device, and wait on status 0
87 };
88
90 std::mutex mutex;
91
94
96 size_t timeout{10000};
97
99 std::string targetAlias;
100
103 boost::shared_ptr<ChimeraTK::DeviceBackend> targetDevice;
104
106 std::string targetArea;
107
110
112 size_t sleepTime{100};
113
116
120
123 void verifyRegisterAccessorSize(const NumericAddressedRegisterInfo& info, size_t& numberOfWords,
124 size_t wordOffsetInRegister, bool enforceAlignment);
125
126 template<typename UserType>
127 boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(
128 const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
130
132 template<typename UserType>
133 boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_area(
134 const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
135
137 template<typename UserType>
138 boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_synchronized(
139 const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister,
140 const AccessModeFlags& flags);
141
143 void obtainTargetBackend();
144
145 void setExceptionImpl() noexcept override;
146
147 void activateAsyncRead() noexcept override;
148
151
152 // helper for reducing code duplication among template specializations
153 boost::shared_ptr<SubdeviceRegisterAccessor> getRegisterAccessor_helper(const NumericAddressedRegisterInfo& info,
154 size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
155 };
156
157} // 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.
Catalogue of register information.
Class to store a register path name.
Backend for subdevices which are passed through some register or area of another device (subsequently...
std::string targetAddress
for type == threeRegisters or twoRegisters: the name of the target registers
size_t timeout
timeout (in milliseconds), used in threeRegisters to throw a runtime_error if status register stuck a...
std::mutex mutex
Mutex to deal with concurrent access to the device.
NumericAddressedRegisterCatalogue _registerMap
map from register names to addresses
size_t addressToDataDelay
for type == threeRegisters or twoRegisters: sleep time between address and data write
void open() override
Open the device.
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
void close() override
Close the device.
MetadataCatalogue getMetadataCatalogue() const override
Return the device metadata catalogue.
std::string targetAlias
the target device name
DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER(SubdeviceBackend, getRegisterAccessor_impl, 4)
void setExceptionImpl() noexcept override
Function to be (optionally) implemented by backends if additional actions are needed when switching t...
MetadataCatalogue _metadataCatalogue
void obtainTargetBackend()
obtain the target backend if not yet done
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_impl(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
std::string targetArea
for type == area: the name of the target register
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...
Type type
type of the subdeivce
boost::shared_ptr< SubdeviceRegisterAccessor > getRegisterAccessor_helper(const NumericAddressedRegisterInfo &info, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
size_t sleepTime
for type == threeRegisters or twoRegisters: sleep time of polling loop resp. between operations,...
boost::shared_ptr< ChimeraTK::DeviceBackend > targetDevice
The target device backend itself.
std::string readDeviceInfo() override
Return a device information string containing hardware details like the firmware version number or th...
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_area(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
getRegisterAccessor implemenation for area types
RegisterCatalogue getRegisterCatalogue() const override
Return the register catalogue with detailed information on all registers.
void activateAsyncRead() noexcept override
Activate asyncronous read for all transfer elements where AccessMode::wait_for_new_data is set.
std::set< DeviceBackend::BackendID > getInvolvedBackendIDs() override
Get the backend IDs of all involved backends.
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_synchronized(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, const AccessModeFlags &flags)
getRegisterAccessor implemenation for threeRegisters types