99
1010from amaranth .lib import wiring , io
1111from amaranth .lib .cdc import FFSynchronizer
12- from amaranth .lib .wiring import Component , In
12+ from amaranth .lib .wiring import Component , In , PureInterface , flipped , connect
1313
1414from amaranth .back import rtlil
1515from amaranth .hdl import Fragment
@@ -72,7 +72,6 @@ def __init__(self,
7272 self ._invert = invert
7373 self ._options = port .options
7474
75- self ._i = self ._o = self ._oe = Signal (1 )
7675 if self ._direction in (io .Direction .Input , io .Direction .Bidir ):
7776 self ._i = Signal (port .width , name = f"{ component } _{ name } __i" )
7877 if self ._direction in (io .Direction .Output , io .Direction .Bidir ):
@@ -86,7 +85,16 @@ def __init__(self,
8685 self ._pins = port .pins
8786 logger .debug (f"Created SiliconPlatformPort { name } , width={ len (port .pins )} ,dir{ self ._direction } " )
8887
88+ def wire (self , m : Module , interface : PureInterface ):
89+ assert self ._direction == interface .signature .direction
90+ if hasattr (interface , 'i' ):
91+ m .d .comb += interface .i .eq (self .i )
92+ for d in ['o' , 'oe' ]:
93+ if hasattr (interface , d ):
94+ m .d .comb += getattr (self , d ).eq (getattr (interface , d ))
95+
8996 @property
97+
9098 def i (self ):
9199 if self ._i is None :
92100 raise AttributeError ("SiliconPlatformPort with output direction does not have an "
@@ -229,6 +237,10 @@ def __init__(self, config):
229237 self ._ports = {}
230238 self ._files = {}
231239
240+ @property
241+ def ports (self ):
242+ return self ._ports
243+
232244 def instantiate_ports (self , m : Module ):
233245 if hasattr (self , "pinlock" ):
234246 return
@@ -237,7 +249,7 @@ def instantiate_ports(self, m: Module):
237249 for component , iface in pinlock .port_map .items ():
238250 for k , v in iface .items ():
239251 for name , port in v .items ():
240- self ._ports [name ] = SiliconPlatformPort (component , name , port )
252+ self ._ports [port . port_name ] = SiliconPlatformPort (component , name , port )
241253
242254 for clock , name in self ._config ["chipflow" ]["clocks" ].items ():
243255 if name not in pinlock .package .clocks :
@@ -246,6 +258,7 @@ def instantiate_ports(self, m: Module):
246258 port_data = pinlock .package .clocks [name ]
247259 port = SiliconPlatformPort (component , name , port_data , invert = True )
248260 self ._ports [name ] = port
261+
249262 if clock == 'default' :
250263 clock = 'sync'
251264 setattr (m .domains , clock , ClockDomain (name = clock ))
@@ -311,13 +324,14 @@ def _prepare(self, elaboratable, name="top"):
311324 # Check that only a single clock domain is used.
312325 self ._check_clock_domains (fragment )
313326
314- # Prepare toplevel ports according to chipflow.toml.
327+ # Prepare toplevel ports according to pinlock
315328 ports = []
316329 for port_name , port in self ._ports .items ():
317330 if port .direction in (io .Direction .Input , io .Direction .Bidir ):
318331 ports .append ((f"io${ port_name } $i" , port .i , PortDirection .Input ))
319332 if port .direction in (io .Direction .Output , io .Direction .Bidir ):
320333 ports .append ((f"io${ port_name } $o" , port .o , PortDirection .Output ))
334+ if port .direction is io .Direction .Bidir :
321335 ports .append ((f"io${ port_name } $oe" , port .oe , PortDirection .Output ))
322336
323337 # Prepare design for RTLIL conversion.
0 commit comments