712fb29ed15c96a23a21eb841e94167de5567a68
3 """ pin interface declaration.
4 * name is the name of the pin
5 * ready, enabled and io all create a (* .... *) prefix
6 * action changes it to an "in" if true
9 def __init__(self
, name
,
16 self
.enabled
= enabled
24 status
.append('always_ready')
26 status
.append('always_enabled')
28 status
.append('result="io"')
31 res
+= ','.join(status
)
39 res
+= ' (Bit#(1) in)'
46 def ifacedef(self
, fmtoutfn
=None, fmtinfn
=None):
49 fmtname
= fmtinfn(self
.name
) if fmtinfn
else self
.name
52 res
+= '(Bit#(1) in);\n'
53 res
+= ' %s<=in;\n' % fmtname
56 fmtname
= fmtoutfn(self
.name
) if fmtoutfn
else self
.name
57 res
+= "%s=%s;" % (self
.name
, fmtname
)
61 class Interface(object):
62 """ create an interface from a list of pinspecs.
63 each pinspec is a dictionary, see Pin class arguments
66 def __init__(self
, pinspecs
):
69 if p
.get('outen') is True: # special case, generate 3 pins
73 for psuffix
in ['out', 'outen', 'in']:
74 _p
['name'] = "%s_%s" % (p
['name'], psuffix
)
75 _p
['action'] = psuffix
!= 'in'
76 self
.pins
.append(Pin(**_p
))
78 self
.pins
.append(Pin(**p
))
80 def ifacefmt(self
, i
):
81 return '\n'+'\n'.join(map(lambda x
:x
.ifacefmt(), self
.pins
)).format(i
)
83 def ifacefmtoutfn(self
, name
):
86 def ifacefmtinfn(self
, name
):
89 def ifacefmtpin(self
, pin
):
90 return pin
.ifacedef(self
.ifacefmtoutfn
, self
.ifacefmtinfn
)
92 def ifacedef(self
, i
):
93 res
= '\n'.join(map(self
.ifacefmtpin
, self
.pins
)).format(i
)
94 return '\n' + res
+ '\n'
97 class IOInterface(Interface
):
99 def ifacefmtoutfn(self
, name
):
100 return "cell{0}_out.%s" % (name
[3:-4])
102 def ifacefmtinfn(self
, name
):
106 # ========= Interface declarations ================ #
109 method Action cell{0}_mux(Bit#({1}) in);'''
111 io_interface
= IOInterface([{'name': 'io_outputval_{0}', 'enabled': False},
112 {'name': 'io_output_en_{0}', 'enabled': False},
113 {'name': 'io_input_en_{0}', 'enabled': False},
114 {'name': 'io_pullup_en_{0}', 'enabled': False},
115 {'name': 'io_pulldown_en_{0}', 'enabled': False},
116 {'name': 'io_drivestrength_{0}', 'enabled': False},
117 {'name': 'io_pushpull_en_{0}', 'enabled': False},
118 {'name': 'io_opendrain_en_{0}', 'enabled': False},
119 {'name': 'io_inputval_{0}', 'action': True, 'io': True},
122 # == Peripheral Interface definitions == #
123 # these are the interface of the peripherals to the pin mux
124 # Outputs from the peripherals will be inputs to the pinmux
125 # module. Hence the change in direction for most pins
127 uartinterface_decl
= Interface([{'name': 'tx_{0}', 'action': True},
131 spiinterface_decl
= Interface([{'name': 'sclk_{0}', 'action': True},
132 {'name': 'mosi_{0}', 'action': True},
133 {'name': 'ss_{0}', 'action': True},
134 {'name': 'miso_{0}'},
137 twiinterface_decl
= Interface([{'name': 'sda{0}', 'outen': True},
138 {'name': 'scl{0}', 'outen': True},
141 sdinterface_decl
= Interface([{'name': 'sd{0}_clk', 'action': True},
142 {'name': 'sd{0}_cmd', 'action': True},
143 {'name': 'sd{0}_d0', 'outen': True},
144 {'name': 'sd{0}_d1', 'outen': True},
145 {'name': 'sd{0}_d2', 'outen': True},
146 {'name': 'sd{0}_d3', 'outen': True}
149 jtaginterface_decl
= Interface([{'name': 'jtag{0}_tdi'},
150 {'name': 'jtag{0}_tms'},
151 {'name': 'jtag{0}_tclk'},
152 {'name': 'jtag{0}_trst'},
153 {'name': 'jtag{0}_tdo', 'action': True}])
155 pwminterface_decl
= Interface([{'name': "pwm{0}", 'action': True}])
157 # ======================================= #
160 if __name__
== '__main__':
162 def _pinmunge(p
, sep
, repl
, dedupe
=True):
163 """ munges the text so it's easier to compare.
164 splits by separator, strips out blanks, re-joins.
169 p
= filter(lambda x
: x
, p
) # filter out blanks
173 """ munges the text so it's easier to compare.
175 # first join lines by semicolons, strip out returns
177 p
= map(lambda x
: x
.replace('\n', ''), p
)
179 # now split first by brackets, then spaces (deduping on spaces)
180 p
= _pinmunge(p
, "(", " ( ", False)
181 p
= _pinmunge(p
, ")", " ) ", False)
182 p
= _pinmunge(p
, " ", " ")
185 from interface_def
import io_interface_def
186 print io_interface_def
.format(0)
187 print io_interface
.ifacedef(0)