DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
uhallibs
include
uhallibs
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
61
#include "
uhallibs/ipc/RobustMutex.hpp
"
62
#include "
uhallibs/ipc/SharedMemObject.hpp
"
63
64
namespace
boost
{
65
template
<
class
Y>
66
class
shared_ptr
;
67
}
68
69
namespace
uhal
{
70
struct
URI;
71
class
Buffers;
72
}
73
74
namespace
uhallibs
{
75
76
namespace
exception {
78
UHAL_DEFINE_DERIVED_EXCEPTION_CLASS
(FlxInvalidDevice,
79
uhal::exception::ClientTimeout,
80
"Exception class to handle the case in which the Felix device is invalid."
)
82
UHAL_DEFINE_DERIVED_EXCEPTION_CLASS
(FlxTimeout,
83
uhal
::
exception
::ClientTimeout,
84
"Exception class to handle the case in which the Felix connection timed out."
)
86
UHAL_DEFINE_DERIVED_EXCEPTION_CLASS
(
87
FlxInitialisationError,
88
uhal
::
exception
::TransportLayerError,
89
"Exception class to handle a failure to read from the specified device files during initialisation."
)
91
UHAL_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
97
class
Flx
: public
uhal
::IPbus<2, 0>
98
{
99
private
:
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
;
128
int
mDeviceId
;
129
u_int
mLockMask
;
130
131
FlxCard
mFlxCard
;
132
bool
mIsOpen
;
133
134
int
mFd
;
135
bool
mLocked
;
136
};
137
138
template
<
typename
T>
139
struct
HexTo
140
{
141
T
value
;
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
154
public
:
160
Flx
(
const
std::string& aId,
const
uhal::URI& aUri);
161
163
virtual
~Flx
();
164
165
private
:
166
typedef
ipc::RobustMutex
IPCMutex_t
;
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
206
void
connect
(
IPCScopedLock_t
&);
207
209
void
disconnect
();
210
212
void
write
(
const
std::shared_ptr<uhal::Buffers>& aBuffers);
213
215
void
read
();
216
217
bool
mConnected
;
218
219
Card
mDeviceFile
;
220
221
ipc::SharedMemObject<IPCMutex_t>
mIPCMutex
;
222
bool
mIPCExternalSessionActive
;
223
uint64_t
mIPCSessionCount
;
224
225
std::chrono::microseconds
mSleepDuration
;
226
227
uint32_t
mNumberOfPages
,
mPageSize
,
mIndexNextPage
,
mPublishedReplyPageCount
,
mReadReplyPageCount
;
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_ */
RobustMutex.hpp
SharedMemObject.hpp
boost::shared_ptr
Definition
ProtocolFlx.hpp:66
uhallibs::Flx::Card
Definition
ProtocolFlx.hpp:101
uhallibs::Flx::Card::mPath
std::string mPath
Definition
ProtocolFlx.hpp:127
uhallibs::Flx::Card::mDeviceId
int mDeviceId
Definition
ProtocolFlx.hpp:128
uhallibs::Flx::Card::mLockMask
u_int mLockMask
Definition
ProtocolFlx.hpp:129
uhallibs::Flx::Card::close
void close()
Definition
ProtocolFlx.cpp:154
uhallibs::Flx::Card::getPath
const std::string & getPath() const
Definition
ProtocolFlx.cpp:178
uhallibs::Flx::Card::Card
Card(const std::string &aPath, u_int aLockMask)
Definition
ProtocolFlx.cpp:93
uhallibs::Flx::Card::write
void write(const uint32_t aAddr, const std::vector< std::pair< const uint8_t *, size_t > > &aData)
Definition
ProtocolFlx.cpp:220
uhallibs::Flx::Card::lock
void lock()
Definition
ProtocolFlx.cpp:277
uhallibs::Flx::Card::mFd
int mFd
Definition
ProtocolFlx.hpp:134
uhallibs::Flx::Card::open
void open()
Definition
ProtocolFlx.cpp:124
uhallibs::Flx::Card::mLocked
bool mLocked
Definition
ProtocolFlx.hpp:135
uhallibs::Flx::Card::haveLock
bool haveLock() const
Definition
ProtocolFlx.cpp:271
uhallibs::Flx::Card::mIsOpen
bool mIsOpen
Definition
ProtocolFlx.hpp:132
uhallibs::Flx::Card::getDeviceId
int getDeviceId() const
Definition
ProtocolFlx.cpp:185
uhallibs::Flx::Card::find_reg
static regmap_register_t * find_reg(const std::string &aName)
Definition
ProtocolFlx.cpp:79
uhallibs::Flx::Card::unlock
void unlock()
Definition
ProtocolFlx.cpp:294
uhallibs::Flx::Card::read
void read(const uint32_t aAddr, const uint32_t aNrWords, std::vector< uint32_t > &aValues)
Definition
ProtocolFlx.cpp:192
uhallibs::Flx::Card::mFlxCard
FlxCard mFlxCard
Definition
ProtocolFlx.hpp:131
uhallibs::Flx::dispatchExceptionHandler
virtual void dispatchExceptionHandler()
Function which tidies up this protocol layer in the event of an exception.
Definition
ProtocolFlx.cpp:388
uhallibs::Flx::getMaxReplySize
uint32_t getMaxReplySize()
Definition
ProtocolFlx.cpp:413
uhallibs::Flx::getSharedMemName
static std::string getSharedMemName(const std::string &aPath)
Definition
ProtocolFlx.cpp:310
uhallibs::Flx::mPublishedReplyPageCount
uint32_t mPublishedReplyPageCount
Definition
ProtocolFlx.hpp:227
uhallibs::Flx::connect
void connect()
Set up the connection to the device.
Definition
ProtocolFlx.cpp:422
uhallibs::Flx::write
void write(const std::shared_ptr< uhal::Buffers > &aBuffers)
Write request packet to next page in host-to-FPGA device file.
Definition
ProtocolFlx.cpp:503
uhallibs::Flx::InnerProtocol
IPbus< 2, 0 > InnerProtocol
Definition
ProtocolFlx.hpp:186
uhallibs::Flx::mNumberOfPages
uint32_t mNumberOfPages
Definition
ProtocolFlx.hpp:227
uhallibs::Flx::implementDispatch
void implementDispatch(std::shared_ptr< uhal::Buffers > aBuffers)
Definition
ProtocolFlx.cpp:362
uhallibs::Flx::getMaxSendSize
uint32_t getMaxSendSize()
Definition
ProtocolFlx.cpp:404
uhallibs::Flx::mSleepDuration
std::chrono::microseconds mSleepDuration
Definition
ProtocolFlx.hpp:225
uhallibs::Flx::Flush
virtual void Flush()
Definition
ProtocolFlx.cpp:375
uhallibs::Flx::operator=
Flx & operator=(const Flx &aFlx)
uhallibs::Flx::mConnected
bool mConnected
Definition
ProtocolFlx.hpp:217
uhallibs::Flx::mPageSize
uint32_t mPageSize
Definition
ProtocolFlx.hpp:227
uhallibs::Flx::Flx
Flx(const Flx &aFlx)
uhallibs::Flx::IPCMutex_t
ipc::RobustMutex IPCMutex_t
Definition
ProtocolFlx.hpp:166
uhallibs::Flx::mIPCExternalSessionActive
bool mIPCExternalSessionActive
Definition
ProtocolFlx.hpp:222
uhallibs::Flx::mIPCMutex
ipc::SharedMemObject< IPCMutex_t > mIPCMutex
Definition
ProtocolFlx.hpp:221
uhallibs::Flx::mReadReplyPageCount
uint32_t mReadReplyPageCount
Definition
ProtocolFlx.hpp:227
uhallibs::Flx::mDeviceFile
Card mDeviceFile
Definition
ProtocolFlx.hpp:219
uhallibs::Flx::read
void read()
Read next pending reply packet from appropriate page of FPGA-to-host device file, and validate conten...
Definition
ProtocolFlx.cpp:549
uhallibs::Flx::disconnect
void disconnect()
Close the connection to the device.
Definition
ProtocolFlx.cpp:495
uhallibs::Flx::mAsynchronousException
uhal::exception::exception * mAsynchronousException
Definition
ProtocolFlx.hpp:236
uhallibs::Flx::mIndexNextPage
uint32_t mIndexNextPage
Definition
ProtocolFlx.hpp:227
uhallibs::Flx::SteadyClock_t
std::chrono::steady_clock SteadyClock_t
Definition
ProtocolFlx.hpp:188
uhallibs::Flx::mIPCSessionCount
uint64_t mIPCSessionCount
Definition
ProtocolFlx.hpp:223
uhallibs::Flx::IPCScopedLock_t
std::unique_lock< IPCMutex_t > IPCScopedLock_t
Definition
ProtocolFlx.hpp:167
uhallibs::Flx::mReplyQueue
std::deque< std::shared_ptr< uhal::Buffers > > mReplyQueue
The list of buffers still awaiting a reply.
Definition
ProtocolFlx.hpp:230
uhallibs::ipc::RobustMutex
Definition
RobustMutex.hpp:21
uhallibs::ipc::SharedMemObject
Definition
SharedMemObject.hpp:12
boost
Definition
ProtocolFlx.hpp:64
uhal
Definition
ProtocolAxi4Lite.hpp:63
uhallibs::exception
Definition
ProtocolAxi4Lite.hpp:70
uhallibs::exception::UHAL_DEFINE_DERIVED_EXCEPTION_CLASS
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
uhallibs
Definition
formatters.hpp:9
uhallibs::Flx::HexTo
Definition
ProtocolFlx.hpp:140
uhallibs::Flx::HexTo::operator>>
friend std::istream & operator>>(std::istream &in, HexTo &out)
Definition
ProtocolFlx.hpp:143
uhallibs::Flx::HexTo::value
T value
Definition
ProtocolFlx.hpp:141
Generated on
for DUNE-DAQ by
1.18.0