μHAL (v2.7.9)
Part of the IPbus software repository
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 <deque>
44 #include <vector>
45 
46 #include <boost/chrono/chrono_io.hpp>
47 #include <boost/thread/thread.hpp>
48 
49 #include "uhal/IPbusInspector.hpp"
50 
51 
52 namespace uhal
53 {
54  namespace tests
55  {
56 
58  static const uint32_t ADDRESSMASK = 0x00FFFFFF;
60  static const uint32_t REPLY_HISTORY_DEPTH = 5;
62  static const uint32_t BUFFER_SIZE = 100000;
63 
64 
67  public:
68  DummyHardwareInterface(const boost::chrono::microseconds& aReplyDelay) :
69  mReplyDelay(aReplyDelay)
70  {
71  }
72 
74 
76  virtual void run() = 0;
77 
79  virtual void stop() = 0;
80 
81  template <class DurationType>
82  void setReplyDelay(const DurationType& aDelay)
83  {
84  mReplyDelay = aDelay;
85  }
86 
87  protected:
89  boost::chrono::microseconds mReplyDelay;
90  };
91 
92 
94  template< uint8_t IPbus_major , uint8_t IPbus_minor >
95  class DummyHardware : public DummyHardwareInterface, public HostToTargetInspector< IPbus_major , IPbus_minor >
96  {
98 
99  public:
105  DummyHardware ( const uint32_t& aReplyDelay, const bool& aBigEndianHack );
106 
107  virtual ~DummyHardware();
108 
109  protected:
114  void AnalyzeReceivedAndCreateReply ( const uint32_t& aByteCount );
115 
116  void SetEndpoint( const uint32_t& aAddress , const uint32_t& aValue );
117 
118  private:
119 
120  uint32_t GetEndpoint( const uint32_t& aAddress );
121 
123  void bot();
124 
129  void ni_read ( const uint32_t& aAddress );
130 
135  void read ( const uint32_t& aAddress );
136 
141  void readConfigurationSpace ( const uint32_t& aAddress );
142 
149  void ni_write ( const uint32_t& aAddress , std::vector<uint32_t>::const_iterator& aIt , const std::vector<uint32_t>::const_iterator& aEnd );
150 
157  void write ( const uint32_t& aAddress , std::vector<uint32_t>::const_iterator& aIt , const std::vector<uint32_t>::const_iterator& aEnd );
158 
164  void rmw_sum ( const uint32_t& aAddress , const uint32_t& aAddend );
165 
172  void rmw_bits ( const uint32_t& aAddress , const uint32_t& aAndTerm , const uint32_t& aOrTerm );
173 
175  void unknown_type();
176 
178  bool control_packet_header();
179 
181  void status_packet_header();
182 
184  void resend_packet_header();
185 
187  void unknown_packet_header();
188 
189 
190  private:
192  std::vector< uint32_t > mMemory;
193 
195  std::vector< uint32_t > mConfigurationSpace;
196 
197  protected:
199  std::vector< uint32_t > mReceive;
201  std::vector< uint32_t > mReply;
202 
204  std::deque< std::pair< uint32_t , std::vector< uint32_t > > > mReplyHistory;
205 
208 
210  std::deque< uint8_t > mTrafficHistory;
211 
213  std::deque< uint32_t > mReceivedControlPacketHeaderHistory;
215  std::deque< uint32_t > mSentControlPacketHeaderHistory;
216 
217  private:
220  };
221  }
222 
223 }
224 
225 #endif
226 
227 
uhal::tests::DummyHardware::mConfigurationSpace
std::vector< uint32_t > mConfigurationSpace
The configuration space within the virtual hardware.
Definition: DummyHardware.hpp:195
uhal::tests::DummyHardware::unknown_type
void unknown_type()
Analyse request and create reply when the header is unknown.
Definition: DummyHardware.cpp:368
uhal::tests::DummyHardware::status_packet_header
void status_packet_header()
Analyse request and create reply when an IPbus 2.0 status packet header is observed.
Definition: DummyHardware.cpp:411
uhal::tests::ADDRESSMASK
static const uint32_t ADDRESSMASK
The mask for the address space (size of the address space in one larger than this)
Definition: DummyHardware.hpp:58
uhal::tests::DummyHardwareInterface::mReplyDelay
boost::chrono::microseconds mReplyDelay
The delay in seconds between the request and reply of the first transaction.
Definition: DummyHardware.hpp:89
uhal::tests::DummyHardware::readConfigurationSpace
void readConfigurationSpace(const uint32_t &aAddress)
Analyse request and create reply when an incrementing "configuration space" read is observed.
Definition: DummyHardware.cpp:230
uhal::tests::DummyHardware::ni_read
void ni_read(const uint32_t &aAddress)
Analyse request and create reply when a non-incrementing read is observed.
Definition: DummyHardware.cpp:194
uhal::tests::DummyHardware::control_packet_header
bool control_packet_header()
Analyse request and create reply when an IPbus 2.0 control packet header is observed.
Definition: DummyHardware.cpp:381
uhal::tests::DummyHardwareInterface::DummyHardwareInterface
DummyHardwareInterface(const boost::chrono::microseconds &aReplyDelay)
Definition: DummyHardware.hpp:68
uhal::tests::BUFFER_SIZE
static const uint32_t BUFFER_SIZE
Size of the receive and reply buffers.
Definition: DummyHardware.hpp:62
uhal::tests::DummyHardware::mReply
std::vector< uint32_t > mReply
The buffer for the outgoing IPbus packet.
Definition: DummyHardware.hpp:201
uhal::tests::DummyHardwareInterface::setReplyDelay
void setReplyDelay(const DurationType &aDelay)
Definition: DummyHardware.hpp:82
uhal::HostToTargetInspector
Helper class to decode IPbus packets as passed from the Client to the Target.
Definition: IPbusInspector.hpp:55
uhal::tests::DummyHardware::mTrafficHistory
std::deque< uint8_t > mTrafficHistory
History of the IPbus 2.0 packet-types received.
Definition: DummyHardware.hpp:210
uhal::tests::DummyHardware::ni_write
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.
Definition: DummyHardware.cpp:248
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::tests::DummyHardware::mReplyHistory
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)
Definition: DummyHardware.hpp:204
IPbusInspector.hpp
uhal::tests::DummyHardwareInterface::stop
virtual void stop()=0
Stops this dummy hardware instance - i.e. makes the 'run' method return.
uhal::tests::DummyHardware::bot
void bot()
Analyse request and create reply when a Byte-OrderTransaction is observed.
Definition: DummyHardware.cpp:182
uhal::tests::DummyHardware::SetEndpoint
void SetEndpoint(const uint32_t &aAddress, const uint32_t &aValue)
Definition: DummyHardware.cpp:164
uhal::tests::DummyHardware::mMemory
std::vector< uint32_t > mMemory
The memory space of the virtual hardware.
Definition: DummyHardware.hpp:192
uhal::tests::DummyHardware::DummyHardware
DummyHardware(const uint32_t &aReplyDelay, const bool &aBigEndianHack)
Constructor.
Definition: DummyHardware.cpp:56
uhal::tests::DummyHardware::AnalyzeReceivedAndCreateReply
void AnalyzeReceivedAndCreateReply(const uint32_t &aByteCount)
Function which analyses the received IPbus packet and creates the suitable response.
Definition: DummyHardware.cpp:81
uhal::tests::DummyHardware
Abstract base class to emulate IPbus hardware.
Definition: DummyHardware.hpp:96
uhal::tests::DummyHardware::~DummyHardware
virtual ~DummyHardware()
Definition: DummyHardware.cpp:75
uhal::tests::DummyHardware::write
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.
Definition: DummyHardware.cpp:277
uhal::tests::DummyHardware::mLastPacketHeader
uint32_t mLastPacketHeader
The last sent packet header for the retry mechanism (IPbus 2.0 and above only)
Definition: DummyHardware.hpp:207
uhal::tests::DummyHardware::GetEndpoint
uint32_t GetEndpoint(const uint32_t &aAddress)
Definition: DummyHardware.cpp:173
uhal::tests::DummyHardware::unknown_packet_header
void unknown_packet_header()
Analyse request and create reply when an unknown IPbus 2.0 packet header is observed.
Definition: DummyHardware.cpp:475
uhal::tests::DummyHardwareInterface
Common abstract base class for IPbus 1.3 and 2.0 dummy hardware.
Definition: DummyHardware.hpp:66
uhal::tests::DummyHardware::mBigEndianHack
bool mBigEndianHack
Whether we are talking to an IPbus client which includes the big-endian hack.
Definition: DummyHardware.hpp:219
uhal::tests::REPLY_HISTORY_DEPTH
static const uint32_t REPLY_HISTORY_DEPTH
The size of the reply history for IPbus 2.0.
Definition: DummyHardware.hpp:60
uhal::tests::DummyHardware::mReceivedControlPacketHeaderHistory
std::deque< uint32_t > mReceivedControlPacketHeaderHistory
History of the received control packet headers.
Definition: DummyHardware.hpp:213
uhal::tests::DummyHardwareInterface::~DummyHardwareInterface
virtual ~DummyHardwareInterface()
Definition: DummyHardware.hpp:73
uhal::tests::DummyHardware::resend_packet_header
void resend_packet_header()
Analyse request and create reply when an IPbus 2.0 resend packet header is observed.
Definition: DummyHardware.cpp:456
uhal::tests::DummyHardwareInterface::run
virtual void run()=0
Function which "starts" the dummy hardware; does not return until the 'stop' method is called.
uhal::tests::DummyHardware::mSentControlPacketHeaderHistory
std::deque< uint32_t > mSentControlPacketHeaderHistory
History of the sent control packet headers.
Definition: DummyHardware.hpp:215
uhal::tests::DummyHardware::base_type
HostToTargetInspector< IPbus_major, IPbus_minor > base_type
Definition: DummyHardware.hpp:97
uhal::tests::DummyHardware::read
void read(const uint32_t &aAddress)
Analyse request and create reply when an incrementing read is observed.
Definition: DummyHardware.cpp:212
uhal::tests::DummyHardware::rmw_sum
void rmw_sum(const uint32_t &aAddress, const uint32_t &aAddend)
Analyse request and create reply when a read-modify-write sum is observed.
Definition: DummyHardware.cpp:306
uhal::tests::DummyHardware::mReceive
std::vector< uint32_t > mReceive
The buffer for the incoming IPbus packet.
Definition: DummyHardware.hpp:199
uhal::tests::DummyHardware::rmw_bits
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.
Definition: DummyHardware.cpp:336