From 6511bfc637f773f9fa56722c4f7de9e7f388e478 Mon Sep 17 00:00:00 2001 From: morgan Date: Thu, 3 Oct 2024 12:18:32 +0800 Subject: [PATCH] pipeline GW: add back crc for handling stream pak --- src/gateware/cxp_pipeline.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/gateware/cxp_pipeline.py b/src/gateware/cxp_pipeline.py index 80fb0df..d1c02a6 100644 --- a/src/gateware/cxp_pipeline.py +++ b/src/gateware/cxp_pipeline.py @@ -1,6 +1,7 @@ from migen import * from misoc.interconnect.csr import * from misoc.interconnect import stream +from misoc.cores.liteeth_mini.mac.crc import LiteEthMACCRCEngine, LiteEthMACCRCChecker char_width = 8 char_layout = [("data", char_width), ("k", char_width//8)] @@ -448,3 +449,34 @@ class CXP_Trig_Ack_Checker(Module, AutoCSR): ) ) ) + +@ResetInserter() +@CEInserter() +class CXPCRC32(Module): + # Section 9.2.2.2 (CXP-001-2021) + width = 32 + polynom = 0x04C11DB7 + seed = 2**width-1 + check = 0x00000000 + def __init__(self, data_width): + self.data = Signal(data_width) + self.value = Signal(self.width) + self.error = Signal() + + # # # + + self.submodules.engine = LiteEthMACCRCEngine(data_width, self.width, self.polynom) + reg = Signal(self.width, reset=self.seed) + self.sync += reg.eq(self.engine.next) + self.comb += [ + self.engine.data.eq(self.data), + self.engine.last.eq(reg), + + self.value.eq(reg[::-1]), + self.error.eq(self.engine.next != self.check) + ] + +# For verifying crc in stream data packet +class CXPCRC32Checker(LiteEthMACCRCChecker): + def __init__(self, layout): + LiteEthMACCRCChecker.__init__(self, CXPCRC32, layout)