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