X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fspec%2Fgen.py;h=492ba535074087c93ffb4a8d879082ba6b2c64d7;hb=c492bfb3a86f01e770414f52c1f5884c1bc80cea;hp=3c66f34a7c8412caa90ac9b87debe5e51e97b130;hpb=c34740c39c4747c0472dec67ae09dffa1336eed1;p=pinmux.git diff --git a/src/spec/gen.py b/src/spec/gen.py index 3c66f34..492ba53 100644 --- a/src/spec/gen.py +++ b/src/spec/gen.py @@ -1,53 +1,113 @@ import os +import json import os.path from spec.interfaces import Pinouts -def specgen(pth, pinouts, bankspec, fixedpins): +def specgen(of, pth, pinouts, bankspec, muxwidths, pinbanks, fixedpins, + configs): """ generates a specification of pinouts (tsv files) - for reading in by pinmux + for reading in by pinmux. + + files generated: + * interfaces.txt - contains name and number of interfaces + * {interfacename}.txt - contains name of pin, type, and bus + + type may be in, out or inout. + if type is "inout" then a THIRD optional parameter of type + "bus" indicates whether the bus is ganged together. in + future this may be "bus1", "bus2" and so on if an interface + contains more than one ganged group. + + basically if the function needs to control whether a group + of pins shall be switched from input to output (as opposed + to the *pinmux* via user control deciding that), bus is + the way to indicate it. """ pth = pth or '' #print bankspec.keys() #print fixedpins.keys() + #print pinouts.ganged.items() if not os.path.exists(pth): os.makedirs(pth) + with open(os.path.join(pth, 'configs.txt'), 'w') as f: + f.write("%s\n" % json.dumps(configs)) + with open(os.path.join(pth, 'interfaces.txt'), 'w') as f: for k in pinouts.fnspec.keys(): s = pinouts.fnspec[k] - f.write("%s\t%d\n" % (k.lower(), len(s))) - s0 = s[s.keys()[0]] # hack, take first + line = [k.lower(), str(len(s))] + line = '\t'.join(line) + f.write("%s\n" % line) + s0 = s[list(s.keys())[0]] # hack, take first + gangedgroup = pinouts.ganged[k] 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 - k = "%s_%s" % (s[ks].fname, s[ks].suffix) + assert False, "TODO, single-function" + fntype = 'inout' # XXX TODO + k = s[ks].suffix k_ = k.lower() g.write("%s\t%s\n" % (k_, fntype)) else: for pinname in s0.pingroup: fntype = s0.fntype.get(pinname, 'inout') - k_ = k.lower() pn = pinname.lower() - g.write("%s_%s\t%s\n" % (k_, pn, fntype)) + g.write("%s\t%s" % (pn, fntype)) + if fntype == 'inout' and pinname in gangedgroup: + g.write("\tbus") + g.write("\n") + + # work out range of bankspecs + bankpins = [] + for k, v in bankspec.items(): + bankpins.append((v, k)) + bankpins.sort() + bankpins.reverse() + muxentries = {} + cellbank = {} - pks = pinouts.keys() - pks.sort() + pks = sorted(pinouts.keys()) # truly dreadful way to work out the max mux size... - muxsz = 0 for k in pks: - for m in pinouts[k].keys(): - muxsz = max(muxsz, m + 1) + for (sz, bname) in bankpins: + print "keys", k, sz, bname + if k >= sz: + print "found", bname + muxentries[k] = muxwidths[bname] + cellbank[k] = bname + break + print muxentries + # write out the mux... with open(os.path.join(pth, 'pinmap.txt'), 'w') as g: for k in pks: - res = [str(k)] + muxsz = muxentries[k] + bank = cellbank[k] + res = [str(k), bank, str(muxsz)] # append pin mux for midx in range(muxsz): - if pinouts[k].has_key(midx): + if midx in pinouts[k]: fname = pinouts[k][midx][0] else: fname = '' - print k, midx, fname res.append(fname.lower()) g.write('\t'.join(res) + '\n') + + # ... and the dedicated pins + with open(os.path.join(pth, 'fixedpins.txt'), 'w') as g: + for p in fixedpins: + p = map(str, p) + p = map(str.lower, p) + g.write('\t'.join(p) + '\n') + + # lists bankspec, shows where the pin-numbers *start* + of.write("# Pin Bank starting points and lengths\n\n") + with open(os.path.join(pth, 'pinspec.txt'), 'w') as g: + keys = sorted(bankspec.keys()) + for bank in keys: + pinstart = bankspec[bank] + wid = muxwidths[bank] + of.write("* %s %d %d %d\n" % (bank, pinstart, pinbanks[bank], wid)) + g.write("%s\t%d\t%d\t%d\n" % (bank, pinstart, pinbanks[bank], wid))