μHAL (v2.6.5)
Part of the IPbus software repository
Buffers.cpp
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 
33 #include "uhal/Buffers.hpp"
34 
35 
36 #include <string.h>
37 
38 
39 namespace uhal
40 {
41 
42  Buffers::Buffers ( const uint32_t& aMaxSendSize ) :
43  mSendCounter ( 0 ),
44  mReplyCounter ( 0 ),
45  mSendBuffer ( aMaxSendSize , 0x00 )
46  {
47  }
48 
49 
50 
52  {
53  }
54 
55 
56  const uint32_t& Buffers::sendCounter()
57  {
58  return mSendCounter;
59  }
60 
61  const uint32_t& Buffers::replyCounter()
62  {
63  return mReplyCounter;
64  }
65 
66 
67 
68  uint8_t* Buffers::send ( const uint8_t* aPtr , const uint32_t& aSize )
69  {
70  uint8_t* lStartPtr ( &mSendBuffer[0]+mSendCounter );
71  memcpy ( lStartPtr , aPtr , aSize );
72  mSendCounter += aSize;
73  return lStartPtr;
74  }
75 
76 
77  void Buffers::receive ( uint8_t* aPtr , const uint32_t& aSize )
78  {
79  mReplyBuffer.push_back ( std::make_pair ( aPtr , aSize ) );
80  mReplyCounter += aSize;
81  }
82 
83  void Buffers::add ( const ValHeader& aValMem )
84  {
85  mValHeaders.push_back ( aValMem );
86  }
87 
88  void Buffers::add ( const ValWord< uint32_t >& aValMem )
89  {
90  mUnsignedValWords.push_back ( aValMem );
91  }
92 
93  // void Buffers::add ( const ValWord< int32_t >& aValMem )
94  // {
95  //
96  // mSignedValWords.push_back ( aValMem );
97  // }
98 
99  void Buffers::add ( const ValVector< uint32_t >& aValMem )
100  {
101  mUnsignedValVectors.push_back ( aValMem );
102  }
103 
104  // void Buffers::add ( const ValVector< int32_t >& aValMem )
105  // {
106  //
107  // mSignedValVectors.push_back ( aValMem );
108  // }
109 
111  {
112  return &mSendBuffer[0];
113  }
114 
115  std::deque< std::pair< uint8_t* , uint32_t > >& Buffers::getReplyBuffer()
116  {
117  return mReplyBuffer;
118  }
119 
120 
122  {
123  for ( std::deque< ValHeader >::iterator lIt = mValHeaders.begin() ; lIt != mValHeaders.end() ; ++lIt )
124  {
125  lIt->valid ( true );
126  }
127 
128  for ( std::deque< ValWord< uint32_t > >::iterator lIt = mUnsignedValWords.begin() ; lIt != mUnsignedValWords.end() ; ++lIt )
129  {
130  lIt->valid ( true );
131  }
132 
133  // for ( std::deque< ValWord< int32_t > >::iterator lIt = mSignedValWords.begin() ; lIt != mSignedValWords.end() ; ++lIt )
134  // {
135  // lIt->valid ( true );
136  // }
137 
138  for ( std::deque< ValVector< uint32_t > >::iterator lIt = mUnsignedValVectors.begin() ; lIt != mUnsignedValVectors.end() ; ++lIt )
139  {
140  lIt->valid ( true );
141  }
142 
143  // for ( std::deque< ValVector< int32_t > >::iterator lIt = mSignedValVectors.begin() ; lIt != mSignedValVectors.end() ; ++lIt )
144  // {
145  // lIt->valid ( true );
146  // }
147  }
148 
150  {
151  mSendCounter = 0 ;
152  mReplyCounter = 0 ;
153  mReplyBuffer.clear();
154  mValHeaders.clear();
155  mUnsignedValWords.clear();
156  // mSignedValWords.clear();
157  mUnsignedValVectors.clear();
158  // mSignedValVectors.clear();
159  }
160 
161 }
162 
163 
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
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