1 from string
import digits
3 from string
import maketrans
5 maketrans
= str.maketrans
8 # ============== common bsv templates ============ #
9 # first argument is the io-cell number being assigned.
10 # second argument is the mux value.
11 # Third argument is the signal from the pinmap file
13 rule assign_{2}_on_cell{0}(wrcell{0}_mux=={1});
18 rule assign_{1}_on_cell{0};
22 # ============================================================
23 digits
= maketrans('0123456789', ' ' * 10) # delete space later
26 def cn(idx
): # idx is an integer
27 return "cell%s_mux" % str(idx
)
31 """ removes the number from the string of signal name.
33 temp
= temp
.split('_')
35 temp
[0] = temp
[0].translate(digits
)
36 temp
[0] = temp
[0] .replace(' ', '')
40 """ blank entries need to output a 0 to the pin (it could just as
41 well be a 1 but we choose 0). reason: blank entries in
42 the pinmap.txt file indicate that there's nothing to choose
43 from. however the user may still set the muxer to that value,
44 and rather than throw an exception we choose to output... zero.
46 return "%s_io" % cell
if cell
else '0'
49 def mkcomment(p
, cell
):
50 """ returns a comment string for the cell when muxed
55 """ generates the actual output pinmux for each io-cell. blank lines
56 need to output "0" to the iopad, if there is no entry in
59 text is outputted in the format:
66 last line doesn't need selector-logic, obviously.
70 fmtstr
= "\t\t\twr%s == %d ? %s :%s\n" # mux-selector format
71 for cell
in p
.muxed_cells
:
72 p
.pinmux
+= " // output muxer for cell idx %s\n" % cell
[0]
73 p
.pinmux
+= " %s_out=\n" % cn(cell
[0])
74 for i
in range(0, len(cell
) - 2):
75 comment
= mkcomment(p
, cell
[i
+ 1])
76 p
.pinmux
+= fmtstr
% (cn(cell
[0]), i
, fmt(cell
[i
+ 1]), comment
)
77 comment
= mkcomment(p
, cell
[i
+ 2])
78 p
.pinmux
+= "\t\t\t" + fmt(cell
[i
+ 2]) + comment
# last line
80 # ======================================================== #
82 # check each cell if "peripheral input/inout" then assign its wire
83 # Here we check the direction of each signal in the dictionary.
84 # We choose to keep the dictionary within the code and not user-input
85 # since the interfaces are always standard and cannot change from
86 # user-to-user. Plus this also reduces human-error as well :)
87 for i
in range(0, len(cell
) - 1):
89 if not cname
: # skip blank entries, no need to test
92 x
= ifaces
.getifacetype(temp
)
93 #print (cname, temp, x)
94 assert x
is not None, "ERROR: The signal : " + \
96 " of pinmap.txt isn't present \nin the current" + \
97 " dictionary. Update dictionary or fix-typo."
100 mux_wire
.format(cell
[0], i
, "wr" + cname
) + "\n"
103 mux_wire
.format(cell
[0], i
, "wr" + cname
+
105 # ============================================================ #
107 # ================== Logic for dedicated pins ========= #
108 for cell
in p
.dedicated_cells
:
109 p
.pinmux
+= " %s_out=%s_io;\n" % (cn(cell
[0]), cell
[1])
110 temp
= cell
[1].translate(digits
)
111 x
= ifaces
.getifacetype(temp
)
114 dedicated_wire
.format(cell
[0], "wr" + cell
[1]) + "\n"
117 dedicated_wire
.format(cell
[0], "wr" + cell
[1] + "_in") + "\n"
118 # =======================================================#