full support for dedicated pins.
[pinmux.git] / src / actual_pinmux.py
1 from params import *
2 from string import digits
3
4
5 # dictionary of properties of signals that are supported.
6 dictionary = {
7 "uart_rx" : "input",
8 "uart_tx" : "output",
9 "spi_sclk" : "output",
10 "spi_mosi" : "output",
11 "spi_ss" : "output",
12 "spi_miso" : "input",
13 "twi_sda" : "inout",
14 "twi_scl" : "inout"
15 }
16
17
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
22 mux_wire = '''
23 rule assign_{2}_on_cell{0}(wrmux{0}=={1});
24 {2}<=cell{0}_in;
25 endrule
26 '''
27 dedicated_wire = '''
28 rule assign_{1}_on_cell{0};
29 {1}<=cell{0}_in;
30 endrule
31 '''
32 # ============================================================
33 pinmux = ''' '''
34 pinmap_file = open("./pinmap.txt", "r")
35 dedicated = False
36 for lineno, line in enumerate(pinmap_file):
37 line1 = line.split()
38 if("muxed" in line):
39 dedicated = False
40 elif("dedicated" in line):
41 dedicated = True
42 digits = str.maketrans(dict.fromkeys('0123456789'))
43 # ==== Logic for muxed pins ==== #
44 if(len(line1) > 1 and not(dedicated)):
45 if(lineno > N_IO):
46 print(
47 "ERROR: Parameter N_IO(" +
48 str(N_IO) +
49 ") is less than the pin number in line: " +
50 str(lineno) +
51 " of pinmap.txt")
52 exit(1)
53 # ==== Mux each generic IO cell with the mapping ===== #
54 # provided in the pinmap file
55 pinmux = pinmux + " cell" + str(line1[0]) + "_out="
56 i = 0
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"
62 i = i + 2
63 else:
64 i = i + 1
65 pinmux = pinmux + ";\n"
66 # ======================================================== #
67
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)
76 if(x is None):
77 print(
78 "Error: The signal : " +
79 str(line1[i + 1]) +
80 " in lineno: " +
81 str(lineno) + "of pinmap.txt isn't present in the \
82 current dictionary.\nUpdate dictionary or fix-typo.")
83 exit(1)
84 if(x == "input"):
85 pinmux = pinmux + \
86 mux_wire.format(line1[0], i, "wr" + line1[i + 1]) + "\n"
87 elif(x == "inout"):
88 pinmux = pinmux + \
89 mux_wire.format(line1[0], i, "wr" + line1[i + 1] +
90 "_in") + "\n"
91 # ============================================================ #
92
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)
99 if(x == "input"):
100 pinmux = pinmux + \
101 dedicated_wire.format(line1[0], "wr" + line1[1]) + "\n"
102 elif(x == "inout"):
103 pinmux = pinmux + \
104 dedicated_wire.format(line1[0], "wr" + line1[1] + "_in") + "\n"
105 # ======================================================= #
106 # =========================================================