Arti Zirk
244fdbc35c
subrepo: subdir: "libopencm3" merged: "f5813a54" upstream: origin: "https://github.com/libopencm3/libopencm3" branch: "master" commit: "f5813a54" git-subrepo: version: "0.4.3" origin: "???" commit: "???"
26 lines
941 B
Python
Executable File
26 lines
941 B
Python
Executable File
#!/usr/bin/env python2
|
|
|
|
import sys
|
|
import yaml
|
|
|
|
registers = yaml.load(open(sys.argv[1], 'r'))
|
|
|
|
for register_name, register in registers.iteritems():
|
|
print('/* --- %s values %s */' % (register_name, '-' * (50 - len(register_name))))
|
|
print
|
|
fields = register['fields']
|
|
#for field_name, field in sorted(fields.items(), lambda x, y: cmp(x[1]['lsb'], y[1]['lsb'])):
|
|
for field_name, field in fields.items():
|
|
mask_bits = (1 << field['width']) - 1
|
|
print('/* %s: %s */' % (field_name, field['description']))
|
|
print('#define %s_%s_SHIFT (%d)' % (
|
|
register_name, field_name, field['lsb'],
|
|
))
|
|
print('#define %s_%s_MASK (0x%x << %s_%s_SHIFT)' % (
|
|
register_name, field_name, mask_bits, register_name, field_name,
|
|
))
|
|
print('#define %s_%s(x) ((x) << %s_%s_SHIFT)' % (
|
|
register_name, field_name, register_name, field_name,
|
|
))
|
|
print
|