3 from spec
.interfaces
import Pinouts
6 def specgen(of
, pth
, pinouts
, bankspec
, pinbanks
, fixedpins
, fastbus
):
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
, 'bankwidths.txt'), 'w') as f
:
32 for k
, v
in pinouts
.muxwidths
.items():
33 f
.write("%s\t%d\n" % (k
, v
))
34 with
open(os
.path
.join(pth
, 'interfaces.txt'), 'w') as f
:
35 for k
in pinouts
.fnspec
.keys():
37 line
= [k
.lower(), str(len(s
))]
39 if b
.startswith(k
.lower()):
41 line
= '\t'.join(line
)
42 f
.write("%s\n" % line
)
43 s0
= s
[list(s
.keys())[0]] # hack, take first
44 gangedgroup
= pinouts
.ganged
[k
]
45 with
open(os
.path
.join(pth
, '%s.txt' % k
.lower()), 'w') as g
:
46 if len(s0
.pingroup
) == 1: # only one function, grouped higher
47 for ks
in s
.keys(): # grouped by interface
48 assert False, "TODO, single-function"
49 fntype
= 'inout' # XXX TODO
52 g
.write("%s\t%s\n" % (k_
, fntype
))
54 for pinname
in s0
.pingroup
:
55 fntype
= s0
.fntype
.get(pinname
, 'inout')
57 g
.write("%s\t%s" % (pn
, fntype
))
58 if fntype
== 'inout' and pinname
in gangedgroup
:
62 pks
= sorted(pinouts
.keys())
64 # truly dreadful way to work out the max mux size...
67 for m
in pinouts
[k
].keys():
68 muxsz
= max(muxsz
, m
+ 1)
70 # write out the mux...
71 with
open(os
.path
.join(pth
, 'pinmap.txt'), 'w') as g
:
75 for midx
in range(muxsz
):
76 if midx
in pinouts
[k
]:
77 fname
= pinouts
[k
][midx
][0]
80 res
.append(fname
.lower())
81 g
.write('\t'.join(res
) + '\n')
83 # ... and the dedicated pins
84 with
open(os
.path
.join(pth
, 'fixedpins.txt'), 'w') as g
:
88 g
.write('\t'.join(p
) + '\n')
90 # lists bankspec, shows where the pin-numbers *start*
91 of
.write("# Pin Bank starting points and lengths\n\n")
92 with
open(os
.path
.join(pth
, 'pinspec.txt'), 'w') as g
:
93 keys
= sorted(bankspec
.keys())
95 pinstart
= bankspec
[bank
]
96 of
.write("* %s %d %d\n" % (bank
, pinstart
, pinbanks
[bank
]))
97 g
.write("%s\t%d\t%d\n" % (bank
, pinstart
, pinbanks
[bank
]))