μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
51namespace uhal
52{
53
55 class Buffers
56 {
57 public:
58
64 Buffers ( const uint32_t& aMaxSendSize = 65536 );
65
67 virtual ~Buffers();
68
73 const uint32_t& sendCounter();
74
79 const uint32_t& replyCounter();
80
86 template< typename T >
87 uint8_t* send ( const T* aPtr );
88
94 template< typename T >
95 uint8_t* send ( const T& aRef );
96
103 uint8_t* send ( const uint8_t* aPtr , const uint32_t& aSize );
104
109 template< typename T >
110 void receive ( T* aPtr );
111
116 template< typename T >
117 void receive ( T& aRef );
118
124 void receive ( uint8_t* aPtr , const uint32_t& aSize );
125
130 void add ( const ValHeader& aValMem );
131
136 void add ( const ValWord< uint32_t >& aValMem );
137
142 void add ( const ValVector< uint32_t >& aValMem );
143
148 uint8_t* getSendBuffer();
149
154 std::deque< std::pair< uint8_t* , uint32_t > >& getReplyBuffer();
155
157 void validate ();
158
160 void clear();
161
162 private:
164 uint32_t mSendCounter;
167
169 std::vector<uint8_t> mSendBuffer;
171 std::deque< std::pair< uint8_t* , uint32_t > > mReplyBuffer;
172
174 std::deque< ValHeader > mValHeaders;
176 std::deque< ValWord< uint32_t > > mUnsignedValWords;
178 std::deque< ValVector< uint32_t > > mUnsignedValVectors;
179 };
180
181}
182
184
185#endif
A class wrapping the send and recieve buffers that are to be filled and transported and the validated...
Definition: Buffers.hpp:56
void validate()
Helper function to mark all validated memories associated with this buffer as valid.
Definition: Buffers.cpp:107
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:81
std::deque< std::pair< uint8_t *, uint32_t > > mReplyBuffer
The queue of reply destinations.
Definition: Buffers.hpp:171
void clear()
Clear the counters and the reply buffers.
Definition: Buffers.cpp:120
const uint32_t & sendCounter()
Get the number of bytes that are currently in the send buffer.
Definition: Buffers.cpp:55
uint32_t mReplyCounter
The number of bytes that are currently expected by the reply buffer.
Definition: Buffers.hpp:166
uint8_t * getSendBuffer()
Get a pointer to the start of the send buffer.
Definition: Buffers.cpp:96
std::vector< uint8_t > mSendBuffer
The start location of the memory buffer.
Definition: Buffers.hpp:169
const uint32_t & replyCounter()
Get the number of bytes that are currently expected by the reply buffer.
Definition: Buffers.cpp:60
uint8_t * send(const T *aPtr)
Helper function to copy an object to the send buffer.
Definition: Buffers.hxx:44
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:50
std::deque< std::pair< uint8_t *, uint32_t > > & getReplyBuffer()
Get a reference to the reply queue.
Definition: Buffers.cpp:101
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:176
uint32_t mSendCounter
The number of bytes that are currently in the send buffer.
Definition: Buffers.hpp:164
std::deque< ValHeader > mValHeaders
Deque holding validated memories so that they are guaranteed to exist when the transaction is perform...
Definition: Buffers.hpp:174
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:178
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:147