3 from spec
.interfaces
import Pinouts
6 def specgen(of
, pth
, pinouts
, bankspec
, pinbanks
, fixedpins
):
7 """ generates a specification of pinouts (tsv files)
8 for reading in by pinmux.
11 * interfaces.txt - contains name and number of interfaces
12 * {interfacename}.txt - contains name of pin, type, and bus
14 type may be in, out or inout.
15 if type is "inout" then a THIRD optional parameter of type
16 "bus" indicates whether the bus is ganged together. in
17 future this may be "bus1", "bus2" and so on if an interface
18 contains more than one ganged group.
20 basically if the function needs to control whether a group
21 of pins shall be switched from input to output (as opposed
22 to the *pinmux* via user control deciding that), bus is
23 the way to indicate it.
26 #print bankspec.keys()
27 #print fixedpins.keys()
28 #print pinouts.ganged.items()
29 if not os
.path
.exists(pth
):
31 with
open(os
.path
.join(pth
, 'interfaces.txt'), 'w') as f
:
32 for k
in pinouts
.fnspec
.keys():
34 f
.write("%s\t%d\n" % (k
.lower(), len(s
)))
35 s0
= s
[list(s
.keys())[0]] # hack, take first
36 gangedgroup
= pinouts
.ganged
[k
]
37 with
open(os
.path
.join(pth
, '%s.txt' % k
.lower()), 'w') as g
:
38 if len(s0
.pingroup
) == 1: # only one function, grouped higher
39 for ks
in s
.keys(): # grouped by interface
40 assert False, "TODO, single-function"
41 fntype
= 'inout' # XXX TODO
44 g
.write("%s\t%s\n" % (k_
, fntype
))
46 for pinname
in s0
.pingroup
:
47 fntype
= s0
.fntype
.get(pinname
, 'inout')
49 g
.write("%s\t%s" % (pn
, fntype
))
50 if fntype
== 'inout' and pinname
in gangedgroup
:
54 pks
= sorted(pinouts
.keys())
56 # truly dreadful way to work out the max mux size...
59 for m
in pinouts
[k
].keys():
60 muxsz
= max(muxsz
, m
+ 1)
62 # write out the mux...
63 with
open(os
.path
.join(pth
, 'pinmap.txt'), 'w') as g
:
67 for midx
in range(muxsz
):
68 if midx
in pinouts
[k
]:
69 fname
= pinouts
[k
][midx
][0]
72 res
.append(fname
.lower())
73 g
.write('\t'.join(res
) + '\n')
75 # ... and the dedicated pins
76 with
open(os
.path
.join(pth
, 'fixedpins.txt'), 'w') as g
:
80 g
.write('\t'.join(p
) + '\n')
82 # lists bankspec, shows where the pin-numbers *start*
83 of
.write("# Pin Bank starting points and lengths\n\n")
84 with
open(os
.path
.join(pth
, 'pinspec.txt'), 'w') as g
:
85 keys
= sorted(bankspec
.keys())
87 pinstart
= bankspec
[bank
]
88 of
.write("* %s %d %d\n" % (bank
, pinstart
, pinbanks
[bank
]))
89 g
.write("%s\t%d\t%d\n" % (bank
, pinstart
, pinbanks
[bank
]))