ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
DummyBackend.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 "DummyBackendBase.h"
6#include "Exception.h"
7
8#include <boost/function.hpp>
9
10#include <list>
11#include <map>
12#include <mutex>
13#include <set>
14#include <vector>
15
16namespace ChimeraTK {
17
18 // forward declarations
19 template<typename T>
21
22 template<typename T>
24
26
46 public:
47 explicit DummyBackend(const std::string& mapFileName, const std::string& dataConsistencyKeyDescriptor = "");
48 ~DummyBackend() override = default;
49
50 void open() override;
51
58 void closeImpl() override;
59
60 using DummyBackendBase::read; // use the 32 bit version from the base class
61 using DummyBackendBase::write; // use the 32 bit version from the base class
62 void read(uint64_t bar, uint64_t address, int32_t* data, size_t sizeInBytes) override;
63 void write(uint64_t bar, uint64_t address, int32_t const* data, size_t sizeInBytes) override;
64
65 std::string readDeviceInfo() override;
66
67 static boost::shared_ptr<DeviceBackend> createInstance(
68 std::string address, std::map<std::string, std::string> parameters);
69
77 DummyRegisterRawAccessor getRawAccessor(const std::string& module, const std::string& register_name);
78
79 VersionNumber triggerInterrupt(uint32_t interruptNumber) override;
80
81 protected:
82 struct AddressRange {
83 const uint64_t offset;
84 const uint32_t sizeInBytes;
85 const uint64_t bar;
86
87 AddressRange(uint64_t bar_, uint64_t address, size_t sizeInBytes_)
88 : offset(address), sizeInBytes(sizeInBytes_), bar(bar_) {}
89
91 : offset(info.address), sizeInBytes(info.nElements * info.elementPitchBits / 8), bar(info.bar) {
92 assert(info.elementPitchBits % 8 == 0);
93 }
94
95 bool operator<(AddressRange const& right) const {
96 return (bar == right.bar ? (offset < right.offset) : bar < right.bar);
97 }
98 };
99
101 std::string _mapFile;
102
103 std::map<uint64_t, std::vector<int32_t>> _barContents;
104 std::set<std::pair<uint64_t, uint64_t>> _readOnlyAddresses; // bar/address combinations which are read only
105 std::multimap<AddressRange, boost::function<void(void)>> _writeCallbackFunctions;
106 std::mutex mutex;
107
108 void resizeBarContents();
109
111 std::list<boost::function<void(void)>> findCallbackFunctionsForAddressRange(AddressRange addressRange);
112
113 void setReadOnly(uint64_t bar, uint64_t address, size_t sizeInWords);
114 void setReadOnly(AddressRange addressRange);
115 bool isReadOnly(uint64_t bar, uint64_t address) const;
116 void setWriteCallbackFunction(AddressRange addressRange, boost::function<void(void)> const& writeCallbackFunction);
119 bool isWriteRangeOverlap(AddressRange firstRange, AddressRange secondRange);
120
124 void writeRegisterWithoutCallback(uint64_t bar, uint64_t address, int32_t data);
125
127 template<typename T>
129
130 template<typename T>
132
134 friend class SharedDummyBackend;
135
136 static std::string convertPathRelativeToDmapToAbs(std::string const& mapfileName);
137 };
138
139} // namespace ChimeraTK
Base class for DummyBackends, provides common functionality.
void write(uint8_t bar, uint32_t address, int32_t const *data, size_t sizeInBytes) final
You cannot override the write version with 32 bit address any more.
void read(uint8_t bar, uint32_t address, int32_t *data, size_t sizeInBytes) final
You cannot override the read version with 32 bit address any more.
The dummy device opens a mapping file instead of a device, and implements all registers defined in th...
std::string readDeviceInfo() override
Return a device information string containing hardware details like the firmware version number or th...
DummyRegisterRawAccessor getRawAccessor(const std::string &module, const std::string &register_name)
Get a raw accessor to the underlying memory with the convenience of using register names.
std::set< std::pair< uint64_t, uint64_t > > _readOnlyAddresses
void setWriteCallbackFunction(AddressRange addressRange, boost::function< void(void)> const &writeCallbackFunction)
std::multimap< AddressRange, boost::function< void(void)> > _writeCallbackFunctions
void open() override
Open the device.
std::map< uint64_t, std::vector< int32_t > > _barContents
~DummyBackend() override=default
static std::string convertPathRelativeToDmapToAbs(std::string const &mapfileName)
void closeImpl() override
This closes the device, clears all internal registers, read-only settings and callback functions.
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
std::list< boost::function< void(void)> > findCallbackFunctionsForAddressRange(AddressRange addressRange)
std::string _mapFile
name of the map file
bool isWriteRangeOverlap(AddressRange firstRange, AddressRange secondRange)
returns true if the ranges overlap and at least one of the overlapping registers can be written
void writeRegisterWithoutCallback(uint64_t bar, uint64_t address, int32_t data)
Not write-protected function for internal use only.
bool isReadOnly(uint64_t bar, uint64_t address) const
void setReadOnly(uint64_t bar, uint64_t address, size_t sizeInWords)
VersionNumber triggerInterrupt(uint32_t interruptNumber) override
Simulate the arrival of an interrupt.
void runWriteCallbackFunctionsForAddressRange(AddressRange addressRange)
Register accessor for accessing multiplexed 2D array registers internally of a DummyBackend implement...
Register accessor for accessing single word or 1D array registers internally of a DummyBackend implem...
Accessor for raw 32 bit integer access to the underlying memory space.
uint32_t elementPitchBits
Distance in bits (!) between two elements (of the same channel)
The shared dummy device opens a mapping file defining the registers and implements them in shared mem...
Class for generating and holding version numbers without exposing a numeric representation.
AddressRange(uint64_t bar_, uint64_t address, size_t sizeInBytes_)
bool operator<(AddressRange const &right) const
AddressRange(const NumericAddressedRegisterInfo &info)