From c5d16668a07aafaa5187196ed36e42888f2b7bbe Mon Sep 17 00:00:00 2001 From: morgan Date: Mon, 11 Nov 2024 11:22:01 +0800 Subject: [PATCH] sim: fix frame metadata MSB problem --- sim_pipeline.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/sim_pipeline.py b/sim_pipeline.py index ad9a7ed..75da65b 100644 --- a/sim_pipeline.py +++ b/sim_pipeline.py @@ -5,6 +5,8 @@ from misoc.cores.liteeth_mini.mac.crc import LiteEthMACCRCEngine from src.gateware.cxp_pipeline import * +from types import SimpleNamespace + class EOP_Marker(Module): def __init__(self): self.sink = stream.Endpoint(word_layout_dchar) @@ -276,7 +278,7 @@ class Frame_Extractor(Module): self.new_line = Signal() n_metadata_chars = 23 - self.metadata = Record([ + img_header_layout = [ ("stream_id", char_width), ("source_tag", 2*char_width), ("x_size", 3*char_width), @@ -287,8 +289,9 @@ class Frame_Extractor(Module): ("pixel_format", 2*char_width), ("tap_geo", 2*char_width), ("flag", char_width), - ]) - assert len(self.metadata.raw_bits()) == n_metadata_chars*char_width + ] + assert layout_len(img_header_layout) == n_metadata_chars*char_width + # # # @@ -332,7 +335,7 @@ class Frame_Extractor(Module): type["new_frame"]: [ self.new_frame.eq(1), NextValue(cnt, cnt.reset), - NextState("GET_STREAM_ID"), + NextState("GET_FRAME_DATA"), ], type["line_break"]: [ self.new_line.eq(1), @@ -347,11 +350,12 @@ class Frame_Extractor(Module): ) ) + packet_buffer = Signal(layout_len(img_header_layout)) case = dict( - (i, NextValue(self.metadata.raw_bits()[8*i:8*(i+1)], self.sink.dchar)) + (i, NextValue(packet_buffer[8*i:8*(i+1)], self.sink.dchar)) for i in range(n_metadata_chars) ) - fsm.act("GET_STREAM_ID", + fsm.act("GET_FRAME_DATA", self.sink.ack.eq(1), If(self.sink.stb, Case(cnt, case), @@ -364,6 +368,13 @@ class Frame_Extractor(Module): ), ) + # dissect packet + self.metadata = SimpleNamespace() + idx = 0 + for name, size in img_header_layout: + # CXP use MSB even when sending duplicate chars + setattr(self.metadata, name, reverse_bytes(packet_buffer[idx:idx+size])) + idx += size class Pixel_Decoder(Module):