module = modules[pinspec]
fname = os.path.join(output_dir or '', "%s.mdwn" % pinspec)
+ pyname = os.path.join(output_dir or '', "%s_pins.py" % pinspec)
d = os.path.split(fname)[0]
if not os.path.exists(d):
os.makedirs(d)
with open(fname, "w") as of:
- ps = module.pinspec()
- pinout, bankspec, pin_spec, fixedpins = ps.write(of)
- if testing:
- dummytest(ps, output_dir, output_type)
- else:
- specgen(of, output_dir, pinout,
- bankspec, ps.muxwidths, pin_spec, fixedpins, ps.fastbus)
- module.pinparse(ps, pinspec)
+ with open(pyname, "w") as pyf:
+ ps = module.pinspec()
+ pm = module.pinparse(ps, pinspec)
+ pinout, bankspec, pin_spec, fixedpins = ps.write(pyf, of, pm)
+ if testing:
+ dummytest(ps, output_dir, output_type)
+ else:
+ specgen(of, output_dir, pinout,
+ bankspec, ps.muxwidths, pin_spec, fixedpins,
+ ps.fastbus)
else:
if output_type == 'bsv':
from bsv.pinmux_generator import pinmuxgen as gentypes
from spec.interfaces import Pinouts
from spec.ifaceprint import display, display_fns, check_functions
-from spec.ifaceprint import display_fixed
+from spec.ifaceprint import display_fixed, python_dict_fns
from collections import OrderedDict
self.scenarios.append((name, needed, eint, pwm, descriptions))
- def write(self, of):
+ def write(self, pyf, of, pinmap):
+
+ fns = python_dict_fns(pyf, pinmap, self, self.function_names)
+
of.write("""# Pinouts (PinMux)
auto-generated by [[pinouts.py]]
with open(os.path.join(pth, '%s.txt' % k.lower()), 'w') as g:
if len(s0.pingroup) == 1: # only one function, grouped higher
for ks in s.keys(): # grouped by interface
- #assert False, "TODO, single-function"
+ assert False, "TODO, single-function"
fntype = 'inout' # XXX TODO
k = s[ks].suffix
k_ = k.lower()
if fname.startswith(n):
return n
+def map_name(pinmap, fn, fblower, pin, rename):
+ if not rename:
+ if pin[:-1].isdigit():
+ print "map name digit", pin, fn, fblower
+ if fn in ['PWM', 'EINT', 'VDD', 'VSS']:
+ return fn.lower() + pin.lower()
+ if fn == 'GPIO':
+ return 'gpio' + pin[1:].lower()
+ return pin.lower()
+ pin = pin.lower()
+ if fn == 'GPIO':
+ pk = '%s%s_%s' % (fblower, pin[0], pin[:-1])
+ elif pin[:-1].isdigit() and fn != 'EINT':
+ pk = '%s%s_out' % (fblower, pin[:-1])
+ else:
+ pk = '%s_%s' % (fblower, pin[:-1])
+ print "map name", pk, fblower, pinmap.has_key(pk)
+ if not pinmap.has_key(pk):
+ return pin.lower()
+ remapped = pinmap[pk]
+ uscore = remapped.find('_')
+ if uscore == -1:
+ return pin.lower()
+ fn, pin = remapped[:uscore], remapped[uscore+1:] + pin[-1]
+ return pin.lower()
+
+def python_pindict(of, pinmap, pins, function_names, dname, remap):
+
+ of.write("%s = {\n" % dname)
+
+ for k, pingroup in pins.byspec.items():
+ (a, n) = k
+ if n.isdigit():
+ a = "%s%s" % (a, n)
+ fblower = a.lower()
+ of.write(" '%s': [ " % fblower)
+ count = 0
+ for i, p in enumerate(pingroup):
+ of.write("'%s', " % map_name(pinmap, k[0], fblower, p, remap))
+ count += 1
+ if count == 4 and i != len(pingroup)-1:
+ of.write("\n ")
+ count = 0
+ of.write("],\n")
+ print " dict %s" % dname, a, n, pingroup
+ of.write("}\n\n")
+
+def python_dict_fns(of, pinmap, pins, function_names):
+ of.write("# auto-generated by Libre-SOC pinmux program: do not edit\n")
+ of.write("# python src/pinmux_generator.py -v -s {spec} -o {output}\n")
+
+ fn_names = function_names.keys()
+ fns = {}
+
+ fnidx = list(fns.keys())
+ fnidx.sort(key=fnsplit)
+
+ print "python fnames", function_names
+ print "python speckeys", pins.byspec.keys()
+ print "python dict fns", dir(pins.gpio)
+ print pins.gpio.pinfn('', '')
+ print pins.pwm.pinfn('', '')
+ print pins.sdmmc.pinfn('', '')
+ print "by spec", pins.byspec
+ print pinmap
+
+ python_pindict(of, {}, pins, function_names, 'pindict', False)
+ python_pindict(of, pinmap, pins, function_names, 'litexdict', True)
+
def display_fns(of, bankspec, pins, function_names):
fn_names = function_names.keys()
prefix = self.fname
if start and limit: # limit turns into an offset from start
limit = start + limit
+ sk = (self.fname, suffix)
+ print "pingroup pre", sk, pingroup
pingroup = pingroup[start:limit] # see comment in spec.pinfunctions
+ print "pingroup post", sk, pingroup
+ if self.pinouts.byspec.has_key(sk):
+ self.pinouts.byspec[sk] += pingroup
+ else:
+ self.pinouts.byspec[sk] = deepcopy(pingroup)
pins = Pins(prefix, pingroup, self.bankspec,
suffix, offs, bank, mux,
spec, origsuffix=suffix, gangedgrp=gangedgroup)
self.fnspec = {}
self.ganged = {}
self.clocks = {}
+ self.byspec = {}
for fname, pinfn in pinspec:
if isinstance(pinfn, tuple):
name, pinfn = pinfn
# map pins to litex name conventions, primarily for use in coriolis2
def pinparse(psp, pinspec):
p = Parse(pinspec, verify=False)
+ pinmap = {}
print p.muxed_cells
print p.muxed_cells_bank
clk = psp.clocks[domain]
if clk.lower() in orig_name: # TODO, might over-match
clocks[domain] = name
+ # record remap
+ pinmap[orig_name] = name
# HACK!
pe[13] = 'p_vddeck_0'
+ #pe[0] = 'p_vddeck_1'
pe[23] = 'p_vsseck_0'
+ #pe[31] = 'p_vsseck_1'
pw[10] = 'p_vddick_0'
pw[17] = 'p_vssick_0'
with open("ls180/litex_pinpads.json", "w") as f:
f.write(chip)
+ return pinmap