rename cell mux to consistent naming scheme
[pinmux.git] / src / actual_pinmux.py
1 from parse import *
2 from string import digits
3 try:
4 from string import maketrans
5 except ImportError:
6 maketrans = str.maketrans
7
8
9 # dictionary of properties of signals that are supported.
10 dictionary = {
11 "uart_rx" : "input",
12 "uart_tx" : "output",
13 "spi_sclk" : "output",
14 "spi_mosi" : "output",
15 "spi_ss" : "output",
16 "spi_miso" : "input",
17 "twi_sda" : "inout",
18 "twi_scl" : "inout",
19 "sd_clk": "output",
20 "sd_cmd": "output",
21 "sd_d": "inout",
22 "pwm": "output"
23 }
24
25
26 # ============== common bsv templates ============ #
27 # first argument is the io-cell number being assigned.
28 # second argument is the mux value.
29 # Third argument is the signal from the pinmap file
30 mux_wire = '''
31 rule assign_{2}_on_cell{0}(wrcell{0}_mux=={1});
32 {2}<=cell{0}_mux_in;
33 endrule
34 '''
35 dedicated_wire = '''
36 rule assign_{1}_on_cell{0};
37 {1}<=cell{0}_mux_in;
38 endrule
39 '''
40 # ============================================================
41 pinmux = ''' '''
42 digits = maketrans('0123456789', ' '*10) # delete space later
43
44 def cn(idx):
45 return "cell%s_mux" % str(idx)
46
47 for cell in muxed_cells:
48 pinmux = pinmux + " %s_out=" % cn(cell[0])
49 i = 0
50 while(i < len(cell) - 1):
51 pinmux = pinmux + "wr%s" % cn(cell[0]) + \
52 "==" + str(i) + "?" + cell[i + 1] + "_io:\n\t\t\t"
53 if(i + 2 == len(cell) - 1):
54 pinmux = pinmux + cell[i + 2] + "_io"
55 i = i + 2
56 else:
57 i = i + 1
58 pinmux = pinmux + ";\n"
59 # ======================================================== #
60
61 # check each cell if "peripheral input/inout" then assign its wire
62 # Here we check the direction of each signal in the dictionary.
63 # We choose to keep the dictionary within the code and not user-input
64 # since the interfaces are always standard and cannot change from
65 # user-to-user. Plus this also reduces human-error as well :)
66 for i in range(0, len(cell) - 1):
67 temp = cell[i + 1].translate(digits)
68 temp = temp.replace(' ', '')
69 x = dictionary.get(temp)
70 if(x is None):
71 print(
72 "ERROR: The signal : " +
73 str(cell[i + 1]) +
74 " of pinmap.txt isn't present in the current dictionary.\
75 \nUpdate dictionary or fix-typo.")
76 exit(1)
77 if(x == "input"):
78 pinmux = pinmux + \
79 mux_wire.format(cell[0], i, "wr" + cell[i + 1]) + "\n"
80 elif(x == "inout"):
81 pinmux = pinmux + \
82 mux_wire.format(cell[0], i, "wr" + cell[i + 1] +
83 "_in") + "\n"
84 # ============================================================ #
85
86 # ================== Logic for dedicated pins ========= #
87 for cell in dedicated_cells:
88 pinmux = pinmux + " %s" % cn(cell[0]) + \
89 "_out=" + cell[1] + "_io;\n"
90 temp = cell[1].translate(digits)
91 x = dictionary.get(temp)
92 if(x == "input"):
93 pinmux = pinmux + \
94 dedicated_wire.format(cell[0], "wr" + cell[1]) + "\n"
95 elif(x == "inout"):
96 pinmux = pinmux + \
97 dedicated_wire.format(cell[0], "wr" + cell[1] + "_in") + "\n"
98 # =======================================================#