3 from parse
import Parse
4 from myhdlgen
.pins
import IO
5 from ifacebase
import InterfacesBase
7 from string
import maketrans
9 maketrans
= str.maketrans
11 # XXX hmmm duplicated from src/bsc/actual_pinmux.py
12 digits
= maketrans('0123456789', ' ' * 10) # delete space later
14 # XXX hmmm duplicated from src/bsc/actual_pinmux.py
18 """ removes the number from the string of signal name.
20 temp
= temp
.split('_')
22 temp
[0] = temp
[0].translate(digits
)
23 temp
[0] = temp
[0] .replace(' ', '')
27 class Interface(object):
28 """ create an interface from a list of pinspecs.
29 each pinspec is a dictionary, see Pin class arguments
30 single indicates that there is only one of these, and
31 so the name must *not* be extended numerically (see pname)
33 # sample interface object:
35 twiinterface_decl = Interface('twi',
36 [{'name': 'sda', 'type': 'in'},
37 {'name': 'scl', 'type': 'inout'},
41 def __init__(self
, ifacename
, pinspecs
, ganged
=None, single
=False):
42 self
.ifacename
= ifacename
43 self
.ganged
= ganged
or {}
44 self
.pins
= [] # a list of instances of class Pin
45 self
.pinspecs
= pinspecs
# a list of dictionary
49 _p
['name'] = self
.pname(p
['name'])
50 _p
['typ'] = self
.pname(p
['type'])
51 self
.pins
.append(IO(**_p
))
53 def getifacetype(self
, name
):
54 for p
in self
.pinspecs
:
55 fname
= "%s_%s" % (self
.ifacename
, p
['name'])
56 #print "search", self.ifacename, name, fname
65 def pname(self
, name
):
66 """ generates the interface spec e.g. flexbus_ale
67 if there is only one flexbus interface, or
68 sd{0}_cmd if there are several. string format
69 function turns this into sd0_cmd, sd1_cmd as
70 appropriate. single mode stops the numerical extension.
73 return '%s_%s' % (self
.ifacename
, name
)
74 return '%s{0}_%s' % (self
.ifacename
, name
)
77 class Interfaces(InterfacesBase
):
78 """ contains a list of interface definitions
81 def __init__(self
, pth
=None):
82 InterfacesBase
.__init
__(self
, Interface
, pth
)
84 def create_module(p
, ifaces
):
86 from myhdl import block
88 def pinmux(muxfn, clk, p, ifaces, {0}):
90 return muxfn(clk, p, ifaces, args)
94 for cell
in p
.muxed_cells
:
95 args
.append("sel%d" % int(cell
[0]))
96 args
.append("io%d" % int(cell
[0]))
100 for k
, count
in ifaces
.ifacecount
:
102 for c
in range(count
):
104 args
.append("%s%d" % (k
, c
))
105 args
= ',\n\t\t'.join(args
)
107 path
= os
.path
.abspath(__file__
)
108 fname
= os
.path
.split(path
)[0]
109 fname
= os
.path
.join(fname
, "myhdlautogen.py")
111 with
open(fname
, "w") as f
:
113 x
= "from myhdlgen.myhdlautogen import pinmux"
114 code
= compile(x
, '<string>', 'exec')
123 for cell
in p
.muxed_cells
:
125 for i
in range(0, len(cell
) - 1):
127 if not cname
: # skip blank entries, no need to test
129 temp
= transfn(cname
)
130 x
= ifaces
.getifacetype(temp
)
131 print (cname
, temp
, x
)
134 def pinmuxgen(pth
=None, verify
=True):
135 p
= Parse(pth
, verify
)
137 ifaces
= Interfaces(pth
)
139 create_module(p
, ifaces
)