soc/tools/remote/csr_builder: manage memory regions and some fixes on CSRRegister

This commit is contained in:
Florent Kermarrec 2015-11-23 19:13:37 +01:00
parent 254504e73f
commit 8ebffc563a
1 changed files with 19 additions and 2 deletions

View File

@ -17,6 +17,7 @@ class CSRRegister:
def __init__(self, readfn, writefn, name, addr, length, data_width, mode):
self.readfn = readfn
self.writefn = writefn
self.name = name
self.addr = addr
self.length = length
self.data_width = data_width
@ -24,7 +25,7 @@ class CSRRegister:
def read(self):
if self.mode not in ["rw", "ro"]:
raise KeyError(name + "register not readable")
raise KeyError(self.name + "register not readable")
datas = self.readfn(self.addr, length=self.length)
if isinstance(datas, int):
return datas
@ -37,19 +38,26 @@ class CSRRegister:
def write(self, value):
if self.mode not in ["rw", "wo"]:
raise KeyError(name + "register not writable")
raise KeyError(self.name + "register not writable")
datas = []
for i in range(self.length):
datas.append((value >> ((self.length-1-i)*self.data_width)) & (2**self.data_width-1))
self.writefn(self.addr, datas)
class CSRMemoryRegion:
def __init__(self, base, size):
self.base = base
self.size = size
class CSRBuilder:
def __init__(self, comm, csr_csv, csr_data_width):
self.csr_data_width = csr_data_width
self.constants = self.build_constants(csr_csv)
self.bases = self.build_bases(csr_csv)
self.regs = self.build_registers(csr_csv, comm.read, comm.write)
self.mems = self.build_memories(csr_csv)
def build_bases(self, csr_csv):
csv_reader = csv.reader(open(csr_csv), delimiter=',', quotechar='#')
@ -82,3 +90,12 @@ class CSRBuilder:
except:
d[name] = value
return CSRElements(d)
def build_memories(self, csr_csv):
csv_reader = csv.reader(open(csr_csv), delimiter=',', quotechar='#')
d = {}
for item in csv_reader:
group, name, base, size, dummy1 = item
if group == "memory_region":
d[name] = CSRMemoryRegion(int(base, 16), int(size))
return CSRElements(d)