NSVD Reader  0.0.1
Device.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 #ifndef __NODAMUSHI_SVD_NORMALIZED_DEVICE_HPP__
10 #define __NODAMUSHI_SVD_NORMALIZED_DEVICE_HPP__
11 
12 # include <ostream>
13 # include <memory>
16 
17 namespace nodamushi{
18 namespace svd{
19 namespace normalized{
20 
46 template<typename STRREF>struct Device
47 {
54 
56  STRREF vendor;
58  STRREF vendorID;
60  STRREF name;
62  STRREF series;
64  STRREF version;
66  STRREF description;
68  STRREF licenseText;
74  uint32_t addressUnitBits;
76  uint32_t width;
78  uint32_t size;
84  uint64_t resetValue;
86  uint64_t resetMask;
89 
99 
100  //----------------------------------------------------------
107  template<typename STR>
108  node_ptr<void> find(const ::nodamushi::svd::path<STR>& p)
109  {
110  if(p){
111  string_ref n = p[0];
112  if(auto c=__find_helper(peripherals,n)){
113  if(p.size() == 1)return c;
114  else return c->find(p,1);
115  }
116  }
117  return {};
118  }
126  {
128  return find(pa);
129  }
130 
136  template<typename STR>
137  node_ptr<Peripheral> find_peripheral(const ::nodamushi::svd::path<STR>& p)
138  {
139  if(p.size() == 1){
140  string_ref n = p[0];
141  return __find_helper(peripherals,n);
142  }
143  return {};
144  }
151  {
153  return find_peripheral(pa);
154  }
155 
161  template<typename STR>
162  node_ptr<Cluster> find_cluster(const ::nodamushi::svd::path<STR>& p)
163  {
164  if(p.size() > 1){
165  string_ref n = p[0];
166  if(auto c=__find_helper(peripherals,n))
167  return c->find_cluster(p,1);
168  }
169  return {};
170  }
177  {
179  return find_cluster(pa);
180  }
181 
187  template<typename STR>
188  node_ptr<Register> find_register(const ::nodamushi::svd::path<STR>& p)
189  {
190  if(p.size() > 1){
191  string_ref n = p[0];
192  if(auto c=__find_helper(peripherals,n))
193  return c->find_register(p,1);
194  }
195  return {};
196  }
203  {
205  return find_register(pa);
206  }
207 
213  template<typename STR>
214  node_ptr<Field> find_field(const ::nodamushi::svd::path<STR>& p)
215  {
216  if(p.size() > 2){
217  string_ref n = p[0];
218  if(auto c=__find_helper(peripherals,n))
219  return c->find_field(p,1);
220  }
221  return {};
222  }
229  {
231  return find_field(pa);
232  }
233 
234  //----------------------------------------------------------
239  template<typename NORMALIZED>
240  Device(const NORMALIZED& n)
241  :vendor(n.svd.vendor.get("")),
242  vendorID(n.svd.vendorID.get("")),
243  name(n.svd.name.get("")),
244  series(n.svd.series.get("")),
245  version(n.svd.version.get("")),
246  description(n.svd.description.get("")),
247  licenseText(n.svd.licenseText.get("")),
250  addressUnitBits(n.svd.addressUnitBits.get(8)), // default is 8?
251  width(n.svd.width.get(32)), // default is 32?
252  size(n.svd.size.get(32)), // default is 32?
253  access(n.svd.access.get(Access{})),
254  protection(n.svd.protection.get(Protection{})),
255  resetValue(n.svd.resetValue.get(0)),
256  resetMask(n.svd.resetMask.get(~(uint64_t)0)),
257  cpu(n.svd.cpu),
258  peripherals(n.peripherals.size())
259  {
260  for(const auto& p:n.peripherals)
261  peripherals.emplace_back(p);
262  }
263 
268  {
269  if(this_ptr.get() == this){
271  }
272  }
274  uint64_t get_address()const{return 0;}
276  uint32_t get_size()const{return size;}
278  uint64_t get_resetValue()const{ return resetValue; }
280  uint64_t get_resetMask()const{ return resetMask;}
282  Access get_access()const{ return access;}
286  constexpr const void* get_parent()const noexcept{return nullptr;}
288  constexpr const void* get_parent2()const noexcept{return nullptr;}
289 };
290 
291 
292 
293 //---------- Visitor --------------------
295 {
296  namespace nv = ::nodamushi::visitor;
297  using r = nv::result;
298  // visit Peripheral
299  r ret;
300  ret = CONTROLLER::apply(t.cpu,v);
301  if(ret==r::BREAK)return r::BREAK;
302  else if(ret == r::SKIP)return r::CONTINUE;
303  ret = CONTROLLER::apply(t.peripherals,v);
304  if(ret==r::BREAK)return r::BREAK;
305  return r::CONTINUE;
306 }};
307 //----------------------------------------
308 
309 }}}
310 
311 #endif // __NODAMUSHI_SVD_NORMALIZED_DEVICE_HPP__
node_ptr< Register > find_register(const ::nodamushi::svd::path< STR > &p)
find register
Definition: Device.hpp:188
std::shared_ptr< T > node_ptr
node_ptr< Cluster > find_cluster(string_ref p)
find peripheral
Definition: Device.hpp:176
node_ptr< Register > find_register(string_ref p)
find register
Definition: Device.hpp:202
__NX_NORM_HANDLE_VISIT(Enumeration)
Definition: Enumeration.hpp:90
constexpr const void * get_parent() const noexcept
allways return nullptr
Definition: Device.hpp:286
Protection protection
<protection>
Definition: Device.hpp:82
uint64_t get_resetValue() const
return resetValue
Definition: Device.hpp:278
uint64_t get_address() const
allways return 0
Definition: Device.hpp:274
uint32_t get_size() const
return size
Definition: Device.hpp:276
const std::string & string_ref
Definition: string_type.hpp:44
node_ptr< Cluster > find_cluster(const ::nodamushi::svd::path< STR > &p)
find peripheral
Definition: Device.hpp:162
Access get_access() const
return access
Definition: Device.hpp:282
node_ptr< Peripheral > find_peripheral(string_ref p)
find peripheral
Definition: Device.hpp:150
STRREF headerSystemFilename
<headerSystemFilename>
Definition: Device.hpp:70
container class decralation
STRREF headerDefinitionsPrefix
<headerDefinitionsPrefix>
Definition: Device.hpp:72
node_ptr< Peripheral > find_peripheral(const ::nodamushi::svd::path< STR > &p)
find peripheral
Definition: Device.hpp:137
uint32_t addressUnitBits
<addressUnitBits>
Definition: Device.hpp:74
void update_parent_of_children(list< T > &l, node_ptr< You > &you)
Device(const NORMALIZED &n)
Don't use this constructor.this constructor is for normalizer class.
Definition: Device.hpp:240
node_ptr< void > find(string_ref p)
find path element
Definition: Device.hpp:125
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
node_ptr< Field > find_field(string_ref p)
find field
Definition: Device.hpp:228
STRREF licenseText
<licenseText>
Definition: Device.hpp:68
normalized CPU and SAU
uint64_t resetValue
<resetValue>
Definition: Device.hpp:84
uint64_t get_resetMask() const
return resetMask
Definition: Device.hpp:280
normalized peripheral element
node_ptr< void > find(const ::nodamushi::svd::path< STR > &p)
find path element
Definition: Device.hpp:108
node_ptr< Field > find_field(const ::nodamushi::svd::path< STR > &p)
find field
Definition: Device.hpp:214
vector<pointer<T>>.
Definition: boxvec.hpp:75
constexpr const void * get_parent2() const noexcept
allways return nullptr
Definition: Device.hpp:288
Protection
<protection> enum
Definition: Protection.hpp:23
STRREF description
<description>
Definition: Device.hpp:66
normalized field element
Definition: Field.hpp:32
node_ptr< R > __find_helper(list< R > &v, string_ref n)
dot '.' separeted path.
Definition: path.hpp:16
void update_parent(node_ptr< Device > &this_ptr)
Definition: Device.hpp:267
Protection get_protection() const
return protection
Definition: Device.hpp:284
list< Peripheral > peripherals
peripheral list Peripheral class does not prohibit copying, but basically it should be treated with a...
Definition: Device.hpp:98
uint64_t resetMask
<resetMask>
Definition: Device.hpp:86