diff --git a/liteeth/mac/common.py b/liteeth/mac/common.py index b0160d9..60dab83 100644 --- a/liteeth/mac/common.py +++ b/liteeth/mac/common.py @@ -1,7 +1,7 @@ # # This file is part of LiteEth. # -# Copyright (c) 2015-2021 Florent Kermarrec +# Copyright (c) 2015-2024 Florent Kermarrec # SPDX-License-Identifier: BSD-2-Clause from liteeth.common import * @@ -55,3 +55,31 @@ class LiteEthMACCrossbar(LiteEthCrossbar): raise ValueError("Ethernet type {0:#x} already assigned".format(ethernet_type)) self.users[ethernet_type] = port return port + +# Last Handler ------------------------------------------------------------------------------------- + +class LiteEthLastHandler(LiteXModule): + def __init__(self, layout): + self.sink = sink = stream.Endpoint(layout) + self.source = source = stream.Endpoint(layout) + + # # # + + self.fsm = fsm = FSM(reset_state="COPY") + fsm.act("COPY", + sink.connect(source), + source.last.eq(sink.last_be != 0), + If(sink.valid & sink.ready, + # If last Byte but not last packet token. + If(source.last & ~sink.last, + NextState("WAIT-LAST") + ) + ) + ) + fsm.act("WAIT-LAST", + # Accept incoming stream until we receive last packet token. + sink.ready.eq(1), + If(sink.valid & sink.last, + NextState("COPY") + ) + ) diff --git a/liteeth/mac/last_be.py b/liteeth/mac/last_be.py index 329f4f8..7abf4d4 100644 --- a/liteeth/mac/last_be.py +++ b/liteeth/mac/last_be.py @@ -1,46 +1,36 @@ # # This file is part of LiteEth. # -# Copyright (c) 2015-2020 Florent Kermarrec +# Copyright (c) 2015-2024 Florent Kermarrec # Copyright (c) 2015 Sebastien Bourdeauducq # Copyright (c) 2018 whitequark # SPDX-License-Identifier: BSD-2-Clause -from liteeth.common import * +from litex.gen import * + +from liteeth.common import * +from liteeth.mac.common import LiteEthLastHandler # MAC TX Last BE ----------------------------------------------------------------------------------- -class LiteEthMACTXLastBE(Module): +class LiteEthMACTXLastBE(LiteXModule): def __init__(self, dw): - self.sink = sink = stream.Endpoint(eth_phy_description(dw)) + self.sink = sink = stream.Endpoint(eth_phy_description(dw)) self.source = source = stream.Endpoint(eth_phy_description(dw)) # # # - self.submodules.fsm = fsm = FSM(reset_state="COPY") - fsm.act("COPY", - sink.connect(source), - source.last.eq(sink.last_be != 0), - If(sink.valid & sink.ready, - # If last Byte but not last packet token. - If(source.last & ~sink.last, - NextState("WAIT-LAST") - ) - ) - ) - fsm.act("WAIT-LAST", - # Accept incoming stream until we receive last packet token. - sink.ready.eq(1), - If(sink.valid & sink.last, - NextState("COPY") - ) - ) + self.last_handler = LiteEthLastHandler(layout=eth_phy_description(dw)) + self.comb += [ + sink.connect(self.last_handler.sink), + self.last_handler.source.connect(source), + ] # MAC RX Last BE ----------------------------------------------------------------------------------- class LiteEthMACRXLastBE(Module): def __init__(self, dw): - self.sink = sink = stream.Endpoint(eth_phy_description(dw)) + self.sink = sink = stream.Endpoint(eth_phy_description(dw)) self.source = source = stream.Endpoint(eth_phy_description(dw)) # # #