09b11deb7fa215f8d0040684d4ce0154965311fa
1 from parse
import Parse
2 from myhdlgen
.pins
import IO
3 from ifacebase
import InterfacesBase
5 from string
import maketrans
7 maketrans
= str.maketrans
9 # XXX hmmm duplicated from src/bsc/actual_pinmux.py
10 digits
= maketrans('0123456789', ' ' * 10) # delete space later
12 # XXX hmmm duplicated from src/bsc/actual_pinmux.py
16 """ removes the number from the string of signal name.
18 temp
= temp
.split('_')
20 temp
[0] = temp
[0].translate(digits
)
21 temp
[0] = temp
[0] .replace(' ', '')
26 """ pin interface declaration.
27 * name is the name of the pin
28 * ready, enabled and io all create a (* .... *) prefix
29 * action changes it to an "in" if true
32 def __init__(self
, name
,
41 self
.enabled
= enabled
44 self
.bitspec
= bitspec
if bitspec
else 'Bit#(1)'
45 self
.outenmode
= outenmode
48 class Interface(object):
49 """ create an interface from a list of pinspecs.
50 each pinspec is a dictionary, see Pin class arguments
51 single indicates that there is only one of these, and
52 so the name must *not* be extended numerically (see pname)
54 # sample interface object:
56 twiinterface_decl = Interface('twi',
57 [{'name': 'sda', 'outen': True},
58 {'name': 'scl', 'outen': True},
62 def __init__(self
, ifacename
, pinspecs
, ganged
=None, single
=False):
63 self
.ifacename
= ifacename
64 self
.ganged
= ganged
or {}
65 self
.pins
= [] # a list of instances of class Pin
66 self
.pinspecs
= pinspecs
# a list of dictionary
70 _p
['name'] = self
.pname(p
['name'])
71 _p
['typ'] = self
.pname(p
['type'])
72 self
.pins
.append(IO(**_p
))
74 def getifacetype(self
, name
):
75 for p
in self
.pinspecs
:
76 fname
= "%s_%s" % (self
.ifacename
, p
['name'])
77 #print "search", self.ifacename, name, fname
86 def pname(self
, name
):
87 """ generates the interface spec e.g. flexbus_ale
88 if there is only one flexbus interface, or
89 sd{0}_cmd if there are several. string format
90 function turns this into sd0_cmd, sd1_cmd as
91 appropriate. single mode stops the numerical extension.
94 return '%s_%s' % (self
.ifacename
, name
)
95 return '%s{0}_%s' % (self
.ifacename
, name
)
98 class Interfaces(InterfacesBase
):
99 """ contains a list of interface definitions
102 def __init__(self
, pth
=None):
103 InterfacesBase
.__init
__(self
, Interface
, pth
)
107 for cell
in p
.muxed_cells
:
109 for i
in range(0, len(cell
) - 1):
111 if not cname
: # skip blank entries, no need to test
113 temp
= transfn(cname
)
114 x
= ifaces
.getifacetype(temp
)
115 print (cname
, temp
, x
)
118 def pinmuxgen(pth
=None, verify
=True):
119 p
= Parse(pth
, verify
)
121 ifaces
= Interfaces(pth
)