μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
39namespace uhal
40{
41
42 Buffers::Buffers ( const uint32_t& aMaxSendSize ) :
43 mSendCounter ( 0 ),
44 mReplyCounter ( 0 ),
45 mSendBuffer ( aMaxSendSize , 0x00 )
46 {
47 }
48
49
51 {
52 }
53
54
55 const uint32_t& Buffers::sendCounter()
56 {
57 return mSendCounter;
58 }
59
60 const uint32_t& Buffers::replyCounter()
61 {
62 return mReplyCounter;
63 }
64
65
66 uint8_t* Buffers::send ( const uint8_t* aPtr , const uint32_t& aSize )
67 {
68 uint8_t* lStartPtr ( &mSendBuffer[0]+mSendCounter );
69 memcpy ( lStartPtr , aPtr , aSize );
70 mSendCounter += aSize;
71 return lStartPtr;
72 }
73
74
75 void Buffers::receive ( uint8_t* aPtr , const uint32_t& aSize )
76 {
77 mReplyBuffer.push_back ( std::make_pair ( aPtr , aSize ) );
78 mReplyCounter += aSize;
79 }
80
81 void Buffers::add ( const ValHeader& aValMem )
82 {
83 mValHeaders.push_back ( aValMem );
84 }
85
86 void Buffers::add ( const ValWord< uint32_t >& aValMem )
87 {
88 mUnsignedValWords.push_back ( aValMem );
89 }
90
91 void Buffers::add ( const ValVector< uint32_t >& aValMem )
92 {
93 mUnsignedValVectors.push_back ( aValMem );
94 }
95
97 {
98 return &mSendBuffer[0];
99 }
100
101 std::deque< std::pair< uint8_t* , uint32_t > >& Buffers::getReplyBuffer()
102 {
103 return mReplyBuffer;
104 }
105
106
108 {
109 for (auto& x: mValHeaders)
110 x.valid ( true );
111
112 for (auto& x: mUnsignedValWords)
113 x.valid ( true );
114
115 for (auto& x: mUnsignedValVectors)
116 x.valid ( true );
117 }
118
119
121 {
122 mSendCounter = 0 ;
123 mReplyCounter = 0 ;
124 mReplyBuffer.clear();
125 mValHeaders.clear();
126 mUnsignedValWords.clear();
127 mUnsignedValVectors.clear();
128 }
129
130}
131
132
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
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: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