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
41
42#ifndef _DUNEDAQ_UHALLIBS_PROTOCOLFLX_V0_HPP_
43#define _DUNEDAQ_UHALLIBS_PROTOCOLFLX_V0_HPP_
44
45#include <deque> // for deque
46#include <istream> // for istream
47#include <stddef.h> // for size_t
48#include <stdint.h> // for uint32_t, uint8_t
49#include <string> // for string
50#include <utility> // for pair
51#include <vector> // for vector
52
53#include <chrono> // for steady_clock
54
55#include "uhal/ClientInterface.hpp"
56#include "uhal/ProtocolIPbus.hpp"
57#include "uhal/log/exception.hpp"
58
59#include "flxcard/FlxCard.h"
60
63
64namespace boost {
65template<class Y>
67}
68
69namespace uhal {
70struct URI;
71class Buffers;
72}
73
74namespace uhallibs {
75
76namespace exception {
79 uhal::exception::ClientTimeout,
80 "Exception class to handle the case in which the Felix device is invalid.")
83 uhal::exception::ClientTimeout,
84 "Exception class to handle the case in which the Felix connection timed out.")
87 FlxInitialisationError,
88 uhal::exception::TransportLayerError,
89 "Exception class to handle a failure to read from the specified device files during initialisation.")
91UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(FlxCommunicationError,
92 uhal::exception::TransportLayerError,
93 "Exception class to handle a low-level seek/read/write error after initialisation.")
94}
95
97class Flx : public uhal::IPbus<2, 0>
98{
99private:
100 class Card
101 {
102 public:
103 Card(const std::string& aPath, u_int aLockMask);
104 ~Card();
105
106 const std::string& getPath() const;
107
108 int getDeviceId() const;
109
110 void open();
111
112 void close();
113
114 void read(const uint32_t aAddr, const uint32_t aNrWords, std::vector<uint32_t>& aValues);
115
116 void write(const uint32_t aAddr, const std::vector<std::pair<const uint8_t*, size_t>>& aData);
117
118 bool haveLock() const;
119
120 void lock();
121
122 void unlock();
123
124 private:
125 static regmap_register_t* find_reg(const std::string& aName);
126
127 std::string mPath;
130
131 FlxCard mFlxCard;
133
134 int mFd;
136 };
137
138 template<typename T>
139 struct HexTo
140 {
142 operator T() const { return value; }
143 friend std::istream& operator>>(std::istream& in, HexTo& out)
144 {
145 in >> std::hex >> out.value;
146 return in;
147 }
148 };
149
150 Flx(const Flx& aFlx);
151
152 Flx& operator=(const Flx& aFlx);
153
154public:
160 Flx(const std::string& aId, const uhal::URI& aUri);
161
163 virtual ~Flx();
164
165private:
167 typedef std::unique_lock<IPCMutex_t> IPCScopedLock_t;
168
175 void implementDispatch(std::shared_ptr<uhal::Buffers> aBuffers);
176
179 virtual void Flush();
180
182 virtual void dispatchExceptionHandler();
183
184 static std::string getSharedMemName(const std::string& aPath);
185
186 typedef IPbus<2, 0> InnerProtocol;
187
188 typedef std::chrono::steady_clock SteadyClock_t;
189
194 uint32_t getMaxSendSize();
195
200 uint32_t getMaxReplySize();
201
203 void connect();
204
207
209 void disconnect();
210
212 void write(const std::shared_ptr<uhal::Buffers>& aBuffers);
213
215 void read();
216
218
220
224
225 std::chrono::microseconds mSleepDuration;
226
228
230 std::deque<std::shared_ptr<uhal::Buffers>> mReplyQueue;
231
236 uhal::exception::exception* mAsynchronousException;
237};
238
239}
240
241#endif /* _DUNEDAQ_UHALLIBS_PROTOCOLFLX_V0_HPP_ */
const std::string & getPath() const
Card(const std::string &aPath, u_int aLockMask)
void write(const uint32_t aAddr, const std::vector< std::pair< const uint8_t *, size_t > > &aData)
bool haveLock() const
int getDeviceId() const
static regmap_register_t * find_reg(const std::string &aName)
void read(const uint32_t aAddr, const uint32_t aNrWords, std::vector< uint32_t > &aValues)
virtual void dispatchExceptionHandler()
Function which tidies up this protocol layer in the event of an exception.
uint32_t getMaxReplySize()
static std::string getSharedMemName(const std::string &aPath)
uint32_t mPublishedReplyPageCount
void connect()
Set up the connection to the device.
void write(const std::shared_ptr< uhal::Buffers > &aBuffers)
Write request packet to next page in host-to-FPGA device file.
IPbus< 2, 0 > InnerProtocol
uint32_t mNumberOfPages
void implementDispatch(std::shared_ptr< uhal::Buffers > aBuffers)
uint32_t getMaxSendSize()
std::chrono::microseconds mSleepDuration
virtual void Flush()
Flx & operator=(const Flx &aFlx)
uint32_t mPageSize
Flx(const Flx &aFlx)
ipc::RobustMutex IPCMutex_t
bool mIPCExternalSessionActive
ipc::SharedMemObject< IPCMutex_t > mIPCMutex
uint32_t mReadReplyPageCount
void read()
Read next pending reply packet from appropriate page of FPGA-to-host device file, and validate conten...
void disconnect()
Close the connection to the device.
uhal::exception::exception * mAsynchronousException
uint32_t mIndexNextPage
std::chrono::steady_clock SteadyClock_t
uint64_t mIPCSessionCount
std::unique_lock< IPCMutex_t > IPCScopedLock_t
std::deque< std::shared_ptr< uhal::Buffers > > mReplyQueue
The list of buffers still awaiting a reply.
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)