input cell-types now output 0 on output as well.\
[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): # idx is an integer
27 return "cell%s_mux" % str(idx)
28
29
30 def transfn(temp):
31 """ removes the number from the string of signal name.
32 """
33 temp = temp.split('_')
34 if len(temp) == 2:
35 temp[0] = temp[0].translate(digits)
36 temp[0] = temp[0] .replace(' ', '')
37 return '_'.join(temp)
38
39 def fmt(ifaces, cell):
40 """ blank entries need to output a 0 to the pin (it could just as
41 well be a 1 but we choose 0). reason: blank entries in
42 the pinmap.txt file indicate that there's nothing to choose
43 from. however the user may still set the muxer to that value,
44 and rather than throw an exception we choose to output... zero.
45 """
46 empty = '0' # XXX TODO: fix this, as it's assigned to GenericIOType
47 if not cell:
48 return empty
49 # work out the type. if it's an input, return empty
50 temp = cell[1].translate(digits)
51 x = ifaces.getifacetype(temp)
52 if x == 'input':
53 return empty
54 return "%s_io" % cell
55
56 def init(p, ifaces):
57 """ generates the actual output pinmux for each io-cell. blank lines
58 need to output "0" to the iopad, if there is no entry in
59 that column.
60 """
61 p.pinmux = ' '
62 global dedicated_wire
63 for cell in p.muxed_cells:
64 p.pinmux += " // output muxer for cell idx %s\n" % cell[0]
65 p.pinmux += " %s_out=" % cn(cell[0])
66 for i in range(0, len(cell) - 2):
67 p.pinmux += "wr%s" % cn(cell[0]) + \
68 "==" + str(i) + "?" + fmt(ifaces, cell[i + 1]) + ":\n\t\t\t"
69 p.pinmux += fmt(ifaces, cell[i + 2])
70 p.pinmux += ";\n"
71 # ======================================================== #
72
73 # check each cell if "peripheral input/inout" then assign its wire
74 # Here we check the direction of each signal in the dictionary.
75 # We choose to keep the dictionary within the code and not user-input
76 # since the interfaces are always standard and cannot change from
77 # user-to-user. Plus this also reduces human-error as well :)
78 for i in range(0, len(cell) - 1):
79 cname = cell[i + 1]
80 if not cname: # skip blank entries, no need to test
81 continue
82 temp = transfn(cname)
83 x = ifaces.getifacetype(temp)
84 #print (cname, temp, x)
85 assert x is not None, "ERROR: The signal : " + \
86 str(cname) + \
87 " of pinmap.txt isn't present \nin the current" + \
88 " dictionary. Update dictionary or fix-typo."
89 if x == "input":
90 p.pinmux += \
91 mux_wire.format(cell[0], i, "wr" + cname) + "\n"
92 elif x == "inout":
93 p.pinmux += \
94 mux_wire.format(cell[0], i, "wr" + cname +
95 "_in") + "\n"
96 # ============================================================ #
97
98 # ================== Logic for dedicated pins ========= #
99 for cell in p.dedicated_cells:
100 p.pinmux += " %s_out=%s_io;\n" % (cn(cell[0]), cell[1])
101 temp = cell[1].translate(digits)
102 x = ifaces.getifacetype(temp)
103 if x == "input":
104 pinmux = pinmux + \
105 dedicated_wire.format(cell[0], "wr" + cell[1]) + "\n"
106 elif x == "inout":
107 pinmux = pinmux + \
108 dedicated_wire.format(cell[0], "wr" + cell[1] + "_in") + "\n"
109 # =======================================================#