From 89be86be882e0f9347e1265bee769b8b50ab02aa Mon Sep 17 00:00:00 2001 From: morgan Date: Fri, 20 Sep 2024 15:11:12 +0800 Subject: [PATCH] pipeline GW: refactor byte2word & cleanup --- src/gateware/cxp_pipeline.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/gateware/cxp_pipeline.py b/src/gateware/cxp_pipeline.py index 8982e6f..c254600 100644 --- a/src/gateware/cxp_pipeline.py +++ b/src/gateware/cxp_pipeline.py @@ -3,6 +3,9 @@ from misoc.interconnect.csr import * from misoc.interconnect import stream from misoc.cores.liteeth_mini.mac.crc import LiteEthMACCRCEngine, LiteEthMACCRCChecker + +import struct + upconn_dw = 8 upconn_layout = [("data", upconn_dw), ("k", upconn_dw//8)] @@ -22,12 +25,11 @@ KCode = { } -def _bytes2word(arr): - assert len(arr) == 4 - sum = 0 - for i, val in enumerate(arr): - sum += (val & 0xFF) << i*8 - return sum +def _bytes2word(bytes, big_endian=True): + if big_endian: + return struct.unpack(">I", struct.pack(">4B", *bytes))[0] + else: + return struct.unpack("4B", *bytes))[0] class Code_Source(Module): def __init__(self, layout, counts=4): @@ -390,6 +392,8 @@ class Receiver_Path(Module, AutoCSR): # TODO: self.packet_type = Signal(8) + self.decoder_err = Signal() + self.decoder_err_clr = Signal() # # # @@ -398,10 +402,19 @@ class Receiver_Path(Module, AutoCSR): self.submodules.packet_decoder = packet_decoder = CXP_Data_Packet_Decode() self.sync += [ If(trig_ack_checker.ack, - self.trig_ack.eq(1), + self.trig_ack.eq(1), ).Elif(self.trig_clr, - self.trig_ack.eq(0), + self.trig_ack.eq(0), + ), + + If(packet_decoder.decode_err, + self.decoder_err.eq(1), + ).Elif(self.decoder_err_clr, + self.decoder_err.eq(0), ) + ] + self.comb += [ + self.packet_type.eq(packet_decoder.packet_type), ] @@ -465,11 +478,11 @@ class CXP_Data_Packet_Decode(Module): ).Elif(self.packet_type == type["debug"], self.sink.connect(self.source), ).Else( - # discard K29,7 self.sink.ack.eq(1), - NextValue(self.decode_err, 1), + self.decode_err.eq(1), ) ) + class CXP_Trig_Ack_Checker(Module, AutoCSR): def __init__(self): self.sink = stream.Endpoint(downconn_layout)