2 from string
import digits
4 from string
import maketrans
6 maketrans
= str.maketrans
9 # dictionary of properties of signals that are supported.
13 "spi_sclk" : "output",
14 "spi_mosi" : "output",
26 # ============== common bsv templates ============ #
27 # first argument is the io-cell number being assigned.
28 # second argument is the mux value.
29 # Third argument is the signal from the pinmap file
31 rule assign_{2}_on_cell{0}(wrcell{0}_mux=={1});
36 rule assign_{1}_on_cell{0};
40 # ============================================================
42 digits
= maketrans('0123456789', ' '*10) # delete space later
45 return "cell%s_mux" % str(idx
)
47 for cell
in muxed_cells
:
48 pinmux
= pinmux
+ " %s_out=" % cn(cell
[0])
50 while(i
< len(cell
) - 1):
51 pinmux
= pinmux
+ "wr%s" % cn(cell
[0]) + \
52 "==" + str(i
) + "?" + cell
[i
+ 1] + "_io:\n\t\t\t"
53 if(i
+ 2 == len(cell
) - 1):
54 pinmux
= pinmux
+ cell
[i
+ 2] + "_io"
58 pinmux
= pinmux
+ ";\n"
59 # ======================================================== #
61 # check each cell if "peripheral input/inout" then assign its wire
62 # Here we check the direction of each signal in the dictionary.
63 # We choose to keep the dictionary within the code and not user-input
64 # since the interfaces are always standard and cannot change from
65 # user-to-user. Plus this also reduces human-error as well :)
66 for i
in range(0, len(cell
) - 1):
67 temp
= cell
[i
+ 1].translate(digits
)
68 temp
= temp
.replace(' ', '')
69 x
= dictionary
.get(temp
)
72 "ERROR: The signal : " +
74 " of pinmap.txt isn't present in the current dictionary.\
75 \nUpdate 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 dedicated_cells
:
88 pinmux
= 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 # =======================================================#