DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
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
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"
62
63namespace uhal {
64 struct URI;
65 class Buffers;
66}
67
68namespace uhallibs {
69
70namespace exception {
74 Axi4LiteTimeout, uhal::exception::ClientTimeout,
75 "Exception class to handle the case in "
76 "which the Axi4Lite connection timed out."
77 )
81 Axi4LiteInitialisationError, uhal::exception::TransportLayerError,
82 "Exception class to handle a failure to read from the specified device "
83 "files during initialisation."
84 )
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
95class 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;
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:
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
213
215
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_ */
Transport protocol to transfer an IPbus buffer over Axi4Lite mapped in a 32b address space.
std::chrono::microseconds mSleepDuration
ipc::SharedMemObject< IPCMutex_t > mIPCMutex
IPbus< 2, 0 > InnerProtocol
std::unique_lock< IPCMutex_t > IPCScopedLock_t
std::chrono::steady_clock SteadyClock_t
std::deque< std::shared_ptr< uhal::Buffers > > mReplyQueue
The list of buffers still awaiting a reply.
Axi4Lite(const Axi4Lite &)=delete
ipc::RobustMutex IPCMutex_t
caught dunedaq::conffwk::Exception exception
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
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34