Skip to content

Commit

Permalink
liteeth/mac/core: simplify and fix padding
Browse files Browse the repository at this point in the history
enjoy-digital committed Apr 24, 2015
1 parent ff2d1d9 commit 2d56d32
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions misoclib/com/liteeth/mac/core/padding.py
Original file line number Diff line number Diff line change
@@ -3,24 +3,29 @@


class LiteEthMACPaddingInserter(Module):
def __init__(self, dw, packet_min_length):
def __init__(self, dw, padding):
self.sink = sink = Sink(eth_phy_description(dw))
self.source = source = Source(eth_phy_description(dw))

# # #

packet_min_data = math.ceil(packet_min_length/(dw/8))
padding_limit = math.ceil(padding/(dw/8))-1

self.submodules.counter = counter = Counter(max=eth_mtu)
self.submodules.counter = counter = Counter(16, reset=1)
counter_done = Signal()
self.comb += [
counter.reset.eq(sink.stb & sink.sop & sink.ack),
counter.ce.eq(source.stb & source.ack),
counter_done.eq(counter.value >= padding_limit),
]

self.submodules.fsm = fsm = FSM(reset_state="COPY")
fsm.act("COPY",
counter.reset.eq(sink.stb & sink.sop),
self.submodules.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE",
Record.connect(sink, source),
If(sink.stb & sink.ack,
If(source.stb & source.ack,
counter.ce.eq(1),
If(sink.eop,
If(counter.value < packet_min_data,
If(~counter_done,
source.eop.eq(0),
NextState("PADDING")
)
@@ -29,12 +34,11 @@ def __init__(self, dw, packet_min_length):
)
fsm.act("PADDING",
source.stb.eq(1),
source.eop.eq(counter.value == packet_min_data),
source.eop.eq(counter_done),
source.data.eq(0),
If(source.ack,
counter.ce.eq(1),
If(source.eop,
NextState("COPY")
If(counter_done,
NextState("IDLE")
)
)
)

0 comments on commit 2d56d32

Please sign in to comment.