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}(wrmux{0}=={1});
36 rule assign_{1}_on_cell{0};
40 # ============================================================
42 digits
= maketrans('0123456789', ' '*10) # delete space later
44 for cell
in muxed_cells
:
45 pinmux
= pinmux
+ " cell" + str(cell
[0]) + "_out="
47 while(i
< len(cell
) - 1):
48 pinmux
= pinmux
+ "wrmux" + \
49 str(cell
[0]) + "==" + str(i
) + "?" + cell
[i
+ 1] + "_io:"
50 if(i
+ 2 == len(cell
) - 1):
51 pinmux
= pinmux
+ cell
[i
+ 2] + "_io"
55 pinmux
= pinmux
+ ";\n"
56 # ======================================================== #
58 # check each cell if "peripheral input/inout" then assign its wire
59 # Here we check the direction of each signal in the dictionary.
60 # We choose to keep the dictionary within the code and not user-input
61 # since the interfaces are always standard and cannot change from
62 # user-to-user. Plus this also reduces human-error as well :)
63 for i
in range(0, len(cell
) - 1):
64 temp
= cell
[i
+ 1].translate(digits
)
65 temp
= temp
.replace(' ', '')
66 x
= dictionary
.get(temp
)
69 "ERROR: The signal : " +
71 " of pinmap.txt isn't present in the current dictionary.\
72 \nUpdate dictionary or fix-typo.")
76 mux_wire
.format(cell
[0], i
, "wr" + cell
[i
+ 1]) + "\n"
79 mux_wire
.format(cell
[0], i
, "wr" + cell
[i
+ 1] +
81 # ============================================================ #
83 # ================== Logic for dedicated pins ========= #
84 for cell
in dedicated_cells
:
85 pinmux
= pinmux
+ " cell" + \
86 str(cell
[0]) + "_out=" + cell
[1] + "_io;\n"
87 temp
= cell
[1].translate(digits
)
88 x
= dictionary
.get(temp
)
91 dedicated_wire
.format(cell
[0], "wr" + cell
[1]) + "\n"
94 dedicated_wire
.format(cell
[0], "wr" + cell
[1] + "_in") + "\n"
95 # =======================================================#