2 from string
import digits
5 # dictionary of properties of signals that are supported.
10 "spi_mosi" : "output",
21 # ============== common bsv templates ============ #
22 # first argument is the io-cell number being assigned.
23 # second argument is the mux value.
24 # Third argument is the signal from the pinmap file
26 rule assign_{2}_on_cell{0}(wrmux{0}=={1});
31 rule assign_{1}_on_cell{0};
35 # ============================================================
37 digits
= str.maketrans(dict.fromkeys('0123456789'))
39 for cell
in muxed_cells
:
40 pinmux
= pinmux
+ " cell" + str(cell
[0]) + "_out="
42 while(i
< len(cell
) - 1):
43 pinmux
= pinmux
+ "wrmux" + \
44 str(cell
[0]) + "==" + str(i
) + "?" + cell
[i
+ 1] + "_io:"
45 if(i
+ 2 == len(cell
) - 1):
46 pinmux
= pinmux
+ cell
[i
+ 2] + "_io"
50 pinmux
= pinmux
+ ";\n"
51 # ======================================================== #
53 # check each cell if "peripheral input/inout" then assign its wire
54 # Here we check the direction of each signal in the dictionary.
55 # We choose to keep the dictionary within the code and not user-input
56 # since the interfaces are always standard and cannot change from
57 # user-to-user. Plus this also reduces human-error as well :)
58 for i
in range(0, len(cell
) - 1):
59 temp
= cell
[i
+ 1].translate(digits
)
60 x
= dictionary
.get(temp
)
63 "ERROR: The signal : " +
65 " of pinmap.txt isn't present in the current dictionary.\
66 \nUpdate dictionary or fix-typo.")
70 mux_wire
.format(cell
[0], i
, "wr" + cell
[i
+ 1]) + "\n"
73 mux_wire
.format(cell
[0], i
, "wr" + cell
[i
+ 1] +
75 # ============================================================ #
77 # ================== Logic for dedicated pins ========= #
78 for cell
in dedicated_cells
:
79 pinmux
= pinmux
+ " cell" + \
80 str(cell
[0]) + "_out=" + cell
[1] + "_io;\n"
81 temp
= cell
[1].translate(digits
)
82 x
= dictionary
.get(temp
)
85 dedicated_wire
.format(cell
[0], "wr" + cell
[1]) + "\n"
88 dedicated_wire
.format(cell
[0], "wr" + cell
[1] + "_in") + "\n"
89 # =======================================================#