0dfdef591043aeb94747804d7dc2e56d57483373
1 from parse
import Parse
2 from ifacebase
import InterfacesBase
4 from string
import maketrans
6 maketrans
= str.maketrans
8 digits
= maketrans('0123456789', ' ' * 10) # delete space later
10 # XXX hmmm duplicated from src/bsc/actual_pinmux.py
12 """ removes the number from the string of signal name.
14 temp
= temp
.split('_')
16 temp
[0] = temp
[0].translate(digits
)
17 temp
[0] = temp
[0] .replace(' ', '')
22 """ pin interface declaration.
23 * name is the name of the pin
24 * ready, enabled and io all create a (* .... *) prefix
25 * action changes it to an "in" if true
28 def __init__(self
, name
,
37 self
.enabled
= enabled
40 self
.bitspec
= bitspec
if bitspec
else 'Bit#(1)'
41 self
.outenmode
= outenmode
44 class Interface(object):
45 """ create an interface from a list of pinspecs.
46 each pinspec is a dictionary, see Pin class arguments
47 single indicates that there is only one of these, and
48 so the name must *not* be extended numerically (see pname)
50 # sample interface object:
52 twiinterface_decl = Interface('twi',
53 [{'name': 'sda', 'outen': True},
54 {'name': 'scl', 'outen': True},
58 def __init__(self
, ifacename
, pinspecs
, ganged
=None, single
=False):
59 self
.ifacename
= ifacename
60 self
.ganged
= ganged
or {}
61 self
.pins
= [] # a list of instances of class Pin
62 self
.pinspecs
= pinspecs
# a list of dictionary
67 if p
.get('outen') is True: # special case, generate 3 pins
69 for psuffix
in ['out', 'outen', 'in']:
70 # changing the name (like sda) to (twi_sda_out)
71 _p
['name'] = "%s_%s" % (self
.pname(p
['name']), psuffix
)
72 _p
['action'] = psuffix
!= 'in'
73 self
.pins
.append(Pin(**_p
))
74 # will look like {'name': 'twi_sda_out', 'action': True}
75 # {'name': 'twi_sda_outen', 'action': True}
76 #{'name': 'twi_sda_in', 'action': False}
77 # NOTice - outen key is removed
79 _p
['name'] = self
.pname(p
['name'])
80 self
.pins
.append(Pin(**_p
))
82 def getifacetype(self
, name
):
83 for p
in self
.pinspecs
:
84 fname
= "%s_%s" % (self
.ifacename
, p
['name'])
85 #print "search", self.ifacename, name, fname
94 def pname(self
, name
):
95 """ generates the interface spec e.g. flexbus_ale
96 if there is only one flexbus interface, or
97 sd{0}_cmd if there are several. string format
98 function turns this into sd0_cmd, sd1_cmd as
99 appropriate. single mode stops the numerical extension.
102 return '%s_%s' % (self
.ifacename
, name
)
103 return '%s{0}_%s' % (self
.ifacename
, name
)
107 class Interfaces(InterfacesBase
):
108 """ contains a list of interface definitions
111 def __init__(self
, pth
=None):
112 InterfacesBase
.__init
__(self
, Interface
, pth
)
116 for cell
in p
.muxed_cells
:
118 for i
in range(0, len(cell
) - 1):
120 if not cname
: # skip blank entries, no need to test
122 temp
= transfn(cname
)
123 x
= ifaces
.getifacetype(temp
)
124 print (cname
, temp
, x
)
127 def pinmuxgen(pth
=None, verify
=True):
128 p
= Parse(pth
, verify
)
130 ifaces
= Interfaces(pth
)