+class InterfaceBus(InterfaceFmt):
+
+ def __init__(self, pins, is_inout, namelist, bitspec, filterbus):
+ InterfaceFmt.__init__(self)
+ self.namelist = namelist
+ self.bitspec = bitspec
+ self.fbus = filterbus # filter identifying which are bus pins
+ self.pins_ = pins
+ self.is_inout = is_inout
+ self.buspins = filter(lambda x: x.name_.startswith(self.fbus),
+ self.pins_)
+ self.nonbuspins = filter(lambda x: not x.name_.startswith(self.fbus),
+ self.pins_)
+
+ def get_nonbuspins(self):
+ return self.nonbuspins
+
+ def get_buspins(self):
+ return self.buspins
+
+ def get_n_iopinsdiv(self):
+ return 3 if self.is_inout else 1
+
+ def ifacepfmt(self, *args):
+ pins = self.get_nonbuspins()
+ res = '\n'.join(map(self.ifacepfmtdecpin, pins)).format(*args)
+ res = res.format(*args)
+
+ pins = self.get_buspins()
+ plen = len(pins) / self.get_n_iopinsdiv()
+
+ res += '\n'
+ template = " interface {1}#(%s) {2};\n" % self.bitspec
+ for i, n in enumerate(self.namelist):
+ if not n:
+ continue
+ ftype = 'Get' if i == 2 else "Put"
+ res += template.format(plen, ftype, n)
+
+ return "\n" + res
+
+ def ifacedef2(self, *args):
+ pins = self.get_nonbuspins()
+ res = '\n'.join(map(self.ifacedef2pin, pins))
+ res = res.format(*args)
+
+ pins = self.get_buspins()
+ plen = len(pins) / self.get_n_iopinsdiv()
+ for pin in pins:
+ print "ifbus pins", pin.name_, plen
+ bitspec = self.bitspec.format(plen)
+ print self
+ return '\n' + res + self.vectorifacedef2(
+ pins, plen, self.namelist, bitspec, *args)
+
+ def ifacedef3pin(self, idx, pin):
+ decfn = self.ifacefmtdecfn2
+ outfn = self.ifacefmtoutfn
+ # print pin, pin.outenmode
+ if pin.outenmode:
+ decfn = self.ifacefmtdecfn3
+ outfn = self.ifacefmtoutenfn
+ return pin.ifacedef3(idx, outfn, self.ifacefmtinfn,
+ decfn)
+
+
+class InterfaceMultiBus(object):
+
+ def __init__(self, pins):
+ self.multibus_specs = []
+ self.nonbuspins = pins
+ self.nonb = self.add_bus(False, [], '', "xxxxxxxnofilter")
+
+ def add_bus(self, is_inout, namelist, bitspec, filterbus):
+ pins = self.nonbuspins
+ buspins = filter(lambda x: x.name_.startswith(filterbus), pins)
+ nbuspins = filter(lambda x: not x.name_.startswith(filterbus), pins)
+ self.nonbuspins = nbuspins
+ b = InterfaceBus(buspins, is_inout,
+ namelist, bitspec, filterbus)
+ print is_inout, namelist, filterbus, buspins
+ self.multibus_specs.append(b)
+ self.multibus_specs[0].pins_ = nbuspins
+ self.multibus_specs[0].nonbuspins = nbuspins
+
+ def ifacepfmt(self, *args):
+ res = ''
+ #res = Interface.ifacepfmt(self, *args)
+ for b in self.multibus_specs:
+ res += b.ifacepfmt(*args)
+ return res
+
+ def ifacedef2(self, *args):
+ res = ''
+ #res = Interface.ifacedef2(self, *args)
+ for b in self.multibus_specs:
+ res += b.ifacedef2(*args)
+ return res
+
+
+class InterfaceLCD(InterfaceBus, Interface):
+
+ def __init__(self, *args):
+ Interface.__init__(self, *args)
+ InterfaceBus.__init__(self, self.pins, False, ['data_out', None, None],
+ "Bit#({0})", "out")
+
+
+class InterfaceSDRAM(InterfaceMultiBus, Interface):
+
+ def __init__(self, ifacename, pinspecs, ganged=None, single=False):
+ Interface.__init__(self, ifacename, pinspecs, ganged, single)
+ InterfaceMultiBus.__init__(self, self.pins)
+ self.add_bus(False, ['dqm', None, None],
+ "Bit#({0})", "sdrdqm")
+ self.add_bus(True, ['d_out', 'd_out_en', 'd_in'],
+ "Bit#({0})", "sdrd")
+ self.add_bus(False, ['ad', None, None],
+ "Bit#({0})", "sdrad")
+ self.add_bus(False, ['ba', None, None],
+ "Bit#({0})", "sdrba")
+
+ def ifacedef2(self, *args):
+ return InterfaceMultiBus.ifacedef2(self, *args)
+
+
+class InterfaceFlexBus(InterfaceMultiBus, Interface):
+
+ def __init__(self, ifacename, pinspecs, ganged=None, single=False):
+ Interface.__init__(self, ifacename, pinspecs, ganged, single)
+ InterfaceMultiBus.__init__(self, self.pins)
+ self.add_bus(True, ['ad_out', 'ad_out_en', 'ad_in'],
+ "Bit#({0})", "ad")
+ self.add_bus(False, ['bwe', None, None],
+ "Bit#({0})", "bwe")
+ self.add_bus(False, ['tsiz', None, None],
+ "Bit#({0})", "tsiz")
+ self.add_bus(False, ['cs', None, None],
+ "Bit#({0})", "cs")
+
+ def ifacedef2(self, *args):
+ return InterfaceMultiBus.ifacedef2(self, *args)
+
+
+class InterfaceSD(InterfaceBus, Interface):
+
+ def __init__(self, *args):
+ Interface.__init__(self, *args)
+ InterfaceBus.__init__(self, self.pins, True, ['out', 'out_en', 'in'],
+ "Bit#({0})", "d")
+
+
+class InterfaceNSPI(InterfaceBus, Interface):
+
+ def __init__(self, *args):
+ Interface.__init__(self, *args)
+ InterfaceBus.__init__(self, self.pins, True,
+ ['io_out', 'io_out_en', 'io_in'],
+ "Bit#({0})", "io")
+
+
+class InterfaceEINT(Interface):
+ """ uses old-style (non-get/put) for now
+ """
+
+ def ifacepfmt(self, *args):
+ res = '\n'.join(map(self.ifacefmtdecpin, self.pins)).format(*args)
+ return '\n' + res # pins is a list
+
+ def ifacedef2(self, *args):
+ return self.ifacedef(*args)
+
+
+class InterfaceGPIO(InterfaceBus, Interface):
+ """ note: the busfilter cuts out everything as the entire set of pins
+ is a bus, but it's less code. get_nonbuspins returns empty list.
+ """
+
+ def __init__(self, ifacename, pinspecs, ganged=None, single=False):
+ Interface.__init__(self, ifacename, pinspecs, ganged, single)
+ InterfaceBus.__init__(self, self.pins, True, ['out', 'out_en', 'in'],
+ "Vector#({0},Bit#(1))", ifacename[-1])
+
+
+class Interfaces(InterfacesBase, PeripheralInterfaces):