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)'
47 class Interface(object):
48 """ create an interface from a list of pinspecs.
49 each pinspec is a dictionary, see Pin class arguments
52 def __init__(self
, pinspecs
):
55 if p
.get('outen') is True: # special case, generate 3 pins
59 for psuffix
in ['out', 'outen', 'in']:
60 _p
['name'] = "%s_%s" % (p
['name'], psuffix
)
61 _p
['action'] = psuffix
!= 'in'
62 self
.pins
.append(Pin(**_p
))
64 self
.pins
.append(Pin(**p
))
66 def ifacefmt(self
, i
):
67 return '\n'+'\n'.join(map(lambda x
:x
.ifacefmt(), self
.pins
)).format(i
)
70 if __name__
== '__main__':
72 def _pinmunge(p
, sep
, repl
, dedupe
=True):
73 """ munges the text so it's easier to compare.
74 splits by separator, strips out blanks, re-joins.
79 p
= filter(lambda x
: x
, p
) # filter out blanks
83 """ munges the text so it's easier to compare.
85 # first join lines by semicolons, strip out returns
87 p
= map(lambda x
: x
.replace('\n', ''), p
)
89 # now split first by brackets, then spaces (deduping on spaces)
90 p
= _pinmunge(p
, "(", " ( ", False)
91 p
= _pinmunge(p
, ")", " ) ", False)
92 p
= _pinmunge(p
, " ", " ")
95 # ========= Interface declarations ================ #
98 method Action cell{0}_mux(Bit#({1}) in);'''
100 io_interface
= Interface([{'name': 'io_outputval_{0}', 'enabled': False},
101 {'name': 'io_output_en_{0}', 'enabled': False},
102 {'name': 'io_input_en_{0}', 'enabled': False},
103 {'name': 'io_pullup_en_{0}', 'enabled': False},
104 {'name': 'io_pulldown_en_{0}', 'enabled': False},
105 {'name': 'io_drivestrength_{0}', 'enabled': False},
106 {'name': 'io_pushpull_en_{0}', 'enabled': False},
107 {'name': 'io_opendrain_en_{0}', 'enabled': False},
108 {'name': 'io_inputval_{0}', 'action': True, 'io': True},
111 # == Peripheral Interface definitions == #
112 # these are the interface of the peripherals to the pin mux
113 # Outputs from the peripherals will be inputs to the pinmux
114 # module. Hence the change in direction for most pins
116 uartinterface_decl
= Interface([{'name': 'tx_{0}', 'action': True},
120 spiinterface_decl
= Interface([{'name': 'sclk_{0}', 'action': True},
121 {'name': 'mosi_{0}', 'action': True},
122 {'name': 'ss_{0}', 'action': True},
123 {'name': 'miso_{0}'},
126 twiinterface_decl
= Interface([{'name': 'sda{0}', 'outen': True},
127 {'name': 'scl{0}', 'outen': True},
130 sdinterface_decl
= Interface([{'name': 'sd{0}_clk', 'action': True},
131 {'name': 'sd{0}_cmd', 'action': True},
132 {'name': 'sd{0}_d0', 'outen': True},
133 {'name': 'sd{0}_d1', 'outen': True},
134 {'name': 'sd{0}_d2', 'outen': True},
135 {'name': 'sd{0}_d3', 'outen': True}
138 jtaginterface_decl
= Interface([{'name': 'jtag{0}_tdi'},
139 {'name': 'jtag{0}_tms'},
140 {'name': 'jtag{0}_tclk'},
141 {'name': 'jtag{0}_trst'},
142 {'name': 'jtag{0}_tdo', 'action': True}])
144 pwminterface_decl
= Interface([{'name': "pwm{0}", 'action': True}])
146 # ======================================= #