From 3e7979920a5def333c395cfa4288a9e0d5e2b5a2 Mon Sep 17 00:00:00 2001 From: David Sawatzke Date: Sun, 8 Aug 2021 21:10:01 +0200 Subject: [PATCH] mac/padding: Add 32 bit support to inserter *Should* also work for 16/64 bit --- liteeth/mac/padding.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/liteeth/mac/padding.py b/liteeth/mac/padding.py index 2432873..ac9f644 100644 --- a/liteeth/mac/padding.py +++ b/liteeth/mac/padding.py @@ -14,12 +14,14 @@ from liteeth.common import * class LiteEthMACPaddingInserter(Module): def __init__(self, dw, padding): + assert dw in [8, 16, 32, 64] self.sink = sink = stream.Endpoint(eth_phy_description(dw)) self.source = source = stream.Endpoint(eth_phy_description(dw)) # # # padding_limit = math.ceil(padding/(dw/8))-1 + last_be = 2**((padding-1)%(dw//8)) counter = Signal(16) counter_done = Signal() @@ -33,8 +35,14 @@ class LiteEthMACPaddingInserter(Module): If(sink.last, If(~counter_done, source.last.eq(0), + source.last_be.eq(0), NextState("PADDING") - ).Else( + ).Elif((counter == padding_limit) & (last_be > sink.last_be), + # If the right amount of data words are transmitted, but + # too few bytes, transmit more bytes of the word. The + # formerly "unused" bytes get transmitted as well + source.last_be.eq(last_be) + ). Else( NextValue(counter, 0), ) ) @@ -42,7 +50,9 @@ class LiteEthMACPaddingInserter(Module): ) fsm.act("PADDING", source.valid.eq(1), - source.last.eq(counter_done), + If(counter_done, + source.last_be.eq(last_be), + source.last.eq(1)), source.data.eq(0), If(source.valid & source.ready, NextValue(counter, counter + 1),