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 pinmap_file
= open("./pinmap.txt", "r")
36 for lineno
, line
in enumerate(pinmap_file
):
40 elif("dedicated" in line
):
42 digits
= str.maketrans(dict.fromkeys('0123456789'))
43 # ==== Logic for muxed pins ==== #
44 if(len(line1
) > 1 and not(dedicated
)):
47 "ERROR: Parameter N_IO(" +
49 ") is less than the pin number in line: " +
53 # ==== Mux each generic IO cell with the mapping ===== #
54 # provided in the pinmap file
55 pinmux
= pinmux
+ " cell" + str(line1
[0]) + "_out="
57 while(i
< len(line1
) - 1):
58 pinmux
= pinmux
+ "wrmux" + \
59 str(line1
[0]) + "==" + str(i
) + "?" + line1
[i
+ 1] + "_io:"
60 if(i
+ 2 == len(line1
) - 1):
61 pinmux
= pinmux
+ line1
[i
+ 2] + "_io"
65 pinmux
= pinmux
+ ";\n"
66 # ======================================================== #
68 # check each cell if "peripheral input/inout" then assign its wire
69 # Here we check the direction of each signal in the dictionary.
70 # We choose to keep the dictionary within the code and not user-input
71 # since the interfaces are always standard and cannot change from
72 # user-to-user. Plus this also reduces human-error as well :)
73 for i
in range(0, len(line1
) - 1):
74 temp
= line1
[i
+ 1].translate(digits
)
75 x
= dictionary
.get(temp
)
78 "Error: The signal : " +
81 str(lineno
) + "of pinmap.txt isn't present in the \
82 current dictionary.\nUpdate dictionary or fix-typo.")
86 mux_wire
.format(line1
[0], i
, "wr" + line1
[i
+ 1]) + "\n"
89 mux_wire
.format(line1
[0], i
, "wr" + line1
[i
+ 1] +
91 # ============================================================ #
93 # ================== Logic for dedicated pins ========= #
94 elif(len(line1
) > 1 and dedicated
):
95 pinmux
= pinmux
+ " cell" + \
96 str(line1
[0]) + "_out=" + line1
[1] + "_io;\n"
97 temp
= line1
[1].translate(digits
)
98 x
= dictionary
.get(temp
)
101 dedicated_wire
.format(line1
[0], "wr" + line1
[1]) + "\n"
104 dedicated_wire
.format(line1
[0], "wr" + line1
[1] + "_in") + "\n"
105 # ======================================================= #
106 # =========================================================