ChimeraTK-DeviceAccess  03.18.00
UioAccess.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 <boost/filesystem.hpp>
6 
7 #include <atomic>
8 #include <memory>
9 #include <string>
10 
11 namespace ChimeraTK {
13  class UioAccess {
14  private:
15  boost::filesystem::path _deviceFilePath;
16  int _deviceFileDescriptor = 0;
17  void* _deviceUserBase = nullptr;
18  void* _deviceKernelBase = nullptr;
19  size_t _deviceMemSize = 0;
20  uint32_t _lastInterruptCount = 0;
21  std::atomic<bool> _opened{false};
22 
24  void UioMMap();
25 
27  void UioUnmap();
28 
33  uint32_t subtractUint32OverflowSafe(uint32_t minuend, uint32_t subtrahend);
34 
38  uint32_t readUint32FromFile(std::string fileName);
39 
43  uint64_t readUint64HexFromFile(std::string fileName);
44 
45  public:
46  explicit UioAccess(const std::string& deviceFilePath);
47  ~UioAccess();
48 
50  void open();
51 
53  void close();
54 
60  void read(uint64_t map, uint64_t address, int32_t* data, size_t sizeInBytes);
61 
67  void write(uint64_t map, uint64_t address, int32_t const* data, size_t sizeInBytes);
68 
72  uint32_t waitForInterrupt(int timeoutMs);
73 
75  void clearInterrupts();
76 
79  std::string getDeviceFilePath();
80  };
81 } // namespace ChimeraTK
ChimeraTK::UioAccess::open
void open()
Opens UIO device for read and write operations and interrupt handling.
Definition: UioAccess.cc:23
ChimeraTK::UioAccess::UioAccess
UioAccess(const std::string &deviceFilePath)
Definition: UioAccess.cc:17
ChimeraTK::UioAccess::read
void read(uint64_t map, uint64_t address, int32_t *data, size_t sizeInBytes)
Read data from the specified memory offset address.
Definition: UioAccess.cc:49
ChimeraTK::UioAccess::write
void write(uint64_t map, uint64_t address, int32_t const *data, size_t sizeInBytes)
Write data to the specified memory offset address.
Definition: UioAccess.cc:68
ChimeraTK::UioAccess::close
void close()
Closes UIO device.
Definition: UioAccess.cc:41
ChimeraTK::UioAccess::getDeviceFilePath
std::string getDeviceFilePath()
Return UIO device file path.
Definition: UioAccess.cc:130
ChimeraTK::UioAccess::waitForInterrupt
uint32_t waitForInterrupt(int timeoutMs)
Wait for hardware interrupt to occur within specified timeout period.
Definition: UioAccess.cc:87
ChimeraTK::UioAccess::~UioAccess
~UioAccess()
Definition: UioAccess.cc:19
ChimeraTK::UioAccess
Implements a generic userspace interface for UIO devices.
Definition: UioAccess.h:13
ChimeraTK::UioAccess::clearInterrupts
void clearInterrupts()
Clear all pending interrupts.
Definition: UioAccess.cc:121
ChimeraTK
Definition: DummyBackend.h:16