C++ Header only CMSIS5 SVD read library.
This is an unofficial library.
These codes are licensed under CC0.
C++14/17
Add 'include' directory to your project include search path.
This library uses the external libraries shown below to read XML files.
- Boost.PropertyTree (#include "nodamushi/svd/boost.hpp")
- Expat (#include "nodamushi/svd/expat.hpp")
- 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.
- read svd file and edit data
- resolve 'derivedFrom'
- visitor pattern
https://nodamushi.github.io/nsvd-reader/
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;
}
}
}