mac: add interpacket gap inserter/checker

This commit is contained in:
Florent Kermarrec 2015-02-09 12:57:05 +01:00
parent 497c75e792
commit e18e403f10
4 changed files with 36 additions and 2 deletions

View File

@ -15,6 +15,7 @@ from migen.bank.description import *
eth_mtu = 1532
eth_min_len = 46
eth_interpacket_gap = 12
eth_preamble = 0xD555555555555555
buffer_depth = 2**log2_int(eth_mtu, need_pow2=False)

View File

@ -22,7 +22,7 @@ class LiteEthMACPacketizer(LiteEthPacketizer):
mac_header_len)
class LiteEthMAC(Module, AutoCSR):
def __init__(self, phy, dw, interface="crossbar", endianness="be",
def __init__(self, phy, dw, interface="crossbar", endianness="big",
with_hw_preamble_crc=True):
self.submodules.core = LiteEthMACCore(phy, dw, endianness, with_hw_preamble_crc)
self.csrs = []

View File

@ -1,5 +1,5 @@
from liteeth.common import *
from liteeth.mac.core import preamble, crc, last_be
from liteeth.mac.core import gap, preamble, crc, last_be
class LiteEthMACCore(Module, AutoCSR):
def __init__(self, phy, dw, endianness="big", with_hw_preamble_crc=True):
@ -9,6 +9,14 @@ class LiteEthMACCore(Module, AutoCSR):
rx_pipeline = [phy]
tx_pipeline = [phy]
# Interpacket gap
tx_gap_inserter = gap.LiteEthMACGap(phy.dw)
rx_gap_checker = gap.LiteEthMACGap(phy.dw, ack_on_gap=True)
self.submodules += tx_gap_inserter, rx_gap_checker
tx_pipeline += [tx_gap_inserter]
rx_pipeline += [rx_gap_checker]
# Preamble / CRC
if with_hw_preamble_crc:
self._hw_preamble_crc = CSRStatus(reset=1)

25
liteeth/mac/core/gap.py Normal file
View File

@ -0,0 +1,25 @@
from liteeth.common import *
class LiteEthMACGap(Module):
def __init__(self, dw, ack_on_gap=False):
self.sink = sink = Sink(eth_phy_description(dw))
self.source = source = Source(eth_phy_description(dw))
###
gap = math.ceil(eth_interpacket_gap/(dw//8))
self.submodules.counter = counter = Counter(max=gap)
self.submodules.fsm = fsm = FSM(reset_state="COPY")
fsm.act("COPY",
counter.reset.eq(1),
Record.connect(sink, source),
If(sink.stb & sink.eop & sink.ack,
NextState("GAP")
)
)
fsm.act("GAP",
counter.ce.eq(1),
sink.ack.eq(int(ack_on_gap)),
If(counter.value == (gap-1),
NextState("COPY")
)
)