Skip to content

Commit

Permalink
phy/pcs1000basex: Improve/Simplify PCSRX source logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Oct 16, 2024
1 parent 93472ef commit cd2274d
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions liteeth/phy/pcs_1000basex.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def __init__(self, lsb_first=False):
self.seen_config_reg = Signal() # Config seen.
self.config_reg = Signal(16) # Config register (16-bit).
self.sgmii_speed = Signal(2) # SGMII speed.
self.source = source = stream.Endpoint([("data", 8), ("ce", 1)]) # Data output.
self.source = source = stream.Endpoint([("data", 8)]) # Data output.

self.decoder = Decoder(lsb_first=lsb_first) # 8b/10b Decoder.

Expand All @@ -184,8 +184,13 @@ def __init__(self, lsb_first=False):
# ------------
self.timer = timer = PCSSGMIITimer(speed=self.sgmii_speed)

# Speed adaptation
self.comb += source.ce.eq(source.valid & timer.done)
# Buffer.
# -------
self.buffer = buffer = stream.Buffer([("data", 8)])
self.comb += If(timer.done,
buffer.source.connect(source),
source.last.eq(buffer.source.valid & ~buffer.sink.valid), # Last when next is not valid.
)

# FSM.
# ----
Expand All @@ -201,8 +206,8 @@ def __init__(self, lsb_first=False):
# K-character is Start-of-packet /S/.
If(self.decoder.d == K(27, 7),
timer.enable.eq(1),
source.valid.eq(1),
source.data.eq(0x55), # First Preamble Byte.
buffer.sink.valid.eq(1),
buffer.sink.data.eq(0x55), # First Preamble Byte.
NextState("DATA")
)
)
Expand Down Expand Up @@ -245,8 +250,8 @@ def __init__(self, lsb_first=False):
If(~self.decoder.k,
# Receive Data.
timer.enable.eq(1),
source.valid.eq(1),
source.data.eq(self.decoder.d),
buffer.sink.valid.eq(timer.done),
buffer.sink.data.eq(self.decoder.d),
NextState("DATA")
)
)
Expand Down Expand Up @@ -276,17 +281,11 @@ def __init__(self, lsb_first=False, check_period=6e-3, more_ack_time=10e-3, sgmi

# # #

# Sink -> TX.
self.comb += self.sink.connect(self.tx.sink, omit={"last_be", "error"})

# RX -> Source.
rx_source_valid_d = Signal()
self.sync.eth_rx += [
rx_source_valid_d.eq(self.rx.source.valid),
self.source.valid.eq(self.rx.source.ce),
self.source.data.eq(self.rx.source.data),
# Sink -> TX / RX -> Source.
self.comb += [
self.sink.connect(self.tx.sink, omit={"last_be", "error"}),
self.rx.source.connect(self.source, omit={"last_be", "error"}),
]
self.comb += self.source.last.eq(~self.rx.source.valid & rx_source_valid_d)

# Seen Valid Synchronizer.
self.seen_valid_ci = seen_valid_ci = PulseSynchronizer("eth_rx", "eth_tx")
Expand Down

0 comments on commit cd2274d

Please sign in to comment.