From 576b3a5920cb80608ee01afd17a0d69ea0312fbc Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 13 Apr 2021 17:02:52 +0100 Subject: [PATCH] add pin-to-litex json map --- src/pinmux_generator.py | 10 ++++++++-- src/spec/base.py | 3 +-- src/spec/ifaceprint.py | 33 +++++++++++++++++++++++++++++---- src/spec/ls180.py | 6 +----- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/pinmux_generator.py b/src/pinmux_generator.py index 94357b0..04d3cf9 100644 --- a/src/pinmux_generator.py +++ b/src/pinmux_generator.py @@ -19,6 +19,7 @@ import getopt import os.path import sys +import json from spec import modules, specgen, dummytest @@ -88,15 +89,20 @@ if __name__ == '__main__': with open(fname, "w") as of: with open(pyname, "w") as pyf: ps = module.pinspec() + pm, chip = module.pinparse(ps, pinspec) + litexmap = ps.pywrite(pyf, pm) pinout, bankspec, pin_spec, fixedpins = ps.write(of) + chip['litex.map'] = litexmap + chip = json.dumps(chip) + with open("%s/litex_pinpads.json" % pinspec, "w") as f: + f.write(chip) + if testing: dummytest(ps, output_dir, output_type) else: specgen(of, output_dir, pinout, bankspec, ps.muxwidths, pin_spec, fixedpins, ps.fastbus) - pm = module.pinparse(ps, pinspec) - ps.pywrite(pyf, pm) else: if output_type == 'bsv': from bsv.pinmux_generator import pinmuxgen as gentypes diff --git a/src/spec/base.py b/src/spec/base.py index c6f4ccb..3207b40 100644 --- a/src/spec/base.py +++ b/src/spec/base.py @@ -38,8 +38,7 @@ class PinSpec(Pinouts): self.scenarios.append((name, needed, eint, pwm, descriptions)) def pywrite(self, pyf, pinmap): - - python_dict_fns(pyf, pinmap, self, self.function_names) + return python_dict_fns(pyf, pinmap, self, self.function_names) def write(self, of): diff --git a/src/spec/ifaceprint.py b/src/spec/ifaceprint.py index 3d3cfb4..808985c 100644 --- a/src/spec/ifaceprint.py +++ b/src/spec/ifaceprint.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from copy import deepcopy - +from collections import OrderedDict def display(of, pins, banksel=None, muxwidth=4): of.write("""\ @@ -89,6 +89,7 @@ def map_name(pinmap, fn, fblower, pin, rename): def python_pindict(of, pinmap, pins, function_names, dname, remap): + res = OrderedDict() of.write("\n%s = OrderedDict()\n" % dname) for k, pingroup in pins.byspec.items(): @@ -97,9 +98,12 @@ def python_pindict(of, pinmap, pins, function_names, dname, remap): a = "%s%s" % (a, n) fblower = a.lower() of.write("%s['%s'] = [ " % (dname, fblower)) + res[fblower] = [] count = 0 for i, p in enumerate(pingroup): - of.write("'%s', " % map_name(pinmap, k[0], fblower, p, remap)) + name = map_name(pinmap, k[0], fblower, p, remap) + res[fblower].append(name) + of.write("'%s', " % name) count += 1 if count == 4 and i != len(pingroup)-1: of.write("\n ") @@ -107,6 +111,7 @@ def python_pindict(of, pinmap, pins, function_names, dname, remap): of.write("]\n") print " dict %s" % dname, a, n, pingroup of.write("\n\n") + return res def python_dict_fns(of, pinmap, pins, function_names): of.write("# auto-generated by Libre-SOC pinmux program: do not edit\n") @@ -129,8 +134,28 @@ def python_dict_fns(of, pinmap, pins, function_names): print "by spec", pins.byspec print pinmap - python_pindict(of, {}, pins, function_names, 'pindict', False) - python_pindict(of, pinmap, pins, function_names, 'litexdict', True) + pd = python_pindict(of, {}, pins, function_names, 'pindict', False) + ld = python_pindict(of, pinmap, pins, function_names, 'litexdict', True) + + print "pd", pd + print "ld", ld + # process results and create name map + litexmap = OrderedDict() + for k in pd.keys(): + pl = pd[k] + ll = ld[k] + for pname, lname in zip(pl, ll): + pname = "%s_%s" % (k, pname[:-1]) # strip direction +/-/* + lname = lname[:-1] # strip direction +/-/* + if k in ['eint', 'pwm', 'gpio', 'vdd', 'vss']: # sigh + lname = "%s_%s" % (k, lname) + litexmap[pname] = lname + print "litexmap", litexmap + of.write("litexmap = {\n") + for k, v in litexmap.items(): + of.write("\t'%s': '%s',\n" % (k, v)) + of.write("}\n") + return litexmap def display_fns(of, bankspec, pins, function_names): diff --git a/src/spec/ls180.py b/src/spec/ls180.py index e69a131..15f9353 100644 --- a/src/spec/ls180.py +++ b/src/spec/ls180.py @@ -418,8 +418,4 @@ def pinparse(psp, pinspec): 'chip.n_extpower': n_extpower, } - chip = json.dumps(chip) - with open("ls180/litex_pinpads.json", "w") as f: - f.write(chip) - - return pinmap + return pinmap, chip -- 2.30.2