2 from string
import digits
4 from string
import maketrans
6 maketrans
= str.maketrans
9 # ============== common bsv templates ============ #
10 # first argument is the io-cell number being assigned.
11 # second argument is the mux value.
12 # Third argument is the signal from the pinmap file
14 rule assign_{2}_on_cell{0}(wrcell{0}_mux=={1});
19 rule assign_{1}_on_cell{0};
23 # ============================================================
24 digits
= maketrans('0123456789', ' ' * 10) # delete space later
27 def cn(idx
): # idx is an integer
28 return "cell%s_mux" % str(idx
)
32 """ removes the number from the string of signal name.
34 temp
= temp
.split('_')
36 temp
[0] = temp
[0].translate(digits
)
37 temp
[0] = temp
[0] .replace(' ', '')
41 # XXX this needs to move into interface_decl.py
42 # and made to use ifaceoutfmtfn and ifaceinfmtfn
43 def fmt(ifaces
, cells
, idx
, suffix
=None):
44 """ blank entries need to output a 0 to the pin (it could just as
45 well be a 1 but we choose 0). reason: blank entries in
46 the pinmap.txt file indicate that there's nothing to choose
47 from. however the user may still set the muxer to that value,
48 and rather than throw an exception we choose to output... zero.
50 NOTE: IMPORTANT. when a function is an output-only there
51 is a special-case assumption that:
52 * (a) GPIO is always the first mux entry
53 * (b) GPIO's outen is also used to set the pad
54 the reason for this is that it is assumed better that
55 multiple pads be switched simutaneously to outputs
56 by setting the GPIO direction rather than having them
57 set arbitrarily by changing the muxer registers.
64 #print "fmt", idx, cells, cell
68 x
= ifaces
.getifacetype(temp
)
70 return 'val0' # inputs don't get passed through to the out mux
71 if suffix
== '_outen' and x
== 'out':
72 return "wr%s%s" % (cells
[1], suffix
or '') # USE GPIO FOR SELECTION
73 if x
== 'out': # sigh hack, should be using interface_decl
75 return "wr%s%s" % (cell
, suffix
or '')
77 # XXX this needs to move into interface_decl.py
80 def mkcomment(ifaces
, cell
, idx
, outenmode
=False):
81 """ returns a comment string for the cell when muxed
90 x
= ifaces
.getifacetype(temp
)
93 return ' // %s is an input' % cname
94 if outenmode
and x
== 'inout':
95 return ' // bi-directional'
96 if outenmode
and x
== 'out':
97 return ' // %s is an output' % cname
102 def mkmux(p
, ifaces
, cell
, suffix
, outenmode
):
103 """ creates a straight many-to-one muxer that accepts
104 multiple inputs and, based on an "address" routes
105 a given indexed input through to the (one) output
108 comment
= 'outen' if outenmode
else 'output'
109 fmtstr
= "\t\t\twr%s==%d?%s:%s\n" # mux-selector format
111 ret
+= " // %s muxer for cell idx %s\n" % (comment
, cellnum
)
112 ret
+= " %s%s=\n" % (cn(cellnum
), suffix
)
114 mwid
= p
.get_muxwidth(cellnum
)
116 for i
in range(0, mwid
- 1): # full mux range (minus 1)
117 comment
= mkcomment(ifaces
, cell
, i
, outenmode
)
118 cf
= fmt(ifaces
, cell
, i
, suffix
)
119 ret
+= fmtstr
% (cn(cell
[0]), i
, cf
, comment
)
121 comment
= mkcomment(ifaces
, cell
, i
, outenmode
)
122 ret
+= "\t\t\t" + fmt(ifaces
, cell
, i
, suffix
) # last line
123 ret
+= ";%s\n" % comment
129 """ generates the actual output pinmux for each io-cell. blank lines
130 need to output "0" to the iopad, if there is no entry in
133 text is outputted in the format:
140 last line doesn't need selector-logic, obviously.
142 note that it's *important* that all muxer options be covered
143 (hence going up to 1<<cell_bitwidth) even if the muxer cells
144 are blank (no entries), because muxer selection could be to
145 the last one, and we do not want the "default" (last line)
149 global dedicated_wire
150 for cell
in p
.muxed_cells
:
154 p
.pinmux
+= " // --------------------\n"
155 p
.pinmux
+= " // ----- cell %s -----\n\n" % (cellidx
)
157 # first do the outputs
158 p
.pinmux
+= mkmux(p
, ifaces
, cell
, '_out', False)
161 # now do the output enablers (outens)
162 p
.pinmux
+= mkmux(p
, ifaces
, cell
, '_outen', True)
164 # ======================================================== #
166 # check each cell if "peripheral input/inout" then assign its wire
167 # Here we check the direction of each signal in the dictionary.
168 # We choose to keep the dictionary within the code and not user-input
169 # since the interfaces are always standard and cannot change from
170 # user-to-user. Plus this also reduces human-error as well :)
172 p
.pinmux
+= " // priority-in-muxer for cell idx %s\n" % (cellidx
)
173 for i
in range(0, len(cell
) - 1):
175 if not cname
: # skip blank entries, no need to test
177 temp
= transfn(cname
)
178 x
= ifaces
.getifacetype(temp
)
179 print (cname
, temp
, x
)
180 assert x
is not None, "ERROR: The signal : " + \
182 " of pinmap.txt isn't present \nin the current" + \
183 " dictionary. Update dictionary or fix-typo."
184 bwid
= p
.get_muxbitwidth(cellidx
)
186 muxcell(p
, cname
, x
, cell
, i
)
190 # ================== Logic for dedicated pins ========= #
191 p
.pinmux
+= "\n /*=========================================*/\n"
192 p
.pinmux
+= " // dedicated cells\n\n"
193 for cell
in p
.dedicated_cells
:
194 p
.pinmux
+= " // dedicated cell idx %s\n" % (cell
[0])
195 p
.pinmux
+= " %s_out=%s_io;\n" % (cn(cell
[0]), cell
[1])
196 temp
= transfn(cell
[1])
197 x
= ifaces
.getifacetype(temp
)
201 def muxcell(p
, cname
, x
, cell
, i
):
204 mux_wire
.format(cell
[0], i
, "wr" + cname
) + "\n"
207 mux_wire
.format(cell
[0], i
, "wr" + cname
+
209 def dedcell(p
, x
, cell
):
212 dedicated_wire
.format(cell
[0], "wr" + cell
[1]) + "\n"
215 dedicated_wire
.format(cell
[0], "wr" + cell
[1] + "_in") + "\n"