Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions chipflow_lib/platforms/silicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,45 +86,43 @@ def __init__(self,
self._i = Signal(port.width, name=f"{component}_{name}__i")
if self._direction in (io.Direction.Output, io.Direction.Bidir):
self._o = Signal(port.width, name=f"{component}_{name}__o")
# Only bidir ports have output-enable. Either each line has its own OE, or there's one OE for all the wires
if self._direction is io.Direction.Bidir:
if "all_have_oe" in self._options and self._options["all_have_oe"]:
self._oe = Signal(port.width, name=f"{component}_{name}__oe", init=-1)
else:
self._oe = Signal(1, name=f"{component}_{name}__oe", init=-1)
elif self._direction is io.Direction.Output:
# Always create an _oe for output ports
self._oe = Signal(1, name=f"{component}_{name}__oe", init=-1)

logger.debug(f"Created SiliconPlatformPort {name}, width={len(port.pins)},dir{self._direction}")

def wire(self, m: Module, interface: PureInterface):
assert self._direction == interface.signature.direction
if hasattr(interface, 'i'):
m.d.comb += interface.i.eq(self.i)
for d in ['o', 'oe']:
if hasattr(interface, d):
m.d.comb += getattr(self, d).eq(getattr(interface, d))
if hasattr(interface, 'o'):
m.d.comb += self.o.eq(interface.o)
if hasattr(interface, 'oe') and self._oe is not None:
m.d.comb += self.oe.eq(interface.oe)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the mixing of self._oe and self.oe is a bit confusing here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any suggestions? SiliconPlatformPort is public, so i think it has to be self._oe, but could be wrong!


@property

def i(self):
if self._i is None:
raise AttributeError("SiliconPlatformPort with output direction does not have an "
"input signal")
"input signal")
return self._i

@property
def o(self):
if self._o is None:
raise AttributeError("SiliconPlatformPort with input direction does not have an "
"output signal")
"output signal")
return self._o

@property
def oe(self):
if self._oe is None:
raise AttributeError("SiliconPlatformPort with input direction does not have an "
"output enable signal")
raise AttributeError("SiliconPlatformPort with output or input direction does not have an "
"output enable signal")
return self._oe

@property
Expand Down Expand Up @@ -219,6 +217,9 @@ def elaborate(self, platform):
m.d.comb += i_inv.eq(self.port.i)
if self.direction in (io.Direction.Output, io.Direction.Bidir):
m.d.comb += self.port.o.eq(o_inv)

# Only set oe for bidirectional ports
if self.direction is io.Direction.Bidir:
m.d.comb += self.port.oe.eq(self.oe)

return m
Expand Down
8 changes: 4 additions & 4 deletions tests/test_silicon_platform_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def test_init_output_port(self):

# Test accessing properties
_ = spp.o # Should not raise an error
_ = spp.oe # Should not raise an error since we now always have an _oe for outputs
with self.assertRaises(AttributeError):
_ = spp.oe # Should raise an error since output ports don't have oe signals
with self.assertRaises(AttributeError):
_ = spp.i # Should raise an error for output port

Expand Down Expand Up @@ -174,7 +175,7 @@ def __init__(self):
spp.wire(m, interface)

def test_wire_output(self):
# Test wire method with a mock output interface to cover line 105
# Test wire method with a mock output interface
port_obj = Port(type="output", pins=["1", "2"], port_name="test_output",
direction="o", options={})
spp = SiliconPlatformPort("comp", "test_output", port_obj)
Expand All @@ -193,7 +194,6 @@ class MockInterface(PureInterface):
def __init__(self):
self.signature = MockSignature()
self.o = Signal(2)
self.oe = Signal(1)

interface = MockInterface()
m = Module()
Expand Down Expand Up @@ -247,4 +247,4 @@ def test_repr(self):
self.assertIn("SiliconPlatformPort", repr_str)
self.assertIn("direction", repr_str)
self.assertIn("width=3", repr_str)
self.assertIn("invert=False", repr_str)
self.assertIn("invert=False", repr_str)
Loading