From: Luke Kenneth Casson Leighton Date: Tue, 10 Jul 2018 04:10:23 +0000 (+0100) Subject: shuffle interface-reading code around to create InterfacesBase class X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1b6fa9b183cfa6c14a58c45cd899314a0bc7922b;p=pinmux.git shuffle interface-reading code around to create InterfacesBase class (use for myhdl as well) --- diff --git a/src/bsv/actual_pinmux.py b/src/bsv/actual_pinmux.py index 223d1f8..d2ce816 100644 --- a/src/bsv/actual_pinmux.py +++ b/src/bsv/actual_pinmux.py @@ -174,7 +174,7 @@ def init(p, ifaces): continue temp = transfn(cname) x = ifaces.getifacetype(temp) - #print (cname, temp, x) + print (cname, temp, x) assert x is not None, "ERROR: The signal : " + \ str(cname) + \ " of pinmap.txt isn't present \nin the current" + \ diff --git a/src/bsv/interface_decl.py b/src/bsv/interface_decl.py index b5e551b..5493d16 100644 --- a/src/bsv/interface_decl.py +++ b/src/bsv/interface_decl.py @@ -7,7 +7,7 @@ except ImportError: from bsv.wire_def import generic_io # special case from bsv.wire_def import muxwire # special case - +from ifacebase import InterfacesBase class Pin(object): """ pin interface declaration. @@ -271,78 +271,12 @@ class IOInterface(Interface): return generic_io.format(*args) -class Interfaces(UserDict): +class Interfaces(InterfacesBase): """ contains a list of interface definitions """ def __init__(self, pth=None): - self.pth = pth - self.ifacecount = [] - UserDict.__init__(self, {}) - if not pth: - return - ift = 'interfaces.txt' - if pth: - ift = os.path.join(pth, ift) - with open(ift, 'r') as ifile: - for ln in ifile.readlines(): - ln = ln.strip() - ln = ln.split("\t") - name = ln[0] # will have uart - count = int(ln[1]) # will have count of uart - # spec looks like this: - """ - [{'name': 'sda', 'outen': True}, - {'name': 'scl', 'outen': True}, - ] - """ - spec, ganged = self.read_spec(pth, name) - iface = Interface(name, spec, ganged, count == 1) - self.ifaceadd(name, count, iface) - - def getifacetype(self, fname): - # finds the interface type, e.g sd_d0 returns "inout" - for iface in self.values(): - typ = iface.getifacetype(fname) - if typ: - return typ - return None - - def ifaceadd(self, name, count, iface, at=None): - if at is None: - at = len(self.ifacecount) # ifacecount is a list - self.ifacecount.insert(at, (name, count)) # appends the list - # with (name,count) *at* times - self[name] = iface - - """ - will check specific files of kind peripheral.txt like spi.txt, - uart.txt in test directory - """ - - def read_spec(self, pth, name): - spec = [] - ganged = {} - fname = '%s.txt' % name - if pth: - ift = os.path.join(pth, fname) - with open(ift, 'r') as sfile: - for ln in sfile.readlines(): - ln = ln.strip() - ln = ln.split("\t") - name = ln[0] - d = {'name': name} # here we start to make the dictionary - if ln[1] == 'out': - d['action'] = True # adding element to the dict - elif ln[1] == 'inout': - d['outen'] = True - if len(ln) == 3: - bus = ln[2] - if bus not in ganged: - ganged[bus] = [] - ganged[bus].append(name) - spec.append(d) - return spec, ganged + InterfacesBase.__init__(self, Interface, pth) def ifacedef(self, f, *args): for (name, count) in self.ifacecount: diff --git a/src/ifacebase.py b/src/ifacebase.py new file mode 100644 index 0000000..2fb834c --- /dev/null +++ b/src/ifacebase.py @@ -0,0 +1,81 @@ +import os.path + +try: + from UserDict import UserDict +except ImportError: + from collections import UserDict + + +class InterfacesBase(UserDict): + """ contains a list of interface definitions + """ + + def __init__(self, ifacekls, pth=None): + self.pth = pth + self.ifacecount = [] + UserDict.__init__(self, {}) + if not pth: + return + ift = 'interfaces.txt' + if pth: + ift = os.path.join(pth, ift) + with open(ift, 'r') as ifile: + for ln in ifile.readlines(): + ln = ln.strip() + ln = ln.split("\t") + name = ln[0] # will have uart + count = int(ln[1]) # will have count of uart + # spec looks like this: + """ + [{'name': 'sda', 'outen': True}, + {'name': 'scl', 'outen': True}, + ] + """ + spec, ganged = self.read_spec(pth, name) + iface = ifacekls(name, spec, ganged, count == 1) + self.ifaceadd(name, count, iface) + + def getifacetype(self, fname): + # finds the interface type, e.g sd_d0 returns "inout" + for iface in self.values(): + typ = iface.getifacetype(fname) + if typ: + return typ + return None + + def ifaceadd(self, name, count, iface, at=None): + if at is None: + at = len(self.ifacecount) # ifacecount is a list + self.ifacecount.insert(at, (name, count)) # appends the list + # with (name,count) *at* times + self[name] = iface + + """ + will check specific files of kind peripheral.txt like spi.txt, + uart.txt in test directory + """ + + def read_spec(self, pth, name): + spec = [] + ganged = {} + fname = '%s.txt' % name + if pth: + ift = os.path.join(pth, fname) + with open(ift, 'r') as sfile: + for ln in sfile.readlines(): + ln = ln.strip() + ln = ln.split("\t") + name = ln[0] + d = {'name': name} # here we start to make the dictionary + if ln[1] == 'out': + d['action'] = True # adding element to the dict + elif ln[1] == 'inout': + d['outen'] = True + if len(ln) == 3: + bus = ln[2] + if bus not in ganged: + ganged[bus] = [] + ganged[bus].append(name) + spec.append(d) + return spec, ganged + diff --git a/src/myhdl/__init__.py b/src/myhdl/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/myhdl/pinmux_generator.py b/src/myhdl/pinmux_generator.py new file mode 100644 index 0000000..a31f97d --- /dev/null +++ b/src/myhdl/pinmux_generator.py @@ -0,0 +1,6 @@ +from parse import Parse + +def pinmuxgen(pth=None, verify=True): + p = Parse(pth, verify) + print p, dir(p) + diff --git a/src/pinmux_generator.py b/src/pinmux_generator.py index e34b4c5..6dcc20d 100644 --- a/src/pinmux_generator.py +++ b/src/pinmux_generator.py @@ -22,6 +22,7 @@ import sys from spec import modules, specgen, dummytest from bsv.pinmux_generator import pinmuxgen as bsvgen +from myhdl.pinmux_generator import pinmuxgen as myhdlgen def printhelp(): @@ -94,7 +95,7 @@ if __name__ == '__main__': else: specgen(of, output_dir, pinout, bankspec, pinspec, fixedpins) else: - gentypes = {'bsv': bsvgen} + gentypes = {'bsv': bsvgen, 'myhdl': myhdlgen } if output_type not in gentypes: print ("ERROR: output type '%s' does not exist" % output_type) printhelp()