From 32692639bf44e54f53e071af31b8c79a2d07cbbf Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Wed, 28 Mar 2018 15:16:06 +0100 Subject: [PATCH] remove manual dictionary, use interface txt file definitions --- src/bsv/actual_pinmux.py | 45 +++++++++++++++---------------------- src/bsv/interface_decl.py | 20 +++++++++++++++++ src/bsv/pinmux_generator.py | 2 +- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/bsv/actual_pinmux.py b/src/bsv/actual_pinmux.py index 76a0e2e..2be8fc9 100644 --- a/src/bsv/actual_pinmux.py +++ b/src/bsv/actual_pinmux.py @@ -5,23 +5,6 @@ except ImportError: maketrans = str.maketrans -# dictionary of properties of signals that are supported. -dictionary = { - "uart_rx" : "input", - "uart_tx" : "output", - "spi_sclk" : "output", - "spi_mosi" : "output", - "spi_ss" : "output", - "spi_miso" : "input", - "twi_sda" : "inout", - "twi_scl" : "inout", - "sd_clk": "output", - "sd_cmd": "output", - "sd_d": "inout", - "pwm_pwm": "output" -} - - # ============== common bsv templates ============ # # first argument is the io-cell number being assigned. # second argument is the mux value. @@ -44,7 +27,15 @@ def cn(idx): return "cell%s_mux" % str(idx) -def init(p): +def transfn(temp): + temp = temp.split('_') + if len(temp) == 2: + temp[0] = temp[0].translate(digits) + temp[0] = temp[0] .replace(' ', '') + return '_'.join(temp) + + +def init(p, ifaces): p.pinmux = ' ' global dedicated_wire for cell in p.muxed_cells: @@ -62,28 +53,28 @@ def init(p): # since the interfaces are always standard and cannot change from # user-to-user. Plus this also reduces human-error as well :) for i in range(0, len(cell) - 1): - temp = cell[i + 1].translate(digits) - temp = temp.replace(' ', '') - x = dictionary.get(temp) + cname = cell[i+1] + temp = transfn(cname) + x = ifaces.getifacetype(temp) + print cname, temp, x assert x is not None, "ERROR: The signal : " + \ - str(cell[i + 1]) + \ + str(cname) + \ " of pinmap.txt isn't present \nin the current" + \ " dictionary. Update dictionary or fix-typo." if x == "input": p.pinmux += \ - mux_wire.format(cell[0], i, "wr" + cell[i + 1]) + "\n" + mux_wire.format(cell[0], i, "wr" + cname) + "\n" elif x == "inout": p.pinmux += \ - mux_wire.format(cell[0], i, "wr" + cell[i + 1] + + mux_wire.format(cell[0], i, "wr" + cname + "_in") + "\n" # ============================================================ # # ================== Logic for dedicated pins ========= # for cell in p.dedicated_cells: - p.pinmux += " %s" % cn(cell[0]) + \ - "_out=" + cell[1] + "_io;\n" + p.pinmux += " %s_out=%s_io;\n" % (cn(cell[0]), cell[1]) temp = cell[1].translate(digits) - x = dictionary.get(temp) + x = ifaces.getifacetype(temp) if x == "input": pinmux = pinmux + \ dedicated_wire.format(cell[0], "wr" + cell[1]) + "\n" diff --git a/src/bsv/interface_decl.py b/src/bsv/interface_decl.py index 51e56b2..c10fa9a 100644 --- a/src/bsv/interface_decl.py +++ b/src/bsv/interface_decl.py @@ -99,6 +99,18 @@ class Interface(object): _p['name'] = self.pname(p['name']) self.pins.append(Pin(**_p)) + def getifacetype(self, name): + for p in self.pinspecs: + fname = "%s_%s" % (self.ifacename, p['name']) + print "search", self.ifacename, name, fname + if fname == name: + if p.get('action'): + return 'out' + elif p.get('outen'): + return 'inout' + return 'input' + return None + def pname(self, name): return '%s{0}_%s' % (self.ifacename, name) @@ -203,6 +215,14 @@ class Interfaces(UserDict): spec = self.read_spec(pth, name) self.ifaceadd(name, count, Interface(name, spec)) + 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) diff --git a/src/bsv/pinmux_generator.py b/src/bsv/pinmux_generator.py index 5957ad8..7f8f1a5 100644 --- a/src/bsv/pinmux_generator.py +++ b/src/bsv/pinmux_generator.py @@ -63,9 +63,9 @@ def pinmuxgen(pth=None, verify=True): """ p = Parse(pth, verify) - init(p) ifaces = Interfaces(pth) ifaces.ifaceadd('io', p.N_IO, io_interface, 0) + init(p, ifaces) bp = 'bsv_src' if pth: -- 2.30.2