replace split from whitespace to tabspace
[pinmux.git] / src / bsv / actual_pinmux.py
1 from string import digits
2 try:
3 from string import maketrans
4 except ImportError:
5 maketrans = str.maketrans
6
7
8 # ============== common bsv templates ============ #
9 # first argument is the io-cell number being assigned.
10 # second argument is the mux value.
11 # Third argument is the signal from the pinmap file
12 mux_wire = '''
13 rule assign_{2}_on_cell{0}(wrcell{0}_mux=={1});
14 {2}<=cell{0}_mux_in;
15 endrule
16 '''
17 dedicated_wire = '''
18 rule assign_{1}_on_cell{0};
19 {1}<=cell{0}_mux_in;
20 endrule
21 '''
22 # ============================================================
23 digits = maketrans('0123456789', ' ' * 10) # delete space later
24
25
26 def cn(idx):
27 return "cell%s_mux" % str(idx)
28
29
30 def transfn(temp):
31 temp = temp.split('_')
32 if len(temp) == 2:
33 temp[0] = temp[0].translate(digits)
34 temp[0] = temp[0] .replace(' ', '')
35 return '_'.join(temp)
36
37
38 def init(p, ifaces):
39 """ generates the actual output pinmux for each io-cell. blank lines
40 need to output "0" to the iopad, if there is no entry in
41 that column.
42 """
43 p.pinmux = ' '
44 global dedicated_wire
45 for cell in p.muxed_cells:
46 p.pinmux += " // output muxer for cell idx %d\n" % cell[0]
47 p.pinmux += " %s_out=" % cn(cell[0])
48 for i in range(0, len(cell) - 2):
49 p.pinmux += "wr%s" % cn(cell[0]) + \
50 "==" + str(i) + "?" + cell[i + 1] + "_io:\n\t\t\t"
51 p.pinmux += cell[i + 2] + "_io"
52 p.pinmux += ";\n"
53 # ======================================================== #
54
55 # check each cell if "peripheral input/inout" then assign its wire
56 # Here we check the direction of each signal in the dictionary.
57 # We choose to keep the dictionary within the code and not user-input
58 # since the interfaces are always standard and cannot change from
59 # user-to-user. Plus this also reduces human-error as well :)
60 for i in range(0, len(cell) - 1):
61 cname = cell[i + 1]
62 temp = transfn(cname)
63 x = ifaces.getifacetype(temp)
64 #print (cname, temp, x)
65 assert x is not None, "ERROR: The signal : " + \
66 str(cname) + \
67 " of pinmap.txt isn't present \nin the current" + \
68 " dictionary. Update dictionary or fix-typo."
69 if x == "input":
70 p.pinmux += \
71 mux_wire.format(cell[0], i, "wr" + cname) + "\n"
72 elif x == "inout":
73 p.pinmux += \
74 mux_wire.format(cell[0], i, "wr" + cname +
75 "_in") + "\n"
76 # ============================================================ #
77
78 # ================== Logic for dedicated pins ========= #
79 for cell in p.dedicated_cells:
80 p.pinmux += " %s_out=%s_io;\n" % (cn(cell[0]), cell[1])
81 temp = cell[1].translate(digits)
82 x = ifaces.getifacetype(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 # =======================================================#