decoupling interfaces for IO and memory mapped registers
[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 "sd_clk": "output",
16 "sd_cmd": "output",
17 "sd_d": "inout",
18 }
19
20
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
25 mux_wire = '''
26 rule assign_{2}_on_cell{0}(wrmux{0}=={1});
27 {2}<=cell{0}_in;
28 endrule
29 '''
30 dedicated_wire = '''
31 rule assign_{1}_on_cell{0};
32 {1}<=cell{0}_in;
33 endrule
34 '''
35 # ============================================================
36 pinmux = ''' '''
37 digits = str.maketrans(dict.fromkeys('0123456789'))
38
39 for cell in muxed_cells:
40 pinmux = pinmux + " cell" + str(cell[0]) + "_out="
41 i = 0
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"
47 i = i + 2
48 else:
49 i = i + 1
50 pinmux = pinmux + ";\n"
51 # ======================================================== #
52
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)
61 if(x is None):
62 print(
63 "ERROR: The signal : " +
64 str(cell[i + 1]) +
65 " of pinmap.txt isn't present in the current dictionary.\
66 \nUpdate dictionary or fix-typo.")
67 exit(1)
68 if(x == "input"):
69 pinmux = pinmux + \
70 mux_wire.format(cell[0], i, "wr" + cell[i + 1]) + "\n"
71 elif(x == "inout"):
72 pinmux = pinmux + \
73 mux_wire.format(cell[0], i, "wr" + cell[i + 1] +
74 "_in") + "\n"
75 # ============================================================ #
76
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)
83 if(x == "input"):
84 pinmux = pinmux + \
85 dedicated_wire.format(cell[0], "wr" + cell[1]) + "\n"
86 elif(x == "inout"):
87 pinmux = pinmux + \
88 dedicated_wire.format(cell[0], "wr" + cell[1] + "_in") + "\n"
89 # =======================================================#