From 8ebffc563a9522899b6b2c3da41f2b8d68754763 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Mon, 23 Nov 2015 19:13:37 +0100 Subject: [PATCH] soc/tools/remote/csr_builder: manage memory regions and some fixes on CSRRegister --- litex/soc/tools/remote/csr_builder.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/litex/soc/tools/remote/csr_builder.py b/litex/soc/tools/remote/csr_builder.py index 942929152..e30a18ad6 100644 --- a/litex/soc/tools/remote/csr_builder.py +++ b/litex/soc/tools/remote/csr_builder.py @@ -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)