NSVD Reader  0.0.1
Field.hpp
Go to the documentation of this file.
1 
5 /*
6  * These codes are licensed under CC0.
7  * http://creativecommons.org/publicdomain/zero/1.0/
8  */
9 
10 #ifndef __NODAMUSHI_SVD_NORMALIZED_FIELD_HPP__
11 #define __NODAMUSHI_SVD_NORMALIZED_FIELD_HPP__
12 
18 
19 # include "nodamushi/svd/Access.hpp"
22 
23 namespace nodamushi{
24 namespace svd{
25 namespace normalized{
26 
32 template<typename STRREF>struct Field
33 {
38 
40 
41 
42 private:
43  p_ptr parent;
44 public:
48  std::string name;
54  STRREF description;
79  //-------------------------------------------
84  unsigned int lsb()const{return bit.lsb();}
89  unsigned int msb()const{return bit.msb();}
90 
95  node_ptr<Register const> get_parent()const noexcept{return parent.lock();}
100  node_ptr<Register> get_parent()noexcept{return parent.lock();}
101 
106 
109  return access.get<this_t,get_default_fieldaccess<this_t>>(this);
110  }
113  return modifiedWriteValues.get<this_t,get_default_access<this_t>>(this);
114  }
117  return readAction.get<this_t,get_default_readAction<this_t>>(this);
118  }
123  uint64_t get_resetValue(){
124  if(auto p = get_parent()){
125  return bit.get(p->get_resetValue() & p->get_resetMask());
126  }
127  return 0;
128  }
129  //-------------------------------------------
136  template<typename STR>
137  node_ptr<Enumeration> find(const ::nodamushi::svd::path<STR>& p,size_t pindex=0)
138  {
139  const size_t ps = p.size();
140  if(ps == pindex+1){
141  string_ref n = p[pindex];
142  auto i = enumeratedValues.ptr_begin(),e = enumeratedValues.ptr_end();
143  while(i!=e){
144  auto c = *i;
145  if(c->name == n)
146  return c;
147  ++i;
148  }
149  }
150  return {};
151  }
152 
153  //-----------------------------------------------------------------
157  template<typename T>
158  Field(const T& n): // don't change name
159  parent(),
160  derivedFrom(),
161  name(n.name),
162  dim(n.dim),
163  bit(n),
168  {
169  if(n.svd.derivedFrom)
170  derivedFrom = *n.svd.derivedFrom;
171  for(const auto& c:n.enumeratedValues)
172  enumeratedValues.emplace_back(c);
173  }
174 
175  void update_parent(p_ptr& new_parent,node_ptr<this_t>& me)
176  {
177  parent = new_parent;
178  }
180  constexpr void* get_parent2()const noexcept{return nullptr;}
181 
182 };
183 //---------- Visitor --------------------
185 {
186  namespace nv = ::nodamushi::visitor;
187  using r = nv::result;
188  r ret;
189  ret = CONTROLLER::apply(t.enumeratedValues,v);
190  if(ret == r::BREAK)return ret;
191  return r::CONTINUE;
192 }};
193 //--------------------------------------------
194 
195 
196 }}} // end namespace svd
197 
198 #endif // __NODAMUSHI_SVD_NORMALIZED_FIELD_HPP__
node_ptr< Register const > get_parent() const noexcept
get parent register pointer
Definition: Field.hpp:95
std::shared_ptr< T > node_ptr
node_ptr< Peripheral > get_peripheral() noexcept
find the Peripheral to which this field belongs.
Definition: Field.hpp:105
dim_info dim
dimemtion information object.
Definition: Field.hpp:50
helper for copy derivedFrom element
#define __NORMALIZED_DERIVED_FROM(name)
__NORMALIZED_DERIVED_FROM(name)
__NX_NORM_HANDLE_VISIT(Enumeration)
Definition: Enumeration.hpp:90
Define <readAction> enum.
uint64_t get(uint64_t v)
get the bit number of bit-range.
Definition: bit_range.hpp:45
normalized bit_range
node_ptr< Enumeration > find(const ::nodamushi::svd::path< STR > &p, size_t pindex=0)
find path element
Definition: Field.hpp:137
STRREF description
description
Definition: Field.hpp:54
optional like container
parent_ptr< Register > p_ptr
Definition: Field.hpp:39
ReadAction get_readAction() const
resolve the value of readAction and return it.
Definition: Field.hpp:116
const std::string & string_ref
Definition: string_type.hpp:44
nullable< ReadAction > readAction
<readAction>
Definition: Field.hpp:69
constexpr unsigned int lsb() const noexcept
Definition: bit_range.hpp:35
<access> enum
container class decralation
nullable< ModifiedWriteValues > modifiedWriteValues
<modifiedWriteValues>
Definition: Field.hpp:64
path< STRREF > derivedFrom
derivedFrom Path
Definition: Field.hpp:46
list< Enumeration > enumeratedValues
<enumeratedValues> list Enumeration class does not prohibit copying, but basically it should be treat...
Definition: Field.hpp:78
node_ptr< Peripheral const > get_peripheral() const noexcept
find the Peripheral to which this field belongs.
Definition: Field.hpp:103
std::weak_ptr< Parent > parent_ptr
unsigned int msb() const
get msb bit index.
Definition: Field.hpp:89
uint64_t get_resetValue()
get reset value
Definition: Field.hpp:123
node_ptr< Register > get_parent() noexcept
get parent register pointer
Definition: Field.hpp:100
T get(T defaultValue) const noexcept
Definition: nullable.hpp:70
constexpr unsigned int msb() const noexcept
Definition: bit_range.hpp:34
unsigned int lsb() const
get lsb bit index.
Definition: Field.hpp:84
result apply(T &t)
Definition: imple.hpp:197
Access
Read/Write Access type enum.<access> Read-Write/Read-Only/Write-Only/Write-Once/Read- Write Once.
Definition: Access.hpp:26
dim,dimIndex,array information object.
Definition: dim_info.hpp:27
ModifiedWriteValues get_modifiedWriteValues() const
resolve the value of modifiedWriteValues and return it.
Definition: Field.hpp:112
Access get_access() const
resolve the value of access and return it.
Definition: Field.hpp:108
nullable< Access > access
<access> type.
Definition: Field.hpp:59
normalized peripheral element
vector<pointer<T>>.
Definition: boxvec.hpp:75
std::string name
name of this field
Definition: Field.hpp:48
bit_range bit
bit range
Definition: Field.hpp:52
normalized field element
Definition: Field.hpp:32
Define <modifiedWriteValues> enum.
node_ptr< Peripheral< STRREF > > find_parent_peripheral(O< STRREF > &o)
dimension information
ReadAction
<register>.<readAction> enum
Definition: ReadAction.hpp:26
void update_parent(p_ptr &new_parent, node_ptr< this_t > &me)
Definition: Field.hpp:175
normalized <enumeratedValues> element. iterable
Definition: Enumeration.hpp:27
constexpr void * get_parent2() const noexcept
allways return nullptr
Definition: Field.hpp:180