Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup in ChipFromSvdGenerator #84

Open
jacquelinekay opened this issue Nov 28, 2016 · 3 comments
Open

Cleanup in ChipFromSvdGenerator #84

jacquelinekay opened this issue Nov 28, 2016 · 3 comments

Comments

@jacquelinekay
Copy link

jacquelinekay commented Nov 28, 2016

I'm not the most Pythonic Pythonista who ever Pythoned but I have a few ideas for cleaning up the chip file generator.

It may make sense to use EmPy templates instead of concatenating formatted strings representing C++ code. It may make the process a bit more readable, since you could have a template file that looks a bit more like the resulting C++ code with placeholders that get filled in from the parsed xml. I have some experience with EmPy, so I could do this if others think it would be useful.

I couldn't find tests in place for results of the generator; if the chip generator gets rewritten it would be good to have those in place beforehand, to make sure the rewrite preserves functionality. Are there IP issues with adding example CMSIS SVD files to this repo for testing?

EDIT: just realized that the SVD files are in https://github.com/posborne/cmsis-svd/tree/master/data, cool. For now I can test any refactoring I do on my own by diffing against the state of the header files in master.

@CvRXX
Copy link

CvRXX commented Nov 29, 2016

I looked at a couple of svd files and most of them have licenses that allow distribution as long as you retain the license notice. So I think you could include these files as an example if you check the license first.

However I'm not sure if it is a good idea to put the files in this repo because they are subject to change. Maybe we could make a repo with all the svd files.

@odinthenerd
Copy link
Member

https://github.com/posborne/cmsis-svd has all the SVD files. Probably good to keep them there since there are many people using that. @kblomqvist also made a SVD parser which actually, in retrospect, looks more inline with my views on architecture, maybe there is something to be learned there.

These guys https://github.com/hackndev/zinc are also using the SVD parser for rust stuff, if we rewrite in such a way that we factor out the actual codegen templates then it could also benefit that community.

Essentially we need a property tree and a somewhat smart getProperty function which takes a key (or path) and returns a value. This getProperty function should also back track up the tree looking for default values defined in parents. Everything below that should be use case agnostic.

On top of that layer we walk the sub keys of "peripherals" creating a file for each then walk registers and fields.

@kblomqvist
Copy link

Hi. I have been working with my tool lately by refactoring its SVD parser and adding the missing elements. If there's something you would like to have there please let me know. The parser can be used standalone too, in case you just need the parser and not the templating engine.

from yasha.parsers.svd import SvdFile

with open('nrf51.svd', 'r') as file:
	svd = SvdFile(file)
	svd.parse()
	print(svd.peripherals[0])               # The first found peripheral
	print(svd.peripherals[0].registers[0])  # The first register in the first peripheral
	print(svd.peripherals_dict.keys())      # The names of all peripherals

Installation: pip install yasha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants