ChimeraTK-DeviceAccess  03.18.00
PcieBackend.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 
6 
7 #include <boost/function.hpp>
8 
9 #include <cstdint>
10 #include <cstdlib>
11 
12 namespace ChimeraTK {
13 
18  private:
19  int _deviceID;
20  uint64_t _ioctlPhysicalSlot;
21  uint64_t _ioctlDriverVersion;
22  uint64_t _ioctlDMA;
23  std::string _deviceNodeName;
24 
27  boost::function<void(uint8_t bar, uint32_t address, int32_t* data, size_t size)> _readDMAFunction;
28 
30  // boost::function< void (uint8_t, uint32_t, int32_t const *) >
31  // _writeFunction;
32 
35  boost::function<void(uint8_t bar, uint32_t address, int32_t const* data, size_t sizeInBytes)> _writeFunction;
36 
37  boost::function<void(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInBytes)> _readFunction;
38 
39  void readDMAViaIoctl(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInBytes);
40  void readDMAViaStruct(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInBytes);
41 
42  std::string createErrorStringWithErrnoText(std::string const& startText);
43  void determineDriverAndConfigureIoctl();
44  void writeInternal(uint8_t bar, uint32_t address, int32_t const* data);
45  void writeWithStruct(uint8_t bar, uint32_t address, int32_t const* data, size_t sizeInBytes);
47  void directWrite(uint8_t bar, uint32_t address, int32_t const* data, size_t sizeInBytes);
48 
49  void readInternal(uint8_t bar, uint32_t address, int32_t* data);
50  void readWithStruct(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInBytes);
52  void directRead(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInBytes);
53 
54  size_t minimumTransferAlignment([[maybe_unused]] uint64_t bar) const override { return 4; }
55 
56  bool checkConnection() const;
57 
60  public:
61  explicit PcieBackend(std::string deviceNodeName, const std::string& mapFileName = "");
62  ~PcieBackend() override;
63 
64  void open() override;
65  void closeImpl() override;
66 
67  void read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInBytes) override;
68  void write(uint8_t bar, uint32_t address, int32_t const* data, size_t sizeInBytes) override;
69 
70  std::string readDeviceInfo() override;
71 
72  /*Host or parameters (at least for now) are just place holders as pcidevice
73  * does not use them*/
74  static boost::shared_ptr<DeviceBackend> createInstance(
75  std::string address, std::map<std::string, std::string> parameters);
76  };
77 
78 } // namespace ChimeraTK
ChimeraTK::PcieBackend::~PcieBackend
~PcieBackend() override
Definition: PcieBackend.cc:30
ChimeraTK::PcieBackend::PcieBackend
PcieBackend(std::string deviceNodeName, const std::string &mapFileName="")
constructor called through createInstance to create device object
Definition: PcieBackend.cc:26
ChimeraTK::PcieBackend::closeImpl
void closeImpl() override
All backends derrived from NumericAddressedBackend must implement closeImpl() instead of close.
Definition: PcieBackend.cc:113
ChimeraTK::PcieBackend
A class to provide the Pcie device functionality.
Definition: PcieBackend.h:17
ChimeraTK::PcieBackend::open
void open() override
Open the device.
Definition: PcieBackend.cc:34
NumericAddressedBackend.h
ChimeraTK::NumericAddressedBackend
Base class for address-based device backends (e.g.
Definition: NumericAddressedBackend.h:20
ChimeraTK::PcieBackend::createInstance
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
Definition: PcieBackend.cc:305
ChimeraTK::PcieBackend::read
void read(uint8_t bar, uint32_t address, int32_t *data, size_t sizeInBytes) override
Definition: PcieBackend.cc:196
ChimeraTK::PcieBackend::readDeviceInfo
std::string readDeviceInfo() override
Return a device information string containing hardware details like the firmware version number or th...
Definition: PcieBackend.cc:284
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::PcieBackend::write
void write(uint8_t bar, uint32_t address, int32_t const *data, size_t sizeInBytes) override
Definition: PcieBackend.cc:215