1
0
Fork 0

cxp pipeline: merge packet start & stop into 1 mod

This commit is contained in:
morgan 2024-08-30 16:07:25 +08:00
parent 0b8f3ba466
commit f23ce2ef70
1 changed files with 28 additions and 57 deletions

View File

@ -3,22 +3,13 @@ from misoc.interconnect.csr import *
from misoc.interconnect import stream
from misoc.cores.liteeth_mini.mac.crc import LiteEthMACCRCEngine, LiteEthMACCRCInserter
def K(x, y):
return ((y << 5) | x)
class Code_Inserter(Module):
"""Code inserter
Inserts data in the front or end of each packet.
Attributes
----------
sink : in
Packet octets.
source : out
Preamble, SFD, and packet octets.
"""
def __init__(self, cxp_phy_layout, insert_infront=True, counts=4):
self.sink = sink = stream.Endpoint(cxp_phy_layout)
self.source = source = stream.Endpoint(cxp_phy_layout)
def __init__(self, layout, insert_infront=True, counts=4):
self.sink = sink = stream.Endpoint(layout)
self.source = source = stream.Endpoint(layout)
self.data = Signal.like(sink.data)
self.k = Signal.like(sink.k)
@ -39,25 +30,25 @@ class Code_Inserter(Module):
self.submodules.fsm = fsm = FSM(reset_state="IDLE")
if insert_infront:
fsm.act("IDLE",
sink.ack.eq(1), # = writable/not full
sink.ack.eq(1),
clr_cnt.eq(1),
If(sink.stb, # = data input
sink.ack.eq(0), # = full
If(sink.stb,
sink.ack.eq(0),
NextState("INSERT"),
)
)
fsm.act("INSERT",
source.stb.eq(1), # = writing data now
sink.ack.eq(0),
source.stb.eq(1),
source.data.eq(self.data),
source.k.eq(self.k),
If(cnt == counts - 1,
If(source.ack, NextState("COPY"))
).Else(
inc_cnt.eq(source.ack)# = inc_counter only when next pipeline is ready to accept new data
inc_cnt.eq(source.ack)
)
)
@ -90,60 +81,40 @@ class Code_Inserter(Module):
)
fsm.act("INSERT",
source.stb.eq(1), # = writing data now
sink.ack.eq(0),
source.stb.eq(1),
source.data.eq(self.data),
source.k.eq(self.k),
If(cnt == counts - 1,
source.eop.eq(1),
If(source.ack, NextState("IDLE"))
).Else(
inc_cnt.eq(source.ack) # = inc_counter only when next pipeline is ready to accept new data
inc_cnt.eq(source.ack)
),
)
def K(x, y):
return ((y << 5) | x)
def D(x, y):
return ((y << 5) | x)
class Packet_Start_Inserter(Code_Inserter):
class Packet_Wrapper(Module):
def __init__(self, layout):
Code_Inserter.__init__(self, layout)
self.submodules.pak_start = pak_start = Code_Inserter(layout)
self.submodules.pak_end = pak_end = Code_Inserter(layout, insert_infront=False)
self.sink = pak_start.sink
self.source = pak_end.source
self.comb += [
self.data.eq(K(27, 7)),
self.k.eq(1),
pak_start.data.eq(K(27, 7)),
pak_start.k.eq(1),
pak_end.data.eq(K(29, 7)),
pak_end.k.eq(1),
pak_start.source.connect(pak_end.sink),
]
class Packet_End_Inserter(Code_Inserter):
def __init__(self, layout):
Code_Inserter.__init__(self, layout, insert_infront=False)
self.comb += [
self.data.eq(K(29, 7)),
self.k.eq(1),
]
@ResetInserter()
@CEInserter()
class CXPCRC32(Module):
"""CoaXPress CRC
Implement an CoaXPress CRC generator/checker.
Parameters
----------
data_width : int
Width of the data bus.
Attributes
----------
d : in
Data input.
value : out
CRC value (used for generator).
error : out
CRC error (used for checker).
"""
# Section 9.2.2.2 (CXP-001-2021)
width = 32
polynom = 0x04C11DB7