μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
44#include <iterator>
45#include <stdexcept>
46#include <string>
47#include <unordered_map>
48#include <vector>
49
51#include "uhal/definitions.hpp"
53#include "uhal/ValMem.hpp"
54
55
56namespace uhal
57{
58 class HwInterface;
59 class NodeTreeBuilder;
60 class DerivedNodeFactory;
61
62 namespace exception
63 {
65 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." )
67 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." )
69 UHAL_DEFINE_EXCEPTION_CLASS ( NoBranchFoundWithGivenUID , "Exception class to handle the case where a child ID was requested which does not exist." )
71 UHAL_DEFINE_EXCEPTION_CLASS ( BulkTransferOnSingleRegister , "Exception class to handle the case where a bulk read or write was performed on a single register." )
73 UHAL_DEFINE_EXCEPTION_CLASS ( BulkTransferRequestedTooLarge , "Exception class to handle the case where requested bulk read or write was too large." )
75 UHAL_DEFINE_EXCEPTION_CLASS ( BulkTransferOffsetRequestedForFifo , "Exception class to handle the case where an offset was requested into a FIFO." )
77 UHAL_DEFINE_EXCEPTION_CLASS ( BulkTransferOffsetRequestedForSingleRegister , "Exception class to handle the case where an offset was requested into a Single Register." )
79 UHAL_DEFINE_EXCEPTION_CLASS ( BadNodeCast , "Exception class to handle the case of an attempt to cast a node to the wrong type." )
80 }
81
82
84 class Node
85 {
86 private:
87 friend class HwInterface;
88 friend class NodeTreeBuilder;
89 friend class DerivedNodeFactory;
90
91 public:
92 class const_iterator : public std::iterator< std::forward_iterator_tag , Node , ptrdiff_t, const Node* , const Node& >
93 {
94 friend class Node;
95 typedef std::deque< std::vector< Node* >::const_iterator > stack;
96
97 public:
99 virtual ~const_iterator();
100
101 const_iterator ( const Node* aBegin );
102 const_iterator ( const const_iterator& aOrig );
103
104 const Node& value() const;
105 const Node& operator*() const;
106 const Node* operator->() const;
107
108 bool next();
109 const_iterator& operator++();
110 const_iterator operator++ ( int );
111
112 bool operator== ( const const_iterator& aIt ) const;
113 bool operator!= ( const const_iterator& aIt ) const;
114
115 private:
116 const Node* mBegin;
118 };
119
120 private:
121 friend class const_iterator;
122
123 protected:
125 Node ( );
126
131 Node ( const Node& aNode );
132
138 virtual Node& operator= ( const Node& aNode );
139
144 virtual Node* clone() const;
145
146 public:
148 virtual ~Node();
149
150 const_iterator begin() const;
151
152 const_iterator end() const;
153
159 bool operator == ( const Node& aNode ) const;
160
161 bool hasNode ( const std::string& aId ) const;
162
168 const Node& getNode ( const std::string& aId ) const;
169
175 template< typename T>
176 const T& getNode ( const std::string& aId ) const;
177
182 std::vector<std::string> getNodes() const;
183
189 std::vector<std::string> getNodes ( const std::string& aRegex ) const;
190
195 const std::string& getId() const;
196
201 std::string getPath() const;
202
207 const uint32_t& getAddress() const;
208
213 const uint32_t& getMask() const;
214
219 const defs::BlockReadWriteMode& getMode() const;
220
225 const uint32_t& getSize() const;
226
231 const defs::NodePermission& getPermission() const;
232
237 const std::string& getTags() const;
238
243 const std::string& getDescription() const;
244
249 const std::string& getModule() const;
250
255 const std::unordered_map< std::string, std::string >& getParameters() const;
256
261 const std::unordered_map< std::string, std::string >& getFirmwareInfo() const;
262
268 void stream ( std::ostream& aStr , std::size_t aIndent = 0 ) const;
269
275 ValHeader write ( const uint32_t& aValue ) const;
276
282 ValHeader writeBlock ( const std::vector< uint32_t >& aValues ) const;
283
290 ValHeader writeBlockOffset ( const std::vector< uint32_t >& aValues , const uint32_t& aOffset ) const;
291
296 ValWord< uint32_t > read ( ) const;
297
303 ValVector< uint32_t > readBlock ( const uint32_t& aSize ) const;
304
311 ValVector< uint32_t > readBlockOffset ( const uint32_t& aSize , const uint32_t& aOffset ) const;
312
317 ClientInterface& getClient() const;
318
320 std::vector<const Node*> getLineage(const Node& aAncestor) const;
321
323 bool isChildOf(const Node& aParent) const;
324
325 private:
326
327 std::string getRelativePath(const Node& aAncestor) const;
328
330 void getAncestors ( std::deque< const Node* >& aPath ) const;
331
332 private:
333
336
338 std::string mUid;
339
341 uint32_t mPartialAddr;
343 uint32_t mAddr;
344
346 uint32_t mMask;
352 uint32_t mSize;
353
355 std::string mTags;
356
358 std::string mDescription;
359
361 std::string mModule;
362
364 std::string mClassName;
365
367 std::unordered_map< std::string, std::string > mParameters;
368
370 std::unordered_map< std::string, std::string > mFirmwareInfo;
371
374
376 std::vector< Node* > mChildren;
377
379 std::unordered_map< std::string , Node* > mChildrenMap;
380 };
381
382 std::ostream& operator<< ( std::ostream& aStr , const uhal::Node& aNode );
383}
384
385
387
388#endif
Wrapper to generate a new Python exception type.
Definition: pybind11.h:2517
\rst Holds a reference to a Python object (no reference counting)
Definition: pytypes.h:194
Definition: pytypes.h:1167
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
A singleton class to register derived nodes, and create instances of them later NOTE!...
A class which bundles a node tree and an IPbus client interface together providing everything you nee...
Definition: HwInterface.hpp:56
std::deque< std::vector< Node * >::const_iterator > stack
Definition: Node.hpp:95
const Node * mBegin
Definition: Node.hpp:116
A heirarchical node for navigating heirarchical firmwares.
Definition: Node.hpp:85
std::unordered_map< std::string, std::string > mFirmwareInfo
parameters to infer the VHDL address decoding
Definition: Node.hpp:370
std::vector< Node * > mChildren
The direct children of the node.
Definition: Node.hpp:376
uint32_t mAddr
The register address with which this node is associated.
Definition: Node.hpp:343
defs::BlockReadWriteMode mMode
Whether the node represents a single register, a block of registers or a block-read/write port.
Definition: Node.hpp:350
uint32_t mMask
The mask to be applied if this node is a sub-field, rather than an entire register.
Definition: Node.hpp:346
std::unordered_map< std::string, Node * > mChildrenMap
Helper to assist look-up of a particular child node, given a name.
Definition: Node.hpp:379
std::string mUid
The Unique ID of this node.
Definition: Node.hpp:338
std::string mClassName
Class name used to construct the derived node type.
Definition: Node.hpp:364
std::string mDescription
Optional string which the user can specify.
Definition: Node.hpp:358
std::unordered_map< std::string, std::string > mParameters
Additional parameters of the node.
Definition: Node.hpp:367
defs::NodePermission mPermission
The read/write access permissions of this node.
Definition: Node.hpp:348
std::string mModule
The name of the module in which the current node resides.
Definition: Node.hpp:361
uint32_t mPartialAddr
The register address with which this node is associated.
Definition: Node.hpp:341
uint32_t mSize
The maximum size available to a block read/write.
Definition: Node.hpp:352
std::string mTags
Optional string which the user can specify.
Definition: Node.hpp:355
HwInterface * mHw
The parent hardware interface of which this node is a child (or rather decendent)
Definition: Node.hpp:335
Node * mParent
The parent of the current node.
Definition: Node.hpp:373
A class to build a node tree from an address table file.
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:147
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:59
BlockReadWriteMode
define whether transactions target a single register, a block of registers, a block-read/write port o...
Definition: definitions.hpp:53
NodePermission
define Read and Write permissions of a uhal Node
Definition: definitions.hpp:50
std::ostream & operator<<(std::ostream &aStr, const uhal::HttpResponseType &aHttpResponse)
T cast(const handle &handle)
Definition: cast.h:1050
bool operator==(const HashMe &lhs, const HashMe &rhs)