X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fbsv%2Fperipheral_gen%2Fbase.py;h=582a035016560882fa6e4dca52b8000786e1cb32;hb=9334e2230a72545dfa2f2ce3180b66546982cad0;hp=83af2c07e598f505f05e4cd7a41a88ed32e4dd98;hpb=6bdfa3add7d3d9a10ad5bb48809c0da80e9e41df;p=pinmux.git diff --git a/src/bsv/peripheral_gen/base.py b/src/bsv/peripheral_gen/base.py index 83af2c0..582a035 100644 --- a/src/bsv/peripheral_gen/base.py +++ b/src/bsv/peripheral_gen/base.py @@ -347,9 +347,8 @@ else""" else: spc = ck ck = self.get_clk_spc(ctype) - template = """\ -Ifc_sync#({0}) {1}_sync <-mksyncconnection( - {2}, {3});""" + template = "Ifc_sync#({0}) {1}_sync <-mksyncconnection(\n" + \ + " {2}, {3});" for p in self.peripheral.pinspecs: typ = p['type'] pname = p['name'] @@ -390,9 +389,8 @@ Ifc_sync#({0}) {1}_sync <-mksyncconnection( else: spc = ck ck = self.get_clk_spc(ctype) - template = """\ -Ifc_sync#({0}) {1}_sync <-mksyncconnection( - {2}, {3});""" + template = "Ifc_sync#({0}) {1}_sync <-mksyncconnection(\n" + \ + " {2}, {3});""" n_ = "{0}{1}".format(name, count) n_ = '{0}_{1}'.format(n_, pname) @@ -433,11 +431,9 @@ Ifc_sync#({0}) {1}_sync <-mksyncconnection( con = con.format(count, aname) return txt.format(con, aname, fabricname) - def mk_master_connection(self, count, fabricname, typ, name=None): + def mk_master_connection(self, name, count, fabricname, typ): if not self.has_axi_master(): return '' - if name is None: - name = self.name print "PBase mk_master_conn", self.name, count aname = self.axi_master_name(name, count, typ) ret = [] @@ -449,10 +445,10 @@ Ifc_sync#({0}) {1}_sync <-mksyncconnection( fabricname)) return '\n'.join(ret) - def mk_connection(self, count, fabricname, typ, name=None): - if name is None: - name = self.name - print "PBase mk_conn", self.name, count + def mk_connection(self, name, count, fabricname, typ, name_override=None): + if name_override: # needed for GPIO + name = name_override + print "PBase mk_conn", name, count ret = [] connections = self._mk_connection(name, count) if not isinstance(connections, list): @@ -669,8 +665,6 @@ class PeripheralInterfaces(object): ret = [] for (name, count) in self.ifacecount: for i in range(count): - iname = self.data[name].iname().format(i) - print "extfast", iname, self.is_on_fastbus(name, i) if self.is_on_fastbus(name, i): continue ret.append(self.data[name].extfastifinstance(name, i)) @@ -680,7 +674,6 @@ class PeripheralInterfaces(object): ret = [] for (name, count) in self.ifacecount: for i in range(count): - iname = self.data[name].iname().format(i) ret.append(self.data[name].extifinstance2(name, i)) return '\n'.join(li(list(filter(None, ret)), 8)) @@ -688,7 +681,6 @@ class PeripheralInterfaces(object): ret = [] for (name, count) in self.ifacecount: for i in range(count): - iname = self.data[name].iname().format(i) if not self.is_on_fastbus(name, i): continue ret.append(self.data[name].extifinstance(name, i)) @@ -829,16 +821,8 @@ class PeripheralInterfaces(object): def _mk_connection(self, fabric, typ, indent, master, *args): ret = [] for (name, count) in self.ifacecount: - for i in range(count): - if self.is_on_fastbus(name, i): - continue - if master: - txt = self.data[name].mk_master_connection(i, fabric, typ) - else: - txt = self.data[name].mk_connection(i, fabric, typ) - if name == 'gpioa': - print "txt", txt - ret.append(txt) + ret += list(MkConnection(self, name, count, + fabric, typ, master, *args)) return '\n'.join(li(list(filter(None, ret)), indent)) def mk_master_connection(self, *args): @@ -857,7 +841,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 @@ -874,12 +858,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 = [] @@ -931,11 +911,7 @@ class PeripheralInterfaces(object): def mk_ext_ifacedef(self): 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_ext_ifacedef(name, i) - ret.append(txt) + ret += list(MkExtIface(self, name, count)) return '\n'.join(li(list(filter(None, ret)), 8)) def mk_plic(self): @@ -965,11 +941,7 @@ class PeripheralInterfaces(object): def _mk_clk_con(self, ctype): 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_clk_con(name, i, ctype) - ret.append(txt) + ret += list(MkClkCon(self, name, count, ctype)) return '\n'.join(li(list(filter(None, ret)), 8)) def is_on_fastbus(self, name, i): @@ -980,6 +952,86 @@ class PeripheralInterfaces(object): 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): + #print self.item, self.args + 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 MkConnection(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, fabric, typ, master): + if master: + return self.ifaces.data[name].mk_master_connection(name, + i, fabric, typ) + return self.ifaces.data[name].mk_connection(name, i, fabric, typ) + +class MkExtIface(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): + return self.ifaces.data[name].mk_ext_ifacedef(name, i) + + +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 MkClkCon(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, ctype): + return self.ifaces.data[name]._mk_clk_con(name, i, ctype) + + class PFactory(object): def getcls(self, name): from uart import uart