DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ProtocolFlx.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 _DUNEDAQ_UHALLIBS_PROTOCOLFLX_V0_HPP_
43#define _DUNEDAQ_UHALLIBS_PROTOCOLFLX_V0_HPP_
44
45
46#include <deque> // for deque
47#include <istream> // for istream
48#include <stddef.h> // for size_t
49#include <stdint.h> // for uint32_t, uint8_t
50#include <string> // for string
51#include <utility> // for pair
52#include <vector> // for vector
53
54#include <chrono> // for steady_clock
55
56#include "uhal/ClientInterface.hpp"
57#include "uhal/log/exception.hpp"
58#include "uhal/ProtocolIPbus.hpp"
59
60#include "flxcard/FlxCard.h"
61
64
65namespace boost
66{
67 template <class Y> class shared_ptr;
68}
69
70namespace uhal {
71 struct URI;
72 class Buffers;
73}
74
75namespace uhallibs
76{
77
78 namespace exception
79 {
82 FlxInvalidDevice,
83 uhal::exception::ClientTimeout,
84 "Exception class to handle the case in which the Felix device is invalid."
85 )
88 FlxTimeout,
89 uhal::exception::ClientTimeout,
90 "Exception class to handle the case in which the Felix connection timed out."
91 )
94 FlxInitialisationError ,
95 uhal::exception::TransportLayerError ,
96 "Exception class to handle a failure to read from the specified device files during initialisation."
97 )
100 FlxCommunicationError ,
101 uhal::exception::TransportLayerError ,
102 "Exception class to handle a low-level seek/read/write error after initialisation."
103 )
104 }
105
107 class Flx : public uhal::IPbus< 2 , 0 >
108 {
109 private:
110 class Card {
111 public:
112 Card(const std::string& aPath, u_int aLockMask);
113 ~Card();
114
115 const std::string& getPath() const;
116
117 int getDeviceId() const;
118
119 void open();
120
121 void close();
122
123 void read(const uint32_t aAddr, const uint32_t aNrWords, std::vector<uint32_t>& aValues);
124
125 void write(const uint32_t aAddr, const std::vector<std::pair<const uint8_t*, size_t> >& aData);
126
127 bool haveLock() const;
128
129 void lock();
130
131 void unlock();
132
133 private:
134
135 static regmap_register_t* find_reg( const std::string& aName );
136
137
138 std::string mPath;
141
142 FlxCard mFlxCard;
144
145 int mFd;
147
148
149 };
150
151 template <typename T>
152 struct HexTo {
154 operator T() const {return value;}
155 friend std::istream& operator>>(std::istream& in, HexTo& out)
156 {
157 in >> std::hex >> out.value;
158 return in;
159 }
160 };
161
162 Flx ( const Flx& aFlx );
163
164 Flx& operator= ( const Flx& aFlx );
165
166 public:
172 Flx ( const std::string& aId, const uhal::URI& aUri );
173
175 virtual ~Flx();
176
177 private:
179 typedef std::unique_lock<IPCMutex_t> IPCScopedLock_t;
180
186 void implementDispatch ( std::shared_ptr< uhal::Buffers > aBuffers );
187
189 virtual void Flush( );
190
191
193 virtual void dispatchExceptionHandler();
194
195 static std::string getSharedMemName(const std::string& aPath);
196
197 typedef IPbus< 2 , 0 > InnerProtocol;
198
199 typedef std::chrono::steady_clock SteadyClock_t;
200
205 uint32_t getMaxSendSize();
206
211 uint32_t getMaxReplySize();
212
214 void connect();
215
217 void connect( IPCScopedLock_t& );
218
220 void disconnect();
221
223 void write(const std::shared_ptr<uhal::Buffers>& aBuffers);
224
226 void read();
227
229
231
235
236
237 std::chrono::microseconds mSleepDuration;
238
239 uint32_t mNumberOfPages, mPageSize, mIndexNextPage, mPublishedReplyPageCount, mReadReplyPageCount;
240
242 std::deque < std::shared_ptr< uhal::Buffers > > mReplyQueue;
243
248 uhal::exception::exception* mAsynchronousException;
249 };
250
251
252}
253
254
255#endif /* _DUNEDAQ_UHALLIBS_PROTOCOLFLX_V0_HPP_ */
Transport protocol to transfer an IPbus buffer via device file, using mmap.
std::deque< std::shared_ptr< uhal::Buffers > > mReplyQueue
The list of buffers still awaiting a reply.
std::chrono::microseconds mSleepDuration
Flx(const Flx &aFlx)
bool mIPCExternalSessionActive
ipc::SharedMemObject< IPCMutex_t > mIPCMutex
std::chrono::steady_clock SteadyClock_t
std::unique_lock< IPCMutex_t > IPCScopedLock_t
uhal::exception::exception * mAsynchronousException
uint32_t mIndexNextPage
ipc::RobustMutex IPCMutex_t
IPbus< 2, 0 > InnerProtocol
uint64_t mIPCSessionCount
caught dunedaq::conffwk::Exception exception
Definition file.hpp:28
UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(Axi4LiteTimeout, uhal::exception::ClientTimeout, "Exception class to handle the case in " "which the Axi4Lite connection timed out.") UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(Axi4LiteInitialisationError
friend std::istream & operator>>(std::istream &in, HexTo &out)
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34