μHAL (v2.6.5)
Part of the IPbus software repository
Node.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 
40 #ifndef _uhal_Node_hpp_
41 #define _uhal_Node_hpp_
42 
43 #include "uhal/log/exception.hpp"
44 #include "uhal/definitions.hpp"
45 #include "uhal/ValMem.hpp"
46 #include "uhal/ClientInterface.hpp"
47 
48 #include "boost/unordered_map.hpp"
49 
50 #include <vector>
51 #include <string>
52 #include <iterator>
53 
54 
55 namespace uhal
56 {
57  class HwInterface;
58  class NodeTreeBuilder;
59  class DerivedNodeFactory;
60 
61  namespace exception
62  {
64  UHAL_DEFINE_EXCEPTION_CLASS ( WriteAccessDenied , "Exception class to handle the case where a write was performed on a register which does not allow write access." )
66  UHAL_DEFINE_EXCEPTION_CLASS ( ReadAccessDenied , "Exception class to handle the case where a read was performed on a register which does not allow read access." )
68  UHAL_DEFINE_EXCEPTION_CLASS ( NoBranchFoundWithGivenUID , "Exception class to handle the case where a child ID was requested which does not exist." )
70  UHAL_DEFINE_EXCEPTION_CLASS ( BulkTransferOnSingleRegister , "Exception class to handle the case where a bulk read or write was performed on a single register." )
72  UHAL_DEFINE_EXCEPTION_CLASS ( BulkTransferRequestedTooLarge , "Exception class to handle the case where requested bulk read or write was too large." )
74  UHAL_DEFINE_EXCEPTION_CLASS ( BulkTransferOffsetRequestedForFifo , "Exception class to handle the case where an offset was requested into a FIFO." )
76  UHAL_DEFINE_EXCEPTION_CLASS ( BulkTransferOffsetRequestedForSingleRegister , "Exception class to handle the case where an offset was requested into a Single Register." )
78  UHAL_DEFINE_EXCEPTION_CLASS ( BadNodeCast , "Exception class to handle the case of an attempt to cast a node to the wrong type." )
79  }
80 
81 
83  class Node
84  {
85  private:
86  friend class HwInterface;
87  friend class NodeTreeBuilder;
88  friend class DerivedNodeFactory;
89 
90  public:
91  class const_iterator : public std::iterator< std::forward_iterator_tag , Node , ptrdiff_t, const Node* , const Node& >
92  {
93  friend class Node;
94  typedef std::deque< std::deque< Node* >::const_iterator > stack;
95 
96  public:
98  virtual ~const_iterator();
99 
100  const_iterator ( const Node* aBegin );
101  const_iterator ( const const_iterator& aOrig );
102 
103  const Node& value() const;
104  const Node& operator*() const;
105  const Node* operator->() const;
106 
107  bool next();
108  const_iterator& operator++();
109  const_iterator operator++ ( int );
110 
111  bool operator== ( const const_iterator& aIt ) const;
112  bool operator!= ( const const_iterator& aIt ) const;
113 
114  private:
115  const Node* mBegin;
116  stack mItStack;
117  };
118 
119  private:
120  friend class const_iterator;
121 
122  protected:
126  Node ( );
127 
132  Node ( const Node& aNode );
133 
139  virtual Node& operator= ( const Node& aNode );
140 
145  virtual Node* clone() const;
146 
147  public:
151  virtual ~Node();
152 
153  const_iterator begin() const;
154  const_iterator end() const;
155 
156 
162  bool operator == ( const Node& aNode ) const;
163 
164 
170  const Node& getNode ( const std::string& aId ) const;
171 
172 
178  template< typename T>
179  const T& getNode ( const std::string& aId ) const;
180 
181 
186  std::vector<std::string> getNodes() const;
187 
188 
194  std::vector<std::string> getNodes ( const std::string& aRegex ) const;
195 
196 
201  const std::string& getId() const;
202 
207  std::string getPath() const;
208 
213  const uint32_t& getAddress() const;
214 
219  const uint32_t& getMask() const;
220 
225  const defs::BlockReadWriteMode& getMode() const;
226 
231  const uint32_t& getSize() const;
232 
237  const defs::NodePermission& getPermission() const;
238 
243  const std::string& getTags() const;
244 
249  const std::string& getDescription() const;
250 
255  const std::string& getModule() const;
256 
261  const boost::unordered_map< std::string, std::string >& getParameters() const;
262 
267  const boost::unordered_map< std::string, std::string >& getFirmwareInfo() const;
268 
274  void stream ( std::ostream& aStr , std::size_t aIndent = 0 ) const;
275 
276 
282  ValHeader write ( const uint32_t& aValue ) const;
283 
289  ValHeader writeBlock ( const std::vector< uint32_t >& aValues ) const;
290 
297  ValHeader writeBlockOffset ( const std::vector< uint32_t >& aValues , const uint32_t& aOffset ) const;
298 
303  ValWord< uint32_t > read ( ) const;
304 
310  ValVector< uint32_t > readBlock ( const uint32_t& aSize ) const;
311 
318  ValVector< uint32_t > readBlockOffset ( const uint32_t& aSize , const uint32_t& aOffset ) const;
319 
320 
325  ClientInterface& getClient() const;
326 
327 
328  private:
332  void getAncestors ( std::deque< const Node* >& aPath ) const;
333 
334  private:
335 
338 
340  std::string mUid;
341 
343  uint32_t mPartialAddr;
345  uint32_t mAddr;
346 
348  uint32_t mMask;
354  uint32_t mSize;
355 
357  std::string mTags;
358 
360  std::string mDescription;
361 
363  std::string mModule;
364 
366  std::string mClassName;
367 
369  boost::unordered_map< std::string, std::string > mParameters;
370 
372  boost::unordered_map< std::string, std::string > mFirmwareInfo;
373 
375  Node* mParent;
376 
378  std::deque< Node* > mChildren;
379 
381  boost::unordered_map< std::string , Node* > mChildrenMap;
382  };
383 
384  std::ostream& operator<< ( std::ostream& aStr , const uhal::Node& aNode );
385 }
386 
387 
389 
390 #endif
A class to build a node tree from an Address table file NOTE! This is a factory method and must be Mu...
hw getNode("SUBSYSTEM1.SUBMODULE.REG").write(x)
boost::unordered_map< std::string, std::string > mFirmwareInfo
parameters to infer the VHDL address decoding
Definition: Node.hpp:372
HwInterface * mHw
The parent hardware interface of which this node is a child (or rather decendent) ...
Definition: Node.hpp:337
std::string mClassName
Class name used to construct the derived node type.
Definition: Node.hpp:366
A class which bundles a node tree and an IPbus client interface together providing everything you nee...
Definition: HwInterface.hpp:59
std::deque< std::deque< Node *>::const_iterator > stack
Definition: Node.hpp:94
defs::NodePermission mPermission
The read/write access permissions of this node.
Definition: Node.hpp:350
c writeBlock(addr, xx)
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:64
defs::BlockReadWriteMode mMode
Whether the node represents a single register, a block of registers or a block-read/write port...
Definition: Node.hpp:352
std::string mTags
Optional string which the user can specify.
Definition: Node.hpp:357
uint32_t mSize
The maximum size available to a block read/write.
Definition: Node.hpp:354
std::string mDescription
Optional string which the user can specify.
Definition: Node.hpp:360
std::string mModule
The name of the module in which the current node resides.
Definition: Node.hpp:363
boost::unordered_map< std::string, std::string > mParameters
Additional parameters of the node.
Definition: Node.hpp:369
uint32_t mPartialAddr
The register address with which this node is associated.
Definition: Node.hpp:343
uint32_t mMask
The mask to be applied if this node is a sub-field, rather than an entire register.
Definition: Node.hpp:348
A heirarchical node for navigating heirarchical firmwares.
Definition: Node.hpp:83
std::deque< Node *> mChildren
The direct children of the node.
Definition: Node.hpp:378
A singleton class to register derived nodes, and create instances of them later NOTE! This is a facto...
uint32_t mAddr
The register address with which this node is associated.
Definition: Node.hpp:345
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
std::string mUid
The Unique ID of this node.
Definition: Node.hpp:340
const Node * mBegin
Definition: Node.hpp:115
NodePermission
define Read and Write permissions of a uhal Node
Definition: definitions.hpp:50
Node * mParent
The parent of the current node.
Definition: Node.hpp:375
BlockReadWriteMode
define whether transactions target a single register, a block of registers, a block-read/write port o...
Definition: definitions.hpp:53
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:156
boost::unordered_map< std::string, Node *> mChildrenMap
Helper to assist look-up of a particular child node, given a name.
Definition: Node.hpp:381
std::ostream & operator<<(std::ostream &aStr, const uhal::HttpResponseType &aHttpResponse)
c write(addr, xx[0])