Skip to content

nodamushi/nsvd-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NSVD Reader

C++ Header only CMSIS5 SVD read library.

This is an unofficial library.

License

These codes are licensed under CC0.

CC0

Language

C++14/17

Install

Add 'include' directory to your project include search path.

Dependency

This library uses the external libraries shown below to read XML files.

  1. Boost.PropertyTree (#include "nodamushi/svd/boost.hpp")
  2. Expat (#include "nodamushi/svd/expat.hpp")
  3. TinyXML-2 (#include "nodamushi/svd/tinyxml.hpp")

You can choose which library to use. You can also create your own XML reader.

Follow the license of the external library to use.

Feature

  1. read svd file and edit data
  2. resolve 'derivedFrom'
  3. visitor pattern

Document

https://nodamushi.github.io/nsvd-reader/

Sample Code

Here is a simple example code.

For other examples, see the files in the sample directory.

#include <string>
#include <iostream>

#include "nodamushi/svd.hpp"
#include "nodamushi/svd/normalize.hpp"

// select xml reader
#include "nodamushi/svd/boost.hpp"
//#include "nodamushi/svd/expat.hpp"
//#include "nodamushi/svd/tinyxml.hpp"

// visitor pattern
struct visitor
{
  using this_t =  visitor;
#undef  VISITOR_MEMBER
#define VISITOR_MEMBER
  SVD_VISITOR_INIT;
  //-------------------------------
  SVD_Visit_Interrupt(i)
  {
    if(i.name && i.value)
      std::cout << "interrupt:" <<*i.name << "," << *i.value<<std::endl;
    return result::CONTINUE;
  }

  SVD_Visit_Register(r)
  {
    count_register++;
    return result::CONTINUE;
  }
  
  int count_register=0;
};


int main(int argc,char** argv)
{
  std::string filename = argv[1];
  
  // read svd
  namespace svd=nodamushi::svd;
  svd::boost_svd_reader svd(filename);
  svd::Device<> device(svd);
  
  // edit data
  device.vendor = "Foo Bar.inc";
  device.description = "Foo Bar";
  
  // print SVD(xml)
  std::cout << device << std::endl;

  // get cpu name
  if(device.cpu && device.cpu->name){
    std::cout <<"Device CPU:"<< device.cpu->name.get() << std::endl;
  }else{
    std::cout << "Device CPU is not defined" << std::endl;
  }
  
  // use visitor pattern
  visitor v;
  visitor::accept(device,v);
  
  // normalize (resovle 'derivedFrom')
  namespace norm =nodamushi::svd::normalized;
  auto dptr = svd::normalize(device);
  // dptr is std::shared_ptr<norm::Device<std::string/std::string_view>>

  if(auto p = dptr->find_peripheral("UART2")){
    for(auto& r:p->registers){
      std::cout << "UART2 Register:" 
                << r.name << ","
                << r.get_address() << std::endl;
    }
  }
}

Releases

No releases published

Packages