Skip to content

Instantly share code, notes, and snippets.

@mithro
Created January 12, 2017 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mithro/a5ed4d86e53a81259b835ed559fcf2b1 to your computer and use it in GitHub Desktop.
Save mithro/a5ed4d86e53a81259b835ed559fcf2b1 to your computer and use it in GitHub Desktop.
Hacky script to check the csrs don't violate constraints in litex
#!/usr/bin/env python3
import sys
import csv
import pprint
print(sys.argv[1])
data = list(csv.reader(open(sys.argv[1],'r')))
bases = [x for x in data if x[0] == 'csr_base']
regs = [x for x in data if x[0] == 'csr_register']
mem_map = []
for _, name, loc, size, rw in regs:
mem_map.append((int(loc, 16), int(size), name))
mem_map.sort()
for i, (loc, size, name) in enumerate(mem_map[:-1]):
print("{:x} {} {}".format(loc, size, name))
nloc, nsize, nname = mem_map[i+1]
assert (loc + size*4) <= nloc, "{:x}+{} < {:x} ({} < {})".format(loc, size, nloc, name, nname)
assert loc < (0xe0000000 + (2**14)*4), "{:x} {}".format(loc, name)
regs_in_base = {}
for _, name, loc, size, rw in regs:
for _, bname, base, _, _ in bases:
if name.startswith(bname):
if bname not in regs_in_base:
regs_in_base[bname] = []
regs_in_base[bname].append((int(loc, 16), name[len(bname)+1:], int(size), rw))
for name, regs in regs_in_base.items():
num_regs = sum(size for loc, name, size, rw in regs)
assert num_regs < 200
print(name, num_regs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment