예제 #1
0
 def _read(self, path):
     reader = RegisterMapReader()
     rmap = reader(path)
     print(rmap.config)
     print(rmap)
     assert rmap.config['regmap']['read_filler'].value == 0xDEADBEEF
     assert rmap['LEN'].address == 0x0
     assert rmap['START']['STB'].access == 'wo'
예제 #2
0
 def _write(self, path):
     # create regmap
     rmap_orig = RegisterMap()
     # write to file
     RegisterMapWriter()(path, rmap_orig)
     # read back
     rmap_test = RegisterMapReader()(path)
     assert rmap_test == rmap_orig
예제 #3
0
 def test_write(self, tmpdir):
     """Test of creating python regmap file."""
     rmap_path = 'tests/data/map.json'
     py_path = str(tmpdir.join('regs.py'))
     print('rmap_path:', rmap_path)
     print('py_path:', py_path)
     # read regmap
     rmap = RegisterMapReader()(rmap_path)
     # write output file
     PyRegisterMapWriter()(py_path, rmap)
     # read file and verify
     with open(py_path, 'r') as f:
         raw_str = ''.join(f.readlines())
     assert 'class RegMap:' in raw_str
예제 #4
0
 def test_md_write(self, tmpdir):
     """Test of creating markdown regmap file."""
     rmap_path = 'tests/data/map.json'
     md_path = str(tmpdir.join('regs.md'))
     print('rmap_path:', rmap_path)
     print('md_path:', md_path)
     # read regmap
     rmap = RegisterMapReader()(rmap_path)
     # write output file
     DocsWriter()(md_path, rmap)
     # read file and verify
     with open(md_path, 'r') as f:
         raw_str = ''.join(f.readlines())
     assert '## Register map' in raw_str
     assert 'Back to [Register map](#register-map).' in raw_str
예제 #5
0
 def _read_rmap(self, path):
     reader = RegisterMapReader()
     rmap = reader(path)
예제 #6
0
파일: custom.py 프로젝트: esynr3z/corsair
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Some custom processing based on corsair
"""
from corsair import RegisterMapReader, Jinja2Writer

# read register map description file
rmap = RegisterMapReader()('regmap.json')


# create custom writer, i.e. to write csv file
class CsvWriter(Jinja2Writer):
    def __call__(self, path, rmap):
        print("Write '%s' file with CsvWriter:" % path)
        j2_template = 'csv.j2'
        rmap._validate()

        j2_vars = {}
        j2_vars['rmap'] = rmap
        j2_vars['config'] = rmap.config

        self.render_to_file(j2_template, j2_vars, path, templates_path='.')


# generate CSV file from register map
CsvWriter()('rmap.csv', rmap)