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