a9dab0106acc2a2efdb10fcc39a595a36716d1a8
1 from parse
import Parse
2 from ifacebase
import InterfacesBase
4 from string
import maketrans
6 maketrans
= str.maketrans
8 # XXX hmmm duplicated from src/bsc/actual_pinmux.py
9 digits
= maketrans('0123456789', ' ' * 10) # delete space later
11 # XXX hmmm duplicated from src/bsc/actual_pinmux.py
15 """ removes the number from the string of signal name.
17 temp
= temp
.split('_')
19 temp
[0] = temp
[0].translate(digits
)
20 temp
[0] = temp
[0] .replace(' ', '')
25 """ pin interface declaration.
26 * name is the name of the pin
27 * ready, enabled and io all create a (* .... *) prefix
28 * action changes it to an "in" if true
31 def __init__(self
, name
,
40 self
.enabled
= enabled
43 self
.bitspec
= bitspec
if bitspec
else 'Bit#(1)'
44 self
.outenmode
= outenmode
47 class Interface(object):
48 """ create an interface from a list of pinspecs.
49 each pinspec is a dictionary, see Pin class arguments
50 single indicates that there is only one of these, and
51 so the name must *not* be extended numerically (see pname)
53 # sample interface object:
55 twiinterface_decl = Interface('twi',
56 [{'name': 'sda', 'outen': True},
57 {'name': 'scl', 'outen': True},
61 def __init__(self
, ifacename
, pinspecs
, ganged
=None, single
=False):
62 self
.ifacename
= ifacename
63 self
.ganged
= ganged
or {}
64 self
.pins
= [] # a list of instances of class Pin
65 self
.pinspecs
= pinspecs
# a list of dictionary
70 if p
.get('outen') is True: # special case, generate 3 pins
72 for psuffix
in ['out', 'outen', 'in']:
73 # changing the name (like sda) to (twi_sda_out)
74 _p
['name'] = "%s_%s" % (self
.pname(p
['name']), psuffix
)
75 _p
['action'] = psuffix
!= 'in'
76 self
.pins
.append(Pin(**_p
))
77 # will look like {'name': 'twi_sda_out', 'action': True}
78 # {'name': 'twi_sda_outen', 'action': True}
79 #{'name': 'twi_sda_in', 'action': False}
80 # NOTice - outen key is removed
82 _p
['name'] = self
.pname(p
['name'])
83 self
.pins
.append(Pin(**_p
))
85 def getifacetype(self
, name
):
86 for p
in self
.pinspecs
:
87 fname
= "%s_%s" % (self
.ifacename
, p
['name'])
88 #print "search", self.ifacename, name, fname
97 def pname(self
, name
):
98 """ generates the interface spec e.g. flexbus_ale
99 if there is only one flexbus interface, or
100 sd{0}_cmd if there are several. string format
101 function turns this into sd0_cmd, sd1_cmd as
102 appropriate. single mode stops the numerical extension.
105 return '%s_%s' % (self
.ifacename
, name
)
106 return '%s{0}_%s' % (self
.ifacename
, name
)
109 class Interfaces(InterfacesBase
):
110 """ contains a list of interface definitions
113 def __init__(self
, pth
=None):
114 InterfacesBase
.__init
__(self
, Interface
, pth
)
118 for cell
in p
.muxed_cells
:
120 for i
in range(0, len(cell
) - 1):
122 if not cname
: # skip blank entries, no need to test
124 temp
= transfn(cname
)
125 x
= ifaces
.getifacetype(temp
)
126 print (cname
, temp
, x
)
129 def pinmuxgen(pth
=None, verify
=True):
130 p
= Parse(pth
, verify
)
132 ifaces
= Interfaces(pth
)