02603a97122a784daa32b53d57096cb7921f0896
[pinmux.git] / src / actual_pinmux.py
1 from parse 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 digits = str.maketrans(dict.fromkeys('0123456789'))
35
36 for cell in muxed_cells:
37 pinmux = pinmux + " cell" + str(cell[0]) + "_out="
38 i = 0
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"
44 i = i + 2
45 else:
46 i = i + 1
47 pinmux = pinmux + ";\n"
48 # ======================================================== #
49
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)
58 if(x is None):
59 print(
60 "Error: The signal : " +
61 str(cell[i + 1]) +
62 " in lineno: " +
63 str(lineno) + "of pinmap.txt isn't present in the \
64 current dictionary.\nUpdate dictionary or fix-typo.")
65 exit(1)
66 if(x == "input"):
67 pinmux = pinmux + \
68 mux_wire.format(cell[0], i, "wr" + cell[i + 1]) + "\n"
69 elif(x == "inout"):
70 pinmux = pinmux + \
71 mux_wire.format(cell[0], i, "wr" + cell[i + 1] +
72 "_in") + "\n"
73 # ============================================================ #
74
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)
81 if(x == "input"):
82 pinmux = pinmux + \
83 dedicated_wire.format(cell[0], "wr" + cell[1]) + "\n"
84 elif(x == "inout"):
85 pinmux = pinmux + \
86 dedicated_wire.format(cell[0], "wr" + cell[1] + "_in") + "\n"
87 # =======================================================#