DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
uhallibs
include
uhallibs
ProtocolAxi4Lite.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_PROTOCOLAXI4LITE_HPP_
43
#define _DUNEDAQ_UHALLIBS_PROTOCOLAXI4LITE_HPP_
44
45
#include <stddef.h>
// for size_t
46
#include <stdint.h>
// for uint32_t, uint8_t
47
48
#include <chrono>
49
#include <deque>
// for deque
50
#include <memory>
51
#include <mutex>
52
#include <string>
// for string
53
#include <utility>
// for pair
54
#include <vector>
// for vector
55
56
#include "uhal/ClientInterface.hpp"
57
#include "uhal/ProtocolIPbus.hpp"
58
#include "uhal/log/exception.hpp"
59
#include "
uhallibs/formatters.hpp
"
60
#include "
uhallibs/ipc/RobustMutex.hpp
"
61
#include "
uhallibs/ipc/SharedMemObject.hpp
"
62
63
namespace
uhal
{
64
struct
URI;
65
class
Buffers;
66
}
67
68
namespace
uhallibs
{
69
70
namespace
exception
{
73
UHAL_DEFINE_DERIVED_EXCEPTION_CLASS
(Axi4LiteTimeout,
74
uhal::exception::ClientTimeout,
75
"Exception class to handle the case in "
76
"which the Axi4Lite connection timed out."
)
79
UHAL_DEFINE_DERIVED_EXCEPTION_CLASS
(Axi4LiteInitialisationError,
80
uhal
::
exception
::TransportLayerError,
81
"Exception class to handle a failure to read from the specified device "
82
"files during initialisation."
)
85
UHAL_DEFINE_DERIVED_EXCEPTION_CLASS
(Axi4LiteCommunicationError,
86
uhal
::
exception
::TransportLayerError,
87
"Exception class to handle a low-level seek/read/write error after "
88
"initialisation."
)
89
}
// namespace exception
90
92
class
Axi4Lite
: public
uhal
::IPbus<2, 0>
93
{
94
public
:
95
class
MappedFile
96
{
97
public
:
98
MappedFile
(
const
std::string& aPath,
size_t
aLength,
int
aProtFlags = PROT_WRITE);
99
~MappedFile
();
100
101
const
std::string&
getPath
()
const
;
102
103
void
setPath
(
const
std::string& aPath);
104
105
void
setLength
(
size_t
);
106
108
void
open
();
110
void
close
();
111
113
void
createBuffer
(
const
size_t
aNrBytes);
114
115
void
read
(
const
uint32_t aAddr,
const
uint32_t aNrWords, std::vector<uint32_t>& aValues);
116
117
void
write
(
const
uint32_t aAddr,
const
std::vector<uint32_t>& aValues);
118
119
void
write
(
const
uint32_t aAddr,
const
uint8_t*
const
aPtr,
const
size_t
aNrBytes);
120
121
void
write
(
const
uint32_t aAddr,
const
std::vector<std::pair<const uint8_t*, size_t>>& aData);
122
123
bool
haveLock
()
const
;
124
125
void
lock
();
126
127
void
unlock
();
128
129
private
:
130
std::string
mPath
;
131
int
mFd
;
132
uint32_t*
mBar
;
133
size_t
mLength
;
134
int
mProtFlags
;
135
bool
mLocked
;
136
size_t
mBufferSize
;
137
char
*
mBuffer
;
138
};
139
145
Axi4Lite
(
const
std::string& aId,
const
uhal::URI& aUri);
146
147
Axi4Lite
(
const
Axi4Lite
&) =
delete
;
148
Axi4Lite
&
operator=
(
const
Axi4Lite
&) =
delete
;
149
151
virtual
~Axi4Lite
();
152
153
private
:
154
typedef
ipc::RobustMutex
IPCMutex_t
;
155
typedef
std::unique_lock<IPCMutex_t>
IPCScopedLock_t
;
156
157
typedef
IPbus<2, 0>
InnerProtocol
;
158
typedef
std::chrono::steady_clock
SteadyClock_t
;
159
166
void
implementDispatch
(std::shared_ptr<uhal::Buffers> aBuffers);
167
170
virtual
void
Flush
();
171
173
virtual
void
dispatchExceptionHandler
();
174
175
static
std::string
getDevicePath
(
const
uhal::URI& aUri);
176
177
static
std::string
getSharedMemName
(
const
std::string&);
178
183
uint32_t
getMaxSendSize
();
184
189
uint32_t
getMaxReplySize
();
191
void
connect
();
192
194
void
connect
(
IPCScopedLock_t
&);
195
197
void
disconnect
();
198
200
void
write
(
const
std::shared_ptr<uhal::Buffers>& aBuffers);
201
203
void
read
();
204
205
bool
mConnected
;
206
207
MappedFile
mMappedFile
;
208
209
ipc::SharedMemObject<IPCMutex_t>
mIPCMutex
;
210
bool
mIPCExternalSessionActive
;
211
uint64_t
mIPCSessionCount
;
212
213
std::chrono::microseconds
mSleepDuration
;
214
215
uint32_t
mNumberOfPages
,
mMaxInFlight
,
mPageSize
,
mMaxPacketSize
,
mIndexNextPage
,
mPublishedReplyPageCount
,
216
mReadReplyPageCount
;
217
219
std::deque<std::shared_ptr<uhal::Buffers>>
mReplyQueue
;
220
};
221
222
}
// namespace uhal
223
224
#endif
/* _DUNEDAQ_UHALLIBS_PROTOCOLAXI4LITE_HPP_ */
RobustMutex.hpp
SharedMemObject.hpp
uhallibs::Axi4Lite::MappedFile
Definition
ProtocolAxi4Lite.hpp:96
uhallibs::Axi4Lite::MappedFile::close
void close()
Unmap and close file.
Definition
ProtocolAxi4Lite.cpp:74
uhallibs::Axi4Lite::MappedFile::MappedFile
MappedFile(const std::string &aPath, size_t aLength, int aProtFlags=PROT_WRITE)
Definition
ProtocolAxi4Lite.cpp:22
uhallibs::Axi4Lite::MappedFile::mLength
size_t mLength
Definition
ProtocolAxi4Lite.hpp:133
uhallibs::Axi4Lite::MappedFile::mBufferSize
size_t mBufferSize
Definition
ProtocolAxi4Lite.hpp:136
uhallibs::Axi4Lite::MappedFile::open
void open()
Open bus file and map it to memory.
Definition
ProtocolAxi4Lite.cpp:59
uhallibs::Axi4Lite::MappedFile::lock
void lock()
Definition
ProtocolAxi4Lite.cpp:189
uhallibs::Axi4Lite::MappedFile::mFd
int mFd
Definition
ProtocolAxi4Lite.hpp:131
uhallibs::Axi4Lite::MappedFile::setPath
void setPath(const std::string &aPath)
Definition
ProtocolAxi4Lite.cpp:48
uhallibs::Axi4Lite::MappedFile::unlock
void unlock()
Definition
ProtocolAxi4Lite.cpp:206
uhallibs::Axi4Lite::MappedFile::haveLock
bool haveLock() const
Definition
ProtocolAxi4Lite.cpp:183
uhallibs::Axi4Lite::MappedFile::write
void write(const uint32_t aAddr, const std::vector< uint32_t > &aValues)
Definition
ProtocolAxi4Lite.cpp:131
uhallibs::Axi4Lite::MappedFile::mLocked
bool mLocked
Definition
ProtocolAxi4Lite.hpp:135
uhallibs::Axi4Lite::MappedFile::mPath
std::string mPath
Definition
ProtocolAxi4Lite.hpp:130
uhallibs::Axi4Lite::MappedFile::createBuffer
void createBuffer(const size_t aNrBytes)
Create a local buffer.
Definition
ProtocolAxi4Lite.cpp:97
uhallibs::Axi4Lite::MappedFile::getPath
const std::string & getPath() const
Definition
ProtocolAxi4Lite.cpp:42
uhallibs::Axi4Lite::MappedFile::setLength
void setLength(size_t)
Definition
ProtocolAxi4Lite.cpp:53
uhallibs::Axi4Lite::MappedFile::read
void read(const uint32_t aAddr, const uint32_t aNrWords, std::vector< uint32_t > &aValues)
Definition
ProtocolAxi4Lite.cpp:120
uhallibs::Axi4Lite::MappedFile::mBuffer
char * mBuffer
Definition
ProtocolAxi4Lite.hpp:137
uhallibs::Axi4Lite::MappedFile::mBar
uint32_t * mBar
Definition
ProtocolAxi4Lite.hpp:132
uhallibs::Axi4Lite::MappedFile::mProtFlags
int mProtFlags
Definition
ProtocolAxi4Lite.hpp:134
uhallibs::Axi4Lite::mIPCExternalSessionActive
bool mIPCExternalSessionActive
Definition
ProtocolAxi4Lite.hpp:210
uhallibs::Axi4Lite::mReplyQueue
std::deque< std::shared_ptr< uhal::Buffers > > mReplyQueue
The list of buffers still awaiting a reply.
Definition
ProtocolAxi4Lite.hpp:219
uhallibs::Axi4Lite::mPageSize
uint32_t mPageSize
Definition
ProtocolAxi4Lite.hpp:215
uhallibs::Axi4Lite::mSleepDuration
std::chrono::microseconds mSleepDuration
Definition
ProtocolAxi4Lite.hpp:213
uhallibs::Axi4Lite::getSharedMemName
static std::string getSharedMemName(const std::string &)
Definition
ProtocolAxi4Lite.cpp:222
uhallibs::Axi4Lite::mIPCMutex
ipc::SharedMemObject< IPCMutex_t > mIPCMutex
Definition
ProtocolAxi4Lite.hpp:209
uhallibs::Axi4Lite::getMaxSendSize
uint32_t getMaxSendSize()
Definition
ProtocolAxi4Lite.cpp:312
uhallibs::Axi4Lite::connect
void connect()
Set up the connection to the device.
Definition
ProtocolAxi4Lite.cpp:330
uhallibs::Axi4Lite::mNumberOfPages
uint32_t mNumberOfPages
Definition
ProtocolAxi4Lite.hpp:215
uhallibs::Axi4Lite::Flush
virtual void Flush()
Definition
ProtocolAxi4Lite.cpp:280
uhallibs::Axi4Lite::IPCMutex_t
ipc::RobustMutex IPCMutex_t
Definition
ProtocolAxi4Lite.hpp:154
uhallibs::Axi4Lite::getDevicePath
static std::string getDevicePath(const uhal::URI &aUri)
Definition
ProtocolAxi4Lite.cpp:231
uhallibs::Axi4Lite::mReadReplyPageCount
uint32_t mReadReplyPageCount
Definition
ProtocolAxi4Lite.hpp:216
uhallibs::Axi4Lite::mMaxInFlight
uint32_t mMaxInFlight
Definition
ProtocolAxi4Lite.hpp:215
uhallibs::Axi4Lite::getMaxReplySize
uint32_t getMaxReplySize()
Definition
ProtocolAxi4Lite.cpp:321
uhallibs::Axi4Lite::InnerProtocol
IPbus< 2, 0 > InnerProtocol
Definition
ProtocolAxi4Lite.hpp:157
uhallibs::Axi4Lite::disconnect
void disconnect()
Close the connection to the device.
Definition
ProtocolAxi4Lite.cpp:388
uhallibs::Axi4Lite::mMaxPacketSize
uint32_t mMaxPacketSize
Definition
ProtocolAxi4Lite.hpp:215
uhallibs::Axi4Lite::dispatchExceptionHandler
virtual void dispatchExceptionHandler()
Function which tidies up this protocol layer in the event of an exception.
Definition
ProtocolAxi4Lite.cpp:293
uhallibs::Axi4Lite::Axi4Lite
Axi4Lite(const std::string &aId, const uhal::URI &aUri)
Definition
ProtocolAxi4Lite.cpp:247
uhallibs::Axi4Lite::write
void write(const std::shared_ptr< uhal::Buffers > &aBuffers)
Write request packet to next page in host-to-FPGA device file.
Definition
ProtocolAxi4Lite.cpp:395
uhallibs::Axi4Lite::Axi4Lite
Axi4Lite(const Axi4Lite &)=delete
uhallibs::Axi4Lite::mMappedFile
MappedFile mMappedFile
Definition
ProtocolAxi4Lite.hpp:207
uhallibs::Axi4Lite::mIndexNextPage
uint32_t mIndexNextPage
Definition
ProtocolAxi4Lite.hpp:215
uhallibs::Axi4Lite::mConnected
bool mConnected
Definition
ProtocolAxi4Lite.hpp:205
uhallibs::Axi4Lite::SteadyClock_t
std::chrono::steady_clock SteadyClock_t
Definition
ProtocolAxi4Lite.hpp:158
uhallibs::Axi4Lite::mPublishedReplyPageCount
uint32_t mPublishedReplyPageCount
Definition
ProtocolAxi4Lite.hpp:215
uhallibs::Axi4Lite::operator=
Axi4Lite & operator=(const Axi4Lite &)=delete
uhallibs::Axi4Lite::read
void read()
Read next pending reply packet from appropriate page of FPGA-to-host device file, and validate conten...
Definition
ProtocolAxi4Lite.cpp:443
uhallibs::Axi4Lite::IPCScopedLock_t
std::unique_lock< IPCMutex_t > IPCScopedLock_t
Definition
ProtocolAxi4Lite.hpp:155
uhallibs::Axi4Lite::implementDispatch
void implementDispatch(std::shared_ptr< uhal::Buffers > aBuffers)
Definition
ProtocolAxi4Lite.cpp:267
uhallibs::Axi4Lite::mIPCSessionCount
uint64_t mIPCSessionCount
Definition
ProtocolAxi4Lite.hpp:211
uhallibs::ipc::RobustMutex
Definition
RobustMutex.hpp:21
uhallibs::ipc::SharedMemObject
Definition
SharedMemObject.hpp:12
formatters.hpp
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
Generated on
for DUNE-DAQ by
1.18.0