μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ProtocolMmap.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_ProtocolMmap_hpp_
43#define _uhal_ProtocolMmap_hpp_
44
45
46#include <chrono>
47#include <deque> // for deque
48#include <istream> // for istream
49#include <memory>
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
63
64namespace uhal
65{
66 class Buffers;
67 struct URI;
68
69 namespace exception
70 {
72 UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( MmapTimeout , ClientTimeout , "Exception class to handle the case in which the PCIe connection timed out." )
74 UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( MmapInitialisationError , TransportLayerError , "Exception class to handle a failure to read from the specified device files during initialisation." )
76 UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( MmapCommunicationError , TransportLayerError , "Exception class to handle a low-level seek/read/write error after initialisation." )
77 }
78
80 class Mmap : public IPbus< 2 , 0 >
81 {
82 private:
83 class File {
84 public:
85 File(const std::string& aPath, int aFlags);
86 ~File();
87
88 const std::string& getPath() const;
89 void setPath(const std::string& aPath);
90
91 void setOffset(size_t aOffset);
92
93 void open();
94 void close();
95
96 void read(const uint32_t aAddr, const uint32_t aNrWords, std::vector<uint32_t>& aValues);
97
98 void write(const uint32_t aAddr, const std::vector<std::pair<const uint8_t*, size_t> >& aData);
99
100 bool haveLock() const;
101
102 void lock();
103
104 void unlock();
105
106 private:
107 std::string mPath;
108 int mFd;
111 off_t mOffset;
112 void* mMmapPtr;
114 };
115
116 template <typename T>
117 struct HexTo {
119 operator T() const {return value;}
120 friend std::istream& operator>>(std::istream& in, HexTo& out)
121 {
122 in >> std::hex >> out.value;
123 return in;
124 }
125 };
126
127 Mmap ( const Mmap& aMmap );
128
129 Mmap& operator= ( const Mmap& aMmap );
130
131 static std::string getSharedMemName(const std::string& );
132
133 public:
139 Mmap ( const std::string& aId, const URI& aUri );
140
142 virtual ~Mmap();
143
144 private:
145
151 void implementDispatch ( std::shared_ptr< Buffers > aBuffers );
152
154 virtual void Flush();
155
157 virtual void dispatchExceptionHandler();
158
160
161 typedef std::chrono::steady_clock SteadyClock_t;
162
167 uint32_t getMaxSendSize();
168
173 uint32_t getMaxReplySize();
174
176 void connect();
177
179 void connect(detail::ScopedSessionLock& );
180
182 void disconnect();
183
185 void write(const std::shared_ptr<Buffers>& aBuffers);
186
188 void read();
189
191
193
197
198 std::chrono::microseconds mSleepDuration;
199
200 uint32_t mNumberOfPages, mMaxInFlight, mPageSize, mMaxPacketSize, mIndexNextPage, mPublishedReplyPageCount, mReadReplyPageCount;
201
203 std::deque < std::shared_ptr< Buffers > > mReplyQueue;
204 };
205
206
207}
208
209
210#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 device file, using mmap.
std::chrono::microseconds mSleepDuration
uint32_t mIndexNextPage
std::deque< std::shared_ptr< Buffers > > mReplyQueue
The list of buffers still awaiting a reply.
uint64_t mIPCSessionCount
bool mIPCExternalSessionActive
IPbus< 2, 0 > InnerProtocol
std::chrono::steady_clock SteadyClock_t
Mmap(const Mmap &aMmap)
detail::SharedObject< detail::RobustSessionMutex > mIPCMutex
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
friend std::istream & operator>>(std::istream &in, HexTo &out)
Struct to store a URI when parsed by boost spirit.
Definition: URI.hpp:50