From 6b50d83e67273b732facbeb86718b7a7e4eb1907 Mon Sep 17 00:00:00 2001 From: morgan Date: Wed, 11 Sep 2024 10:16:35 +0800 Subject: [PATCH] pipeline GW: add test packet --- src/gateware/cxp_pipeline.py | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/gateware/cxp_pipeline.py b/src/gateware/cxp_pipeline.py index 001fb04..f440642 100644 --- a/src/gateware/cxp_pipeline.py +++ b/src/gateware/cxp_pipeline.py @@ -278,3 +278,62 @@ class TX_Command_Packet(Module, AutoCSR): ), ) ] + +class TX_Test_Packet(Module, AutoCSR): + def __init__(self, layout): + + self.stb = CSR() + + # # # + + testdata_src = stream.Endpoint(layout) + + + # Section 9.9.2 (CXP-001-2021) + # 0x00, 0x01 ... 0xFF need to be send 16 times + # cnt[8:12] is used to count up 16 times while cnt[:8] is the data + + cnt = Signal(max=0x1000) + clr_cnt = Signal() + inc_cnt = Signal() + + self.sync += [ + If(clr_cnt, + cnt.eq(cnt.reset), + ).Elif(inc_cnt, + cnt.eq(cnt + 1), + ), + ] + + self.submodules.fsm = fsm = FSM(reset_state="IDLE") + + fsm.act("IDLE", + clr_cnt.eq(1), + If(self.stb.re, + NextState("WRITE") + ) + ) + + fsm.act("WRITE", + testdata_src.stb.eq(1), + testdata_src.data.eq(cnt[:8]), + testdata_src.k.eq(0), + If(cnt == 0xFFF, + testdata_src.eop.eq(1), + If(testdata_src.ack, NextState("IDLE")) + ).Else( + inc_cnt.eq(testdata_src.ack) + ) + ) + + self.submodules.pak_type_inserter = pak_type_inserter = Code_Inserter(layout) + self.submodules.pak_wrp = pak_wrp = Packet_Wrapper(layout) + self.comb += [ + pak_type_inserter.data.eq(0x04), + pak_type_inserter.k.eq(0x04), + + testdata_src.connect(pak_type_inserter.sink), + pak_type_inserter.source.connect(pak_wrp.sink), + ] + + self.source = pak_wrp.source