μHAL (v2.6.5)
Part of the IPbus software repository
Buffers.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 ---------------------------------------------------------------------------
31 */
32 
39 #ifndef _uhal_Buffers_hpp_
40 #define _uhal_Buffers_hpp_
41 
42 
43 #include <deque>
44 #include <stdint.h> // for uint32_t, uint8_t
45 #include <utility> // for pair
46 #include <vector> // for vector
47 
48 #include "uhal/ValMem.hpp"
49 
50 
51 namespace uhal
52 {
53 
55  class Buffers
56  {
57  public:
58 
64  Buffers ( const uint32_t& aMaxSendSize = 65536 );
65 
69  virtual ~Buffers();
70 
75  const uint32_t& sendCounter();
76 
81  const uint32_t& replyCounter();
82 
88  template< typename T >
89  uint8_t* send ( const T* aPtr );
90 
96  template< typename T >
97  uint8_t* send ( const T& aRef );
98 
105  uint8_t* send ( const uint8_t* aPtr , const uint32_t& aSize );
106 
111  template< typename T >
112  void receive ( T* aPtr );
113 
118  template< typename T >
119  void receive ( T& aRef );
120 
126  void receive ( uint8_t* aPtr , const uint32_t& aSize );
127 
132  void add ( const ValHeader& aValMem );
133 
138  void add ( const ValWord< uint32_t >& aValMem );
139 
140  // /*
141  // Helper function to associate a validated memory with this buffer so that it is guaranteed to exist when the transaction is performed
142  // @param aValMem a validated memory to be associated with this buffer
143  // */
144  // void add ( const ValWord< int32_t >& aValMem );
145 
150  void add ( const ValVector< uint32_t >& aValMem );
151 
152  // /*
153  // Helper function to associate a validated memory with this buffer so that it is guaranteed to exist when the transaction is performed
154  // @param aValMem a validated memory to be associated with this buffer
155  // */
156  // void add ( const ValVector< int32_t >& aValMem );
157 
162  uint8_t* getSendBuffer();
163 
168  std::deque< std::pair< uint8_t* , uint32_t > >& getReplyBuffer();
169 
173  void validate ();
174 
178  void clear();
179 
180  private:
182  uint32_t mSendCounter;
184  uint32_t mReplyCounter;
185 
187  std::vector<uint8_t> mSendBuffer;
189  std::deque< std::pair< uint8_t* , uint32_t > > mReplyBuffer;
190 
192  std::deque< ValHeader > mValHeaders;
194  std::deque< ValWord< uint32_t > > mUnsignedValWords;
195  // Deque holding validated memories so that they are guaranteed to exist when the transaction is performed
196  // std::deque< ValWord< int32_t > > mSignedValWords;
198  std::deque< ValVector< uint32_t > > mUnsignedValVectors;
199  // Deque holding validated memories so that they are guaranteed to exist when the transaction is performed
200  // std::deque< ValVector< int32_t > > mSignedValVectors;
201  };
202 
203 
204 
205 
206 
207 }
208 
210 
211 #endif
uint32_t mReplyCounter
The number of bytes that are currently expected by the reply buffer.
Definition: Buffers.hpp:184
void receive(T *aPtr)
Helper function to add a destination object to the reply queue.
Definition: Buffers.hxx:64
virtual ~Buffers()
Destructor.
Definition: Buffers.cpp:51
std::deque< std::pair< uint8_t *, uint32_t > > mReplyBuffer
The queue of reply destinations.
Definition: Buffers.hpp:189
void clear()
Clear the counters and the reply buffers.
Definition: Buffers.cpp:149
void validate()
Helper function to mark all validated memories associated with this buffer as valid.
Definition: Buffers.cpp:121
uint8_t * send(const T *aPtr)
Helper function to copy an object to the send buffer.
Definition: Buffers.hxx:44
A class wrapping the send and recieve buffers that are to be filled and transported and the validated...
Definition: Buffers.hpp:55
std::deque< std::pair< uint8_t *, uint32_t > > & getReplyBuffer()
Get a reference to the reply queue.
Definition: Buffers.cpp:115
void add(const ValHeader &aValMem)
Helper function to associate a validated memory with this buffer so that it is guaranteed to exist wh...
Definition: Buffers.cpp:83
Buffers(const uint32_t &aMaxSendSize=65536)
Constructor.
Definition: Buffers.cpp:42
std::deque< ValHeader > mValHeaders
Deque holding validated memories so that they are guaranteed to exist when the transaction is perform...
Definition: Buffers.hpp:192
std::deque< ValWord< uint32_t > > mUnsignedValWords
Deque holding validated memories so that they are guaranteed to exist when the transaction is perform...
Definition: Buffers.hpp:194
uint32_t mSendCounter
The number of bytes that are currently in the send buffer.
Definition: Buffers.hpp:182
const uint32_t & sendCounter()
Get the number of bytes that are currently in the send buffer.
Definition: Buffers.cpp:56
std::deque< ValVector< uint32_t > > mUnsignedValVectors
Deque holding validated memories so that they are guaranteed to exist when the transaction is perform...
Definition: Buffers.hpp:198
const uint32_t & replyCounter()
Get the number of bytes that are currently expected by the reply buffer.
Definition: Buffers.cpp:61
uint8_t * getSendBuffer()
Get a pointer to the start of the send buffer.
Definition: Buffers.cpp:110
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:156
std::vector< uint8_t > mSendBuffer
The start location of the memory buffer.
Definition: Buffers.hpp:187