μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DummyHardware.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_tests_DummyHardware_hpp_
40#define _uhal_tests_DummyHardware_hpp_
41
42
43#include <chrono>
44#include <deque>
45#include <vector>
46
48
49
50namespace uhal
51{
52 namespace tests
53 {
54
56 static const uint32_t ADDRESSMASK = 0x00FFFFFF;
58 static const uint32_t REPLY_HISTORY_DEPTH = 5;
60 static const uint32_t BUFFER_SIZE = 100000;
61
62
65 public:
66 DummyHardwareInterface(const std::chrono::microseconds& aReplyDelay) :
67 mReplyDelay(aReplyDelay)
68 {
69 }
70
72
74 virtual void run() = 0;
75
77 virtual void stop() = 0;
78
79 template <class DurationType>
80 void setReplyDelay(const DurationType& aDelay)
81 {
82 mReplyDelay = aDelay;
83 }
84
85 protected:
87 std::chrono::microseconds mReplyDelay;
88 };
89
90
92 template< uint8_t IPbus_major , uint8_t IPbus_minor >
93 class DummyHardware : public DummyHardwareInterface, public HostToTargetInspector< IPbus_major , IPbus_minor >
94 {
96
97 public:
103 DummyHardware ( const uint32_t& aReplyDelay, const bool& aBigEndianHack );
104
105 virtual ~DummyHardware();
106
107 protected:
112 void AnalyzeReceivedAndCreateReply ( const uint32_t& aByteCount );
113
114 void SetEndpoint( const uint32_t& aAddress , const uint32_t& aValue );
115
116 private:
117
118 uint32_t GetEndpoint( const uint32_t& aAddress );
119
121 void bot();
122
127 void ni_read ( const uint32_t& aAddress );
128
133 void read ( const uint32_t& aAddress );
134
139 void readConfigurationSpace ( const uint32_t& aAddress );
140
147 void ni_write ( const uint32_t& aAddress , std::vector<uint32_t>::const_iterator& aIt , const std::vector<uint32_t>::const_iterator& aEnd );
148
155 void write ( const uint32_t& aAddress , std::vector<uint32_t>::const_iterator& aIt , const std::vector<uint32_t>::const_iterator& aEnd );
156
162 void rmw_sum ( const uint32_t& aAddress , const uint32_t& aAddend );
163
170 void rmw_bits ( const uint32_t& aAddress , const uint32_t& aAndTerm , const uint32_t& aOrTerm );
171
173 void unknown_type();
174
177
180
183
186
187
188 private:
190 std::vector< uint32_t > mMemory;
191
193 std::vector< uint32_t > mConfigurationSpace;
194
195 protected:
197 std::vector< uint32_t > mReceive;
199 std::vector< uint32_t > mReply;
200
202 std::deque< std::pair< uint32_t , std::vector< uint32_t > > > mReplyHistory;
203
206
208 std::deque< uint8_t > mTrafficHistory;
209
213 std::deque< uint32_t > mSentControlPacketHeaderHistory;
214
215 private:
218 };
219 }
220
221}
222
223#endif
224
225
Helper class to decode IPbus packets as passed from the Client to the Target.
Abstract base class to emulate IPbus hardware.
void unknown_type()
Analyse request and create reply when the header is unknown.
void rmw_sum(const uint32_t &aAddress, const uint32_t &aAddend)
Analyse request and create reply when a read-modify-write sum is observed.
std::vector< uint32_t > mMemory
The memory space of the virtual hardware.
void read(const uint32_t &aAddress)
Analyse request and create reply when an incrementing read is observed.
void SetEndpoint(const uint32_t &aAddress, const uint32_t &aValue)
bool mBigEndianHack
Whether we are talking to an IPbus client which includes the big-endian hack.
std::vector< uint32_t > mReply
The buffer for the outgoing IPbus packet.
void ni_write(const uint32_t &aAddress, std::vector< uint32_t >::const_iterator &aIt, const std::vector< uint32_t >::const_iterator &aEnd)
Analyse request and create reply when a non-incrementing write is observed.
std::deque< uint32_t > mSentControlPacketHeaderHistory
History of the sent control packet headers.
void ni_read(const uint32_t &aAddress)
Analyse request and create reply when a non-incrementing read is observed.
uint32_t GetEndpoint(const uint32_t &aAddress)
std::deque< uint32_t > mReceivedControlPacketHeaderHistory
History of the received control packet headers.
void write(const uint32_t &aAddress, std::vector< uint32_t >::const_iterator &aIt, const std::vector< uint32_t >::const_iterator &aEnd)
Analyse request and create reply when an incrementing write is observed.
std::vector< uint32_t > mReceive
The buffer for the incoming IPbus packet.
std::deque< uint8_t > mTrafficHistory
History of the IPbus 2.0 packet-types received.
std::deque< std::pair< uint32_t, std::vector< uint32_t > > > mReplyHistory
The history of the replies for the retry mechanism (IPbus 2.0 and above only)
void rmw_bits(const uint32_t &aAddress, const uint32_t &aAndTerm, const uint32_t &aOrTerm)
Analyse request and create reply when a read-modify-write bits is observed.
void status_packet_header()
Analyse request and create reply when an IPbus 2.0 status packet header is observed.
uint32_t mLastPacketHeader
The last sent packet header for the retry mechanism (IPbus 2.0 and above only)
std::vector< uint32_t > mConfigurationSpace
The configuration space within the virtual hardware.
bool control_packet_header()
Analyse request and create reply when an IPbus 2.0 control packet header is observed.
void resend_packet_header()
Analyse request and create reply when an IPbus 2.0 resend packet header is observed.
void readConfigurationSpace(const uint32_t &aAddress)
Analyse request and create reply when an incrementing "configuration space" read is observed.
HostToTargetInspector< IPbus_major, IPbus_minor > base_type
void unknown_packet_header()
Analyse request and create reply when an unknown IPbus 2.0 packet header is observed.
void bot()
Analyse request and create reply when a Byte-OrderTransaction is observed.
void AnalyzeReceivedAndCreateReply(const uint32_t &aByteCount)
Function which analyses the received IPbus packet and creates the suitable response.
Common abstract base class for IPbus 1.3 and 2.0 dummy hardware.
std::chrono::microseconds mReplyDelay
The delay in seconds between the request and reply of the first transaction.
virtual void run()=0
Function which "starts" the dummy hardware; does not return until the 'stop' method is called.
DummyHardwareInterface(const std::chrono::microseconds &aReplyDelay)
virtual void stop()=0
Stops this dummy hardware instance - i.e. makes the 'run' method return.
void setReplyDelay(const DurationType &aDelay)
None tests(nox.Session session)
Definition: noxfile.py:19
static const uint32_t BUFFER_SIZE
Size of the receive and reply buffers.
static const uint32_t REPLY_HISTORY_DEPTH
The size of the reply history for IPbus 2.0.
static const uint32_t ADDRESSMASK
The mask for the address space (size of the address space in one larger than this)