Giter VIP home page Giter VIP logo

nsvd-reader's Introduction

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;
    }
  }
}

nsvd-reader's People

Contributors

nodamushi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.