From a51649d0ae94dd90f292892f09ed66c0e181c1d4 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 5 Aug 2018 15:41:13 +0100 Subject: [PATCH] convert to class style for peripheral gen --- src/bsv/peripheral_gen/base.py | 48 +++++++++++++++++++++++++++++----- src/bsv/peripheral_gen/gpio.py | 2 +- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/bsv/peripheral_gen/base.py b/src/bsv/peripheral_gen/base.py index 6127a4e..1ac32c3 100644 --- a/src/bsv/peripheral_gen/base.py +++ b/src/bsv/peripheral_gen/base.py @@ -851,7 +851,7 @@ class PeripheralInterfaces(object): for i in range(count): if self.is_on_fastbus(name, i): continue - res = self.data[name].mk_cellconn(cellcount, name, i) + res = self.data[name].mk_cellconn(name, i, cellcount) if not res: continue (txt, cellcount) = res @@ -868,12 +868,8 @@ class PeripheralInterfaces(object): def _mk_pincon(self, typ): ret = [] for (name, count) in self.ifacecount: - for i in range(count): - if self.is_on_fastbus(name, i): - continue - txt = self.data[name]._mk_pincon(name, i, typ) - ret.append(txt) - return '\n'.join(li(list(filter(None, ret)), 4)) + ret += list(MkPinCon(self, name, count, typ)) + return '\n'.join(li(list(ret), 4)) def mk_dma_irq(self): ret = [] @@ -973,6 +969,44 @@ class PeripheralInterfaces(object): return iname not in self.fastbus return iname in self.fastbus +class IfaceIter(object): + + def __init__(self, name, count, *args): + self.i = 0 + self.name = name + self.maxcount = count + self.args = args + + def __iter__(self): + return self + + def __next__(self): + while True: + if self.i > self.maxcount: + raise StopIteration + if self.check(self.name, self.i): + res = self.item(self.name, self.i, *self.args) + if res: + self.i += 1 + return res + self.i += 1 + + def next(self): + return self.__next__() + + +class MkPinCon(IfaceIter): + + def __init__(self, ifaces, name, count, *args): + self.ifaces = ifaces + IfaceIter.__init__(self, name, count, *args) + + def check(self, name, i): + return not self.ifaces.is_on_fastbus(name, i) + + def item(self, name, i, typ): + return self.ifaces.data[name]._mk_pincon(name, i, typ) + class PFactory(object): def getcls(self, name): diff --git a/src/bsv/peripheral_gen/gpio.py b/src/bsv/peripheral_gen/gpio.py index d67ab8f..73fd2a3 100644 --- a/src/bsv/peripheral_gen/gpio.py +++ b/src/bsv/peripheral_gen/gpio.py @@ -63,7 +63,7 @@ class gpio(PBase): return name[3:] return name[4:] - def mk_cellconn(self, cellnum, name, count): + def mk_cellconn(self, name, count, cellnum): ret = [] bank = self.mksuffix(name, count) txt = "pinmux.mux_lines.cell{0}_mux(mux{1}.mux_config.mux[{2}]);" -- 2.30.2