96843ce11764d34f795d20fe3557f5486ce1beca
3 from spec
.interfaces
import Pinouts
6 def specgen(of
, pth
, pinouts
, bankspec
, muxwidths
, pinbanks
, fixedpins
,
8 """ generates a specification of pinouts (tsv files)
9 for reading in by pinmux.
12 * interfaces.txt - contains name and number of interfaces
13 * {interfacename}.txt - contains name of pin, type, and bus
15 type may be in, out or inout.
16 if type is "inout" then a THIRD optional parameter of type
17 "bus" indicates whether the bus is ganged together. in
18 future this may be "bus1", "bus2" and so on if an interface
19 contains more than one ganged group.
21 basically if the function needs to control whether a group
22 of pins shall be switched from input to output (as opposed
23 to the *pinmux* via user control deciding that), bus is
24 the way to indicate it.
27 #print bankspec.keys()
28 #print fixedpins.keys()
29 #print pinouts.ganged.items()
30 if not os
.path
.exists(pth
):
32 with
open(os
.path
.join(pth
, 'interfaces.txt'), 'w') as f
:
33 for k
in pinouts
.fnspec
.keys():
35 line
= [k
.lower(), str(len(s
))]
37 if b
.startswith(k
.lower()):
39 line
= '\t'.join(line
)
40 f
.write("%s\n" % line
)
41 s0
= s
[list(s
.keys())[0]] # hack, take first
42 gangedgroup
= pinouts
.ganged
[k
]
43 with
open(os
.path
.join(pth
, '%s.txt' % k
.lower()), 'w') as g
:
44 if len(s0
.pingroup
) == 1: # only one function, grouped higher
45 for ks
in s
.keys(): # grouped by interface
46 assert False, "TODO, single-function"
47 fntype
= 'inout' # XXX TODO
50 g
.write("%s\t%s\n" % (k_
, fntype
))
52 for pinname
in s0
.pingroup
:
53 fntype
= s0
.fntype
.get(pinname
, 'inout')
55 g
.write("%s\t%s" % (pn
, fntype
))
56 if fntype
== 'inout' and pinname
in gangedgroup
:
60 pks
= sorted(pinouts
.keys())
62 # truly dreadful way to work out the max mux size...
65 for m
in pinouts
[k
].keys():
66 muxsz
= max(muxsz
, m
+ 1)
68 # write out the mux...
69 with
open(os
.path
.join(pth
, 'pinmap.txt'), 'w') as g
:
73 for midx
in range(muxsz
):
74 if midx
in pinouts
[k
]:
75 fname
= pinouts
[k
][midx
][0]
78 res
.append(fname
.lower())
79 g
.write('\t'.join(res
) + '\n')
81 # ... and the dedicated pins
82 with
open(os
.path
.join(pth
, 'fixedpins.txt'), 'w') as g
:
86 g
.write('\t'.join(p
) + '\n')
88 # lists bankspec, shows where the pin-numbers *start*
89 of
.write("# Pin Bank starting points and lengths\n\n")
90 with
open(os
.path
.join(pth
, 'pinspec.txt'), 'w') as g
:
91 keys
= sorted(bankspec
.keys())
93 pinstart
= bankspec
[bank
]
95 of
.write("* %s %d %d %d\n" % (bank
, pinstart
, pinbanks
[bank
], wid
))
96 g
.write("%s\t%d\t%d\t%d\n" % (bank
, pinstart
, pinbanks
[bank
], wid
))