μHAL (v2.6.5)
Part of the IPbus software repository
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 #include <deque> // for deque
46 #include <stddef.h> // for size_t
47 #include <stdint.h> // for uint32_t, uint8_t
48 #include <string> // for string
49 #include <utility> // for pair
50 #include <vector> // for vector
51 
52 #include <boost/chrono/system_clocks.hpp> // for steady_clock
53 #include <boost/function.hpp> // for function
54 
55 #include "uhal/ClientInterface.hpp"
56 #include "uhal/log/exception.hpp"
57 #include "uhal/ProtocolIPbus.hpp"
58 
59 
60 namespace boost
61 {
62  template <class Y> class shared_ptr;
63 }
64 
65 namespace uhal
66 {
67  class Buffers;
68  struct URI;
69 
70  namespace exception
71  {
73  UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( MmapTimeout , ClientTimeout , "Exception class to handle the case in which the PCIe connection timed out." )
75  UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( MmapInitialisationError , TransportLayerError , "Exception class to handle a failure to read from the specified device files during initialisation." )
77  UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( MmapCommunicationError , TransportLayerError , "Exception class to handle a low-level seek/read/write error after initialisation." )
78  }
79 
81  class Mmap : public IPbus< 2 , 0 >
82  {
83  public:
84  class PacketFmt {
85  public:
86  PacketFmt(const uint8_t* const, const size_t);
87  PacketFmt(const std::vector< std::pair<const uint8_t*, size_t> >& aData);
88  ~PacketFmt();
89 
90  const std::vector< std::pair<const uint8_t*, size_t> > mData;
91  };
92 
93  private:
94  class File {
95  public:
96  File(const std::string& aPath, int aFlags);
97  ~File();
98 
99  const std::string& getPath() const;
100  void setPath(const std::string& aPath);
101 
102  void open();
103  void close();
104 
105  void read(const uint32_t aAddr, const uint32_t aNrWords, std::vector<uint32_t>& aValues);
106 
107  void write(const uint32_t aAddr, const std::vector<std::pair<const uint8_t*, size_t> >& aData);
108 
109  private:
110  std::string mPath;
111  int mFd;
112  int mFlags;
114  };
115 
116  Mmap ( const Mmap& aMmap );
117 
118  Mmap& operator= ( const Mmap& aMmap );
119 
120  public:
126  Mmap ( const std::string& aId, const URI& aUri );
127 
129  virtual ~Mmap();
130 
131  private:
132 
138  void implementDispatch ( boost::shared_ptr< Buffers > aBuffers );
139 
143  virtual void Flush( );
144 
145 
147  virtual void dispatchExceptionHandler();
148 
149 
151 
152  typedef boost::chrono::steady_clock SteadyClock_t;
153 
158  uint32_t getMaxSendSize();
159 
164  uint32_t getMaxReplySize();
165 
167  void connect();
168 
170  void disconnect();
171 
173  void write(const boost::shared_ptr<Buffers>& aBuffers);
174 
176  void read();
177 
179 
181 
182  boost::chrono::microseconds mSleepDuration;
183 
184  uint32_t mNumberOfPages, mPageSize, mIndexNextPage, mPublishedReplyPageCount, mReadReplyPageCount;
185 
187  std::deque < boost::shared_ptr< Buffers > > mReplyQueue;
188 
194  };
195 
196 
197 }
198 
199 
200 #endif
A class which provides the version-specific functionality for IPbus.
Transport protocol to transfer an IPbus buffer via device file, using mmap.
IPbus< 2, 0 > InnerProtocol
#define UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(ClassName, BaseClassName, ClassDescription)
Macro for simplifying the declaration and definition of derived exception types.
Definition: exception.hpp:54
An abstract base exception class providing an interface to a throw/ThrowAsDerivedType mechanism which...
Definition: exception.hpp:89
std::deque< boost::shared_ptr< Buffers > > mReplyQueue
The list of buffers still awaiting a reply.
boost::chrono::steady_clock SteadyClock_t
uhal::exception::exception * mAsynchronousException
A pointer to an exception object for passing exceptions from the worker thread to the main thread...
boost::chrono::microseconds mSleepDuration
const std::vector< std::pair< const uint8_t *, size_t > > mData
std::string mPath
uint32_t mReadReplyPageCount
c write(addr, xx[0])
Struct to store a URI when parsed by boost spirit.
Definition: URI.hpp:49