Skip to content

Commit

Permalink
[enh] generate SVD CSR enumeratedValue based on fields values
Browse files Browse the repository at this point in the history
  • Loading branch information
chmousset committed Sep 26, 2023
1 parent 3d956af commit f8e00fc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions litex/soc/integration/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,28 @@ def print_svd_register(csr, csr_address, description, length, svd):
svd.append(' <lsb>{}</lsb>'.format(field.offset))
svd.append(' <description><![CDATA[{}]]></description>'.format(
reflow(field.description)))

if field.values is not None:
svd_v = []
for value in field.values:
if len(value) == 3:
name, description, value = value[1], value[2], value[0]
else:
name, description, value = value[1].split()[0], value[1], value[0]
name = re.search("[_A-Za-z0-9]+", name).group(0)
matches = re.findall("[+]?(0[xX][0-9a-fA-F]+|(#|0b)[01xX]+|[0-9]+)", value)
if len(matches) != 1 or len(name) == 0:
continue
value = matches[0][0]
svd_v.append(' <enumeratedValue>')
svd_v.append(' <name>{}</name>'.format(name))
svd_v.append(' <description>{}</description>'.format(description))
svd_v.append(' <value>{}</value>'.format(value))
svd_v.append(' </enumeratedValue>')
if len(svd_v) != 0:
svd.append(' <enumeratedValues>')
svd += svd_v
svd.append(' </enumeratedValues>')
svd.append(' </field>')
else:
field_size = csr.size
Expand Down

0 comments on commit f8e00fc

Please sign in to comment.