μHAL (v2.6.5)
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 
125  void bot();
126 
131  void ni_read ( const uint32_t& aAddress );
132 
137  void read ( const uint32_t& aAddress );
138 
143  void readConfigurationSpace ( const uint32_t& aAddress );
144 
151  void ni_write ( const uint32_t& aAddress , std::vector<uint32_t>::const_iterator& aIt , const std::vector<uint32_t>::const_iterator& aEnd );
152 
159  void write ( const uint32_t& aAddress , std::vector<uint32_t>::const_iterator& aIt , const std::vector<uint32_t>::const_iterator& aEnd );
160 
166  void rmw_sum ( const uint32_t& aAddress , const uint32_t& aAddend );
167 
174  void rmw_bits ( const uint32_t& aAddress , const uint32_t& aAndTerm , const uint32_t& aOrTerm );
175 
179  void unknown_type();
180 
184  bool control_packet_header();
185 
189  void status_packet_header();
190 
194  void resend_packet_header();
195 
199  void unknown_packet_header();
200 
201 
202  private:
204  std::vector< uint32_t > mMemory;
205 
207  std::vector< uint32_t > mConfigurationSpace;
208 
209  protected:
211  std::vector< uint32_t > mReceive;
213  std::vector< uint32_t > mReply;
214 
216  std::deque< std::pair< uint32_t , std::vector< uint32_t > > > mReplyHistory;
217 
220 
222  std::deque< uint8_t > mTrafficHistory;
223 
225  std::deque< uint32_t > mReceivedControlPacketHeaderHistory;
227  std::deque< uint32_t > mSentControlPacketHeaderHistory;
228 
229  private:
232 
233  };
234  }
235 
236 }
237 
238 #endif
239 
240 
uint32_t mLastPacketHeader
The last sent packet header for the retry mechanism (IPbus 2.0 and above only)
void setReplyDelay(const DurationType &aDelay)
boost::chrono::microseconds mReplyDelay
The delay in seconds between the request and reply of the first transaction.
Helper class to decode IPbus packets as passed from the Client to the Target.
static const uint32_t BUFFER_SIZE
Size of the receive and reply buffers.
bool mBigEndianHack
Whether we are talking to an IPbus client which includes the big-endian hack.
std::deque< uint32_t > mReceivedControlPacketHeaderHistory
History of the received control packet headers.
DummyHardwareInterface(const boost::chrono::microseconds &aReplyDelay)
Common abstract base class for IPbus 1.3 and 2.0 dummy hardware.
HostToTargetInspector< IPbus_major, IPbus_minor > base_type
virtual void stop()=0
Stops this dummy hardware instance - i.e. makes the &#39;run&#39; method return.
std::vector< uint32_t > mReceive
The buffer for the incoming IPbus packet.
std::vector< uint32_t > mConfigurationSpace
The configuration space within the virtual hardware.
std::deque< uint32_t > mSentControlPacketHeaderHistory
History of the sent control packet headers.
static const uint32_t REPLY_HISTORY_DEPTH
The size of the reply history for IPbus 2.0.
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)
std::deque< uint8_t > mTrafficHistory
History of the IPbus 2.0 packet-types received.
Abstract base class to emulate IPbus hardware.
static const uint32_t ADDRESSMASK
The mask for the address space (size of the address space in one larger than this) ...
std::vector< uint32_t > mReply
The buffer for the outgoing IPbus packet.
c write(addr, xx[0])
virtual void run()=0
Function which "starts" the dummy hardware; does not return until the &#39;stop&#39; method is called...
std::vector< uint32_t > mMemory
The memory space of the virtual hardware.