μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ProtocolPCIe.hpp
Go to the documentation of this file.
1/*
2---------------------------------------------------------------------------
3
4 This file is part of uHAL.
5
6 uHAL is a hardware access library and programming framework
7 originally developed for upgrades of the Level-1 trigger of the CMS
8 experiment at CERN.
9
10 uHAL is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 uHAL is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22
23
24 Andrew Rose, Imperial College, London
25 email: awr01 <AT> imperial.ac.uk
26
27 Marc Magrans de Abril, CERN
28 email: marc.magrans.de.abril <AT> cern.ch
29
30 Tom Williams, Rutherford Appleton Laboratory, Oxfordshire
31 email: tom.williams <AT> cern.ch
32
33---------------------------------------------------------------------------
34*/
35
42#ifndef _uhal_ProtocolPCIe_hpp_
43#define _uhal_ProtocolPCIe_hpp_
44
45
46#include <chrono>
47#include <deque> // for deque
48#include <memory>
49#include <mutex>
50#include <stddef.h> // for size_t
51#include <stdint.h> // for uint32_t, uint8_t
52#include <string> // for string
53#include <utility> // for pair
54#include <vector> // for vector
55
61
62
63namespace uhal
64{
65 class Buffers;
66 struct URI;
67
68 namespace exception
69 {
71 UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( PCIeTimeout , ClientTimeout , "Exception class to handle the case in which the PCIe connection timed out." )
73 UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( PCIeInitialisationError , TransportLayerError , "Exception class to handle a failure to read from the specified device files during initialisation." )
75 UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( PCIeCommunicationError , TransportLayerError , "Exception class to handle a low-level seek/read/write error after initialisation." )
76 }
77
79 class PCIe : public IPbus< 2 , 0 >
80 {
81 public:
82 class File {
83 public:
84 File(const std::string& aPath, int aFlags);
85 ~File();
86
87 const std::string& getPath() const;
88 void setPath(const std::string& aPath);
89
90 void open();
91 void close();
92
93 void createBuffer(const size_t aNrBytes);
94
95 void read(const uint32_t aAddr, const uint32_t aNrWords, std::vector<uint32_t>& aValues);
96
97 void write(const uint32_t aAddr, const std::vector<uint32_t>& aValues);
98
99 void write(const uint32_t aAddr, const uint8_t* const aPtr, const size_t aNrBytes);
100
101 void write(const uint32_t aAddr, const std::vector<std::pair<const uint8_t*, size_t> >& aData);
102
103 bool haveLock() const;
104
105 void lock();
106
107 void unlock();
108
109 private:
110 std::string mPath;
111 int mFd;
115 char* mBuffer;
116 };
117
118 private:
119
120 static std::string getSharedMemName(const std::string& );
121
122 public:
128 PCIe ( const std::string& aId, const URI& aUri );
129
131 virtual ~PCIe();
132
133 private:
134
135 PCIe ( const PCIe& aPCIe );
136
137 PCIe& operator= ( const PCIe& aPCIe );
138
144 void implementDispatch ( std::shared_ptr< Buffers > aBuffers );
145
147 virtual void Flush();
148
150 virtual void dispatchExceptionHandler();
151
153
154 typedef std::chrono::steady_clock SteadyClock_t;
155
160 uint32_t getMaxSendSize();
161
166 uint32_t getMaxReplySize();
167
169 void connect();
170
172 void connect(detail::ScopedSessionLock& );
173
175 void disconnect();
176
178 void write(const std::shared_ptr<Buffers>& aBuffers);
179
181 void read();
182
184
191
195
197
199
200 std::chrono::microseconds mSleepDuration;
201
202 uint32_t mNumberOfPages, mMaxInFlight, mPageSize, mMaxPacketSize, mIndexNextPage, mPublishedReplyPageCount, mReadReplyPageCount;
203
205 std::deque < std::shared_ptr< Buffers > > mReplyQueue;
206 };
207
208}
209
210
211#endif
Wrapper to generate a new Python exception type.
Definition: pybind11.h:2517
\rst Holds a reference to a Python object (no reference counting)
Definition: pytypes.h:194
A class which provides the version-specific functionality for IPbus.
std::string mPath
Transport protocol to transfer an IPbus buffer via PCIe.
std::chrono::steady_clock SteadyClock_t
uint32_t mIndexNextPage
File mDeviceFileFPGAToHost
FPGA-to-host device file.
uint64_t mIPCSessionCount
std::deque< std::shared_ptr< Buffers > > mReplyQueue
The list of buffers still awaiting a reply.
std::chrono::microseconds mSleepDuration
bool mXdma7seriesWorkaround
bool mUseInterrupt
bool mIPCExternalSessionActive
IPbus< 2, 0 > InnerProtocol
File mDeviceFileFPGAEvent
FPGA-to-host interrupt (event) file.
detail::SharedObject< detail::RobustSessionMutex > mIPCMutex
PCIe(const PCIe &aPCIe)
File mDeviceFileHostToFPGA
Host-to-FPGA device file.
Wrapper for C++ object that's placed in shared memory.
#define UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(ClassName, BaseClassName, ClassDescription)
Macro for simplifying the declaration and definition of derived exception types.
Definition: exception.hpp:49
std::unique_lock< RobustSessionMutex > ScopedSessionLock
Struct to store a URI when parsed by boost spirit.
Definition: URI.hpp:50