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'
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
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
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
def _read_rmap(self, path): reader = RegisterMapReader() rmap = reader(path)
#!/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)