artiq-zynq/sim_roi.py

231 lines
12 KiB
Python
Raw Normal View History

from migen import *
from misoc.interconnect.csr import *
from misoc.interconnect import stream
from src.gateware.cxp_frame_pipeline import *
from src.gateware.cxp_pipeline import *
class ROI(Module):
def __init__(self):
fifo = stream.SyncFIFO(word_layout, 32) # to avoid data getting eaten and act as delay between eop
dchar_decoder = Duplicated_Char_Decoder()
# self.crc = CXPCRC32_Checker()
self.pipeline = ROI_Pipeline()
pipeline = [fifo, dchar_decoder, self.pipeline]
self.submodules += pipeline
for s, d in zip(pipeline, pipeline[1:]):
self.comb += s.source.connect(d.sink)
self.sink = pipeline[0].sink
self.source = pipeline[-1].source
dut = ROI()
def packet_sim(packets=[]):
print("=================TEST========================")
sink = dut.sink
cyc = len(packets)
pak = packets
for c in range(cyc):
yield sink.data.eq(pak[c]["data"])
yield sink.k.eq(pak[c]["k"])
yield sink.stb.eq(1)
if "eop" in pak[c]:
yield sink.eop.eq(1)
else:
yield sink.eop.eq(0)
yield
# extra clk cycles
for _ in range(cyc, cyc + 20):
yield sink.data.eq(0)
yield sink.k.eq(0)
yield sink.stb.eq(0)
yield sink.eop.eq(0)
yield
metadata = dut.pipeline.header_decoder.metadata
img_header_layout = [
"stream_id",
"source_tag", # image index since powering on
"x_size",
"x_offset",
"y_size",
"y_offset",
"l_size", # number of data words per image line
"pixel_format",
"tap_geo",
"flag",
]
for name in img_header_layout:
print(f"{name} = {yield getattr(metadata, name):#04X} ", end="")
print()
assert True
def testbench():
paks = [
{"data": C(0x7C7C7C7C, word_dw), "k" : Replicate(1, 4)},
{"data": C(0x01010101, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)}, # stream id
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x6AEFACF6, word_dw), "k" : Replicate(0, 4), "eop":0}, # crc
{"data": C(0x02020202, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)}, # Xsize[23:16]
{"data": C(0x09090909, word_dw), "k" : Replicate(0, 4)}, # Xsize[15:8]
{"data": C(0x90909090, word_dw), "k" : Replicate(0, 4)}, # Xsize[7:0]
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x8EE1DAA1, word_dw), "k" : Replicate(0, 4), "eop":0}, # crc
{"data": C(0x08080808, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x08080808, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)}, # DsizeL[23:16]
{"data": C(0x02020202, word_dw), "k" : Replicate(0, 4)}, # DsizeL[15:8]
{"data": C(0x64646464, word_dw), "k" : Replicate(0, 4)}, # DsizeL[7:0]
{"data": C(0x01010101, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x01010101, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x00000000, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x51C243EA, word_dw), "k" : Replicate(0, 4), "eop":0}, # crc
# the new line + pixel data
{"data": C(0x7C7C7C7C, word_dw), "k" : Replicate(1, 4)},
{"data": C(0x02020202, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0D0D0C0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0C0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0C0B0D, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0D0B0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0C0C0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0B0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0B0B0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0B0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0A0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0C0B0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0C0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0C0B0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0C0B0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0B0B0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0C0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0B0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0C0C0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0C0B0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0B0B0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0B0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0D0A, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0C0C0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0B0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0C0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0C0C0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0C0C0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0A0B0D, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0C0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0C0B0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0D0C0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0A0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0D0D0B0A, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0C0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0C0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0C0B0B0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0C0C0B, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0B0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0x0B0B0B0C, word_dw), "k" : Replicate(0, 4)},
{"data": C(0xCB5DCDD6, word_dw), "k" : Replicate(0, 4), "eop": 0}, # crc
# {"data": C(0x0C0B0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0D0B0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0D0B0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0B0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0D0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0C0A, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0D0C0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0D0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0C0D, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0A0C0C0D, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0B0B0A, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0D0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0B0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0B0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0D0B0D0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0B0D0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0B0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0B0B0A, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0A0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0D0C0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0D0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0D0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0D0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0D0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0B0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0D0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0D0C0D0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0D0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0D0C0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0D0D0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0D0B0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0B0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0B0C0B, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0B0C0C0D, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0D0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0B0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0C0C0C0C, word_dw), "k" : Replicate(0, 4)},
# {"data": C(0x0BADF020, word_dw), "k" : Replicate(0, 4), "eop":0}, # crc
]
yield from packet_sim(paks)
run_simulation(dut, testbench(), vcd_name="sim-cxp.vcd")