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
(
74
Axi4LiteTimeout, uhal::exception::ClientTimeout,
75
"Exception class to handle the case in "
76
"which the Axi4Lite connection timed out."
77
)
80
UHAL_DEFINE_DERIVED_EXCEPTION_CLASS
(
81
Axi4LiteInitialisationError,
uhal
::
exception
::TransportLayerError,
82
"Exception class to handle a failure to read from the specified device "
83
"files during initialisation."
84
)
87
UHAL_DEFINE_DERIVED_EXCEPTION_CLASS
(
88
Axi4LiteCommunicationError,
uhal
::
exception
::TransportLayerError,
89
"Exception class to handle a low-level seek/read/write error after "
90
"initialisation."
91
)
92
}
// namespace exception
93
95
class
Axi4Lite
: public
uhal
::IPbus<2, 0> {
96
public
:
97
class
MappedFile
{
98
public
:
99
MappedFile
(
const
std::string& aPath,
size_t
aLength,
int
aProtFlags = PROT_WRITE);
100
~MappedFile
();
101
102
const
std::string&
getPath
()
const
;
103
104
void
setPath
(
const
std::string& aPath);
105
106
void
setLength
(
size_t
);
107
109
void
open
();
111
void
close
();
112
114
void
createBuffer
(
const
size_t
aNrBytes);
115
116
void
read
(
const
uint32_t aAddr,
const
uint32_t aNrWords,
117
std::vector<uint32_t>& aValues);
118
119
void
write
(
const
uint32_t aAddr,
const
std::vector<uint32_t>& aValues);
120
121
void
write
(
const
uint32_t aAddr,
const
uint8_t*
const
aPtr,
122
const
size_t
aNrBytes);
123
124
void
write
(
const
uint32_t aAddr,
125
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
std::string
mPath
;
136
int
mFd
;
137
uint32_t*
mBar
;
138
size_t
mLength
;
139
int
mProtFlags
;
140
bool
mLocked
;
141
size_t
mBufferSize
;
142
char
*
mBuffer
;
143
};
144
150
Axi4Lite
(
const
std::string& aId,
const
uhal::URI& aUri);
151
152
Axi4Lite
(
const
Axi4Lite
& ) =
delete
;
153
Axi4Lite
& operator= (
const
Axi4Lite
& ) =
delete
;
154
156
virtual
~Axi4Lite
();
157
158
159
160
161
162
private
:
163
typedef
ipc::RobustMutex
IPCMutex_t
;
164
typedef
std::unique_lock<IPCMutex_t>
IPCScopedLock_t
;
165
166
typedef
IPbus< 2 , 0 >
InnerProtocol
;
167
typedef
std::chrono::steady_clock
SteadyClock_t
;
168
174
void
implementDispatch
( std::shared_ptr< uhal::Buffers > aBuffers );
175
177
virtual
void
Flush
( );
178
180
virtual
void
dispatchExceptionHandler
();
181
182
static
std::string
getDevicePath
(
const
uhal::URI& aUri);
183
184
static
std::string
getSharedMemName
(
const
std::string& );
185
190
uint32_t
getMaxSendSize
();
191
196
uint32_t
getMaxReplySize
();
198
void
connect
();
199
201
void
connect
(
IPCScopedLock_t
& );
202
204
void
disconnect
();
205
207
void
write
(
const
std::shared_ptr<uhal::Buffers>& aBuffers);
208
210
void
read
();
211
212
bool
mConnected
;
213
214
MappedFile
mMappedFile
;
215
216
ipc::SharedMemObject<IPCMutex_t>
mIPCMutex
;
217
bool
mIPCExternalSessionActive
;
218
uint64_t
mIPCSessionCount
;
219
220
std::chrono::microseconds
mSleepDuration
;
221
222
uint32_t
mNumberOfPages
,
mMaxInFlight
,
mPageSize
,
mMaxPacketSize
,
mIndexNextPage
,
mPublishedReplyPageCount
,
mReadReplyPageCount
;
223
225
std::deque < std::shared_ptr< uhal::Buffers > >
mReplyQueue
;
226
};
227
228
}
// namespace uhal
229
230
#endif
/* _DUNEDAQ_UHALLIBS_PROTOCOLAXI4LITE_HPP_ */
RobustMutex.hpp
SharedMemObject.hpp
uhallibs::Axi4Lite::MappedFile
Definition
ProtocolAxi4Lite.hpp:97
uhallibs::Axi4Lite::MappedFile::close
void close()
Unmap and close file.
Definition
ProtocolAxi4Lite.cpp:55
uhallibs::Axi4Lite::MappedFile::MappedFile
MappedFile(const std::string &aPath, size_t aLength, int aProtFlags=PROT_WRITE)
Definition
ProtocolAxi4Lite.cpp:23
uhallibs::Axi4Lite::MappedFile::mLength
size_t mLength
Definition
ProtocolAxi4Lite.hpp:138
uhallibs::Axi4Lite::MappedFile::mBufferSize
size_t mBufferSize
Definition
ProtocolAxi4Lite.hpp:141
uhallibs::Axi4Lite::MappedFile::open
void open()
Open bus file and map it to memory.
Definition
ProtocolAxi4Lite.cpp:43
uhallibs::Axi4Lite::MappedFile::lock
void lock()
Definition
ProtocolAxi4Lite.cpp:150
uhallibs::Axi4Lite::MappedFile::mFd
int mFd
Definition
ProtocolAxi4Lite.hpp:136
uhallibs::Axi4Lite::MappedFile::setPath
void setPath(const std::string &aPath)
Definition
ProtocolAxi4Lite.cpp:40
uhallibs::Axi4Lite::MappedFile::unlock
void unlock()
Definition
ProtocolAxi4Lite.cpp:160
uhallibs::Axi4Lite::MappedFile::haveLock
bool haveLock() const
Definition
ProtocolAxi4Lite.cpp:148
uhallibs::Axi4Lite::MappedFile::write
void write(const uint32_t aAddr, const std::vector< uint32_t > &aValues)
Definition
ProtocolAxi4Lite.cpp:101
uhallibs::Axi4Lite::MappedFile::mLocked
bool mLocked
Definition
ProtocolAxi4Lite.hpp:140
uhallibs::Axi4Lite::MappedFile::mPath
std::string mPath
Definition
ProtocolAxi4Lite.hpp:135
uhallibs::Axi4Lite::MappedFile::createBuffer
void createBuffer(const size_t aNrBytes)
Create a local buffer.
Definition
ProtocolAxi4Lite.cpp:70
uhallibs::Axi4Lite::MappedFile::getPath
const std::string & getPath() const
Definition
ProtocolAxi4Lite.cpp:38
uhallibs::Axi4Lite::MappedFile::setLength
void setLength(size_t)
Definition
ProtocolAxi4Lite.cpp:41
uhallibs::Axi4Lite::MappedFile::read
void read(const uint32_t aAddr, const uint32_t aNrWords, std::vector< uint32_t > &aValues)
Definition
ProtocolAxi4Lite.cpp:92
uhallibs::Axi4Lite::MappedFile::mBuffer
char * mBuffer
Definition
ProtocolAxi4Lite.hpp:142
uhallibs::Axi4Lite::MappedFile::mBar
uint32_t * mBar
Definition
ProtocolAxi4Lite.hpp:137
uhallibs::Axi4Lite::MappedFile::mProtFlags
int mProtFlags
Definition
ProtocolAxi4Lite.hpp:139
uhallibs::Axi4Lite::mIPCExternalSessionActive
bool mIPCExternalSessionActive
Definition
ProtocolAxi4Lite.hpp:217
uhallibs::Axi4Lite::mPageSize
uint32_t mPageSize
Definition
ProtocolAxi4Lite.hpp:222
uhallibs::Axi4Lite::mSleepDuration
std::chrono::microseconds mSleepDuration
Definition
ProtocolAxi4Lite.hpp:220
uhallibs::Axi4Lite::getSharedMemName
static std::string getSharedMemName(const std::string &)
Definition
ProtocolAxi4Lite.cpp:169
uhallibs::Axi4Lite::mIPCMutex
ipc::SharedMemObject< IPCMutex_t > mIPCMutex
Definition
ProtocolAxi4Lite.hpp:216
uhallibs::Axi4Lite::getMaxSendSize
uint32_t getMaxSendSize()
Definition
ProtocolAxi4Lite.cpp:254
uhallibs::Axi4Lite::connect
void connect()
Set up the connection to the device.
Definition
ProtocolAxi4Lite.cpp:272
uhallibs::Axi4Lite::mNumberOfPages
uint32_t mNumberOfPages
Definition
ProtocolAxi4Lite.hpp:222
uhallibs::Axi4Lite::Flush
virtual void Flush()
Concrete implementation of the synchronization function to block until all buffers have been sent,...
Definition
ProtocolAxi4Lite.cpp:227
uhallibs::Axi4Lite::IPCMutex_t
ipc::RobustMutex IPCMutex_t
Definition
ProtocolAxi4Lite.hpp:163
uhallibs::Axi4Lite::InnerProtocol
IPbus< 2, 0 > InnerProtocol
Definition
ProtocolAxi4Lite.hpp:166
uhallibs::Axi4Lite::getDevicePath
static std::string getDevicePath(const uhal::URI &aUri)
Definition
ProtocolAxi4Lite.cpp:177
uhallibs::Axi4Lite::mReadReplyPageCount
uint32_t mReadReplyPageCount
Definition
ProtocolAxi4Lite.hpp:222
uhallibs::Axi4Lite::mMaxInFlight
uint32_t mMaxInFlight
Definition
ProtocolAxi4Lite.hpp:222
uhallibs::Axi4Lite::getMaxReplySize
uint32_t getMaxReplySize()
Definition
ProtocolAxi4Lite.cpp:263
uhallibs::Axi4Lite::mReplyQueue
std::deque< std::shared_ptr< uhal::Buffers > > mReplyQueue
The list of buffers still awaiting a reply.
Definition
ProtocolAxi4Lite.hpp:225
uhallibs::Axi4Lite::disconnect
void disconnect()
Close the connection to the device.
Definition
ProtocolAxi4Lite.cpp:317
uhallibs::Axi4Lite::mMaxPacketSize
uint32_t mMaxPacketSize
Definition
ProtocolAxi4Lite.hpp:222
uhallibs::Axi4Lite::dispatchExceptionHandler
virtual void dispatchExceptionHandler()
Function which tidies up this protocol layer in the event of an exception.
Definition
ProtocolAxi4Lite.cpp:240
uhallibs::Axi4Lite::Axi4Lite
Axi4Lite(const std::string &aId, const uhal::URI &aUri)
Definition
ProtocolAxi4Lite.cpp:191
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:323
uhallibs::Axi4Lite::Axi4Lite
Axi4Lite(const Axi4Lite &)=delete
uhallibs::Axi4Lite::mMappedFile
MappedFile mMappedFile
Definition
ProtocolAxi4Lite.hpp:214
uhallibs::Axi4Lite::mIndexNextPage
uint32_t mIndexNextPage
Definition
ProtocolAxi4Lite.hpp:222
uhallibs::Axi4Lite::mConnected
bool mConnected
Definition
ProtocolAxi4Lite.hpp:212
uhallibs::Axi4Lite::SteadyClock_t
std::chrono::steady_clock SteadyClock_t
Definition
ProtocolAxi4Lite.hpp:167
uhallibs::Axi4Lite::mPublishedReplyPageCount
uint32_t mPublishedReplyPageCount
Definition
ProtocolAxi4Lite.hpp:222
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:355
uhallibs::Axi4Lite::IPCScopedLock_t
std::unique_lock< IPCMutex_t > IPCScopedLock_t
Definition
ProtocolAxi4Lite.hpp:164
uhallibs::Axi4Lite::implementDispatch
void implementDispatch(std::shared_ptr< uhal::Buffers > aBuffers)
Definition
ProtocolAxi4Lite.cpp:214
uhallibs::Axi4Lite::mIPCSessionCount
uint64_t mIPCSessionCount
Definition
ProtocolAxi4Lite.hpp:218
uhallibs::ipc::RobustMutex
Definition
RobustMutex.hpp:20
uhallibs::ipc::SharedMemObject
Definition
SharedMemObject.hpp:11
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.17.0