e5aa4994b8da15d9e34bd93e2edfa801db158fa6
1 from string
import digits
3 from string
import maketrans
5 maketrans
= str.maketrans
8 # dictionary of properties of signals that are supported.
12 "spi_sclk" : "output",
13 "spi_mosi" : "output",
25 # ============== common bsv templates ============ #
26 # first argument is the io-cell number being assigned.
27 # second argument is the mux value.
28 # Third argument is the signal from the pinmap file
30 rule assign_{2}_on_cell{0}(wrcell{0}_mux=={1});
35 rule assign_{1}_on_cell{0};
39 # ============================================================
40 digits
= maketrans('0123456789', ' ' * 10) # delete space later
44 return "cell%s_mux" % str(idx
)
50 for cell
in p
.muxed_cells
:
51 p
.pinmux
+= " %s_out=" % cn(cell
[0])
53 while (i
< len(cell
) - 1):
54 p
.pinmux
+= "wr%s" % cn(cell
[0]) + \
55 "==" + str(i
) + "?" + cell
[i
+ 1] + "_io:\n\t\t\t"
56 if i
+ 2 == len(cell
) - 1:
57 p
.pinmux
+= cell
[i
+ 2] + "_io"
62 # ======================================================== #
64 # check each cell if "peripheral input/inout" then assign its wire
65 # Here we check the direction of each signal in the dictionary.
66 # We choose to keep the dictionary within the code and not user-input
67 # since the interfaces are always standard and cannot change from
68 # user-to-user. Plus this also reduces human-error as well :)
69 for i
in range(0, len(cell
) - 1):
70 temp
= cell
[i
+ 1].translate(digits
)
71 temp
= temp
.replace(' ', '')
72 x
= dictionary
.get(temp
)
73 assert x
is not None, "ERROR: The signal : " + \
75 " of pinmap.txt isn't present \nin the current" + \
76 " dictionary. Update dictionary or fix-typo."
79 mux_wire
.format(cell
[0], i
, "wr" + cell
[i
+ 1]) + "\n"
82 mux_wire
.format(cell
[0], i
, "wr" + cell
[i
+ 1] +
84 # ============================================================ #
86 # ================== Logic for dedicated pins ========= #
87 for cell
in p
.dedicated_cells
:
88 p
.pinmux
+= " %s" % cn(cell
[0]) + \
89 "_out=" + cell
[1] + "_io;\n"
90 temp
= cell
[1].translate(digits
)
91 x
= dictionary
.get(temp
)
94 dedicated_wire
.format(cell
[0], "wr" + cell
[1]) + "\n"
97 dedicated_wire
.format(cell
[0], "wr" + cell
[1] + "_in") + "\n"
98 # =======================================================#