mac/sram: Add dw=8, 16 support and simplify logic (let the toolchain unused logic for 8/16/32-bit dw automatically).

This commit is contained in:
Florent Kermarrec 2021-10-30 23:28:10 +02:00
parent 2ec2669f6b
commit 1b25f7781c
1 changed files with 24 additions and 42 deletions

View File

@ -23,7 +23,7 @@ class LiteEthMACSRAMWriter(Module, AutoCSR):
self.crc_error = Signal() self.crc_error = Signal()
# Parameters Check / Compute. # Parameters Check / Compute.
assert dw in [32, 64] assert dw in [8, 16, 32, 64]
slotbits = max(int(math.log2(nslots)), 1) slotbits = max(int(math.log2(nslots)), 1)
lengthbits = bits_for(depth * dw//8) lengthbits = bits_for(depth * dw//8)
@ -55,14 +55,6 @@ class LiteEthMACSRAMWriter(Module, AutoCSR):
sink.ready.reset = 1 sink.ready.reset = 1
# Decode Length increment from from last_be. # Decode Length increment from from last_be.
if dw == 32:
self.comb += Case(sink.last_be, {
0b0001 : length_inc.eq(1),
0b0010 : length_inc.eq(2),
0b0100 : length_inc.eq(3),
"default" : length_inc.eq(4)
})
else:
self.comb += Case(sink.last_be, { self.comb += Case(sink.last_be, {
0b00000001 : length_inc.eq(1), 0b00000001 : length_inc.eq(1),
0b00000010 : length_inc.eq(2), 0b00000010 : length_inc.eq(2),
@ -71,7 +63,7 @@ class LiteEthMACSRAMWriter(Module, AutoCSR):
0b00010000 : length_inc.eq(5), 0b00010000 : length_inc.eq(5),
0b00100000 : length_inc.eq(6), 0b00100000 : length_inc.eq(6),
0b01000000 : length_inc.eq(7), 0b01000000 : length_inc.eq(7),
"default" : length_inc.eq(8) "default" : length_inc.eq(dw//8)
}) })
# Status FIFO. # Status FIFO.
@ -173,7 +165,7 @@ class LiteEthMACSRAMReader(Module, AutoCSR):
self.source = source = stream.Endpoint(eth_phy_description(dw)) self.source = source = stream.Endpoint(eth_phy_description(dw))
# Parameters Check / Compute. # Parameters Check / Compute.
assert dw in [32, 64] assert dw in [8, 16, 32, 64]
slotbits = max(int(math.log2(nslots)), 1) slotbits = max(int(math.log2(nslots)), 1)
lengthbits = bits_for(depth * dw//8) lengthbits = bits_for(depth * dw//8)
@ -222,16 +214,6 @@ class LiteEthMACSRAMReader(Module, AutoCSR):
# Encode Length to last_be. # Encode Length to last_be.
length_lsb = cmd_fifo.source.length[0:int(math.log2(dw//8))] length_lsb = cmd_fifo.source.length[0:int(math.log2(dw//8))]
if dw == 32:
self.comb += If(source.last,
Case(length_lsb, {
1 : source.last_be.eq(0b0001),
2 : source.last_be.eq(0b0010),
3 : source.last_be.eq(0b0100),
"default" : source.last_be.eq(0b1000),
})
)
else:
self.comb += If(source.last, self.comb += If(source.last,
Case(length_lsb, { Case(length_lsb, {
1 : source.last_be.eq(0b00000001), 1 : source.last_be.eq(0b00000001),
@ -241,7 +223,7 @@ class LiteEthMACSRAMReader(Module, AutoCSR):
5 : source.last_be.eq(0b00010000), 5 : source.last_be.eq(0b00010000),
6 : source.last_be.eq(0b00100000), 6 : source.last_be.eq(0b00100000),
7 : source.last_be.eq(0b01000000), 7 : source.last_be.eq(0b01000000),
"default" : source.last_be.eq(0b10000000), "default" : source.last_be.eq(2**(dw//8 - 1)),
}) })
) )