testbench for accum adaptation for dma

This commit is contained in:
otroubi
2026-07-29 10:18:33 +03:00
parent 4247a107ef
commit 5eb746c0ad
2 changed files with 99 additions and 87 deletions
+45 -45
View File
@@ -4,12 +4,19 @@ module tb_accumulator_top;
localparam DATA_WIDTH = 12;
localparam ACCUM_WIDTH = 32;
localparam RW_WIDTH = 32;
localparam N_MAX = 4096;
localparam MAX_WINDOW_SIZE = 65;
localparam PACKET_SIZE = 1024;
localparam PACKET_SIZE = 32;
localparam READ_BATCH_SIZE = (PACKET_SIZE*8)/ACCUM_WIDTH;
localparam MAX_WORDS = N_MAX;
localparam MAX_SEQ_NUM = 256;
localparam int WR_WORD_BYTES = ACCUM_WIDTH/8;
localparam int RD_WORD_BYTES = RW_WIDTH/8;
localparam int PACKET_WR_WORDS = PACKET_SIZE / WR_WORD_BYTES;
localparam int PACKET_RD_WORDS = PACKET_SIZE / RD_WORD_BYTES;
logic clk_in;
logic eth_clk_in;
@@ -25,7 +32,7 @@ module tb_accumulator_top;
logic req_ready;
wire send_req;
wire [7:0] m_axis_tdata;
wire [RW_WIDTH-1:0] m_axis_tdata;
wire m_axis_tvalid;
logic m_axis_tready;
wire m_axis_tlast;
@@ -39,10 +46,10 @@ module tb_accumulator_top;
integer tests_passed;
integer packets_seen;
integer current_packet_byte_count;
integer current_packet_word_count;
integer total_words_captured;
byte packet_bytes [0:PACKET_SIZE-1];
logic [RW_WIDTH-1:0] packet_bytes [0:PACKET_RD_WORDS-1];
logic [ACCUM_WIDTH-1:0] expected_words [0:MAX_WORDS-1];
logic [ACCUM_WIDTH-1:0] captured_words_le[0:MAX_WORDS-1];
logic [ACCUM_WIDTH-1:0] captured_words_be[0:MAX_WORDS-1];
@@ -51,7 +58,8 @@ module tb_accumulator_top;
.DATA_WIDTH(DATA_WIDTH),
.ACCUM_WIDTH(ACCUM_WIDTH),
.N_MAX(N_MAX),
.PACKET_SIZE(PACKET_SIZE)
.PACKET_SIZE(PACKET_SIZE),
.RW_WIDTH(RW_WIDTH)
) dut (
.clk_in(clk_in),
.rst(rst),
@@ -62,7 +70,7 @@ module tb_accumulator_top;
.seq_num(seq_num),
.window_size(window_size),
.eth_clk_in(eth_clk_in),
.req_ready(req_ready),
.req_ready(1'b1),
.send_req(send_req),
.m_axis_tdata(m_axis_tdata),
.m_axis_tvalid(m_axis_tvalid),
@@ -85,14 +93,14 @@ module tb_accumulator_top;
integer i;
begin
packets_seen = 0;
current_packet_byte_count = 0;
current_packet_word_count = 0;
total_words_captured = 0;
for (i = 0; i < MAX_WORDS; i = i + 1) begin
expected_words[i] = '0;
captured_words_le[i] = '0;
captured_words_be[i] = '0;
end
for (i = 0; i < PACKET_SIZE; i = i + 1)
for (i = 0; i < PACKET_RD_WORDS; i = i + 1)
packet_bytes[i] = 8'h00;
end
endtask
@@ -184,7 +192,7 @@ module tb_accumulator_top;
smp_num = smp_num_i;
seq_num = seq_num_i;
window_size = window_size_i;
req_ready = 1'b1; // приемник готов заранее
req_ready = 1'b1; // ïðèåìíèê ãîòîâ çàðàíåå
exp_word_count = smp_num_i / window_size_i;
exp_packet_count = (exp_word_count + READ_BATCH_SIZE - 1) / READ_BATCH_SIZE;
@@ -219,7 +227,7 @@ module tb_accumulator_top;
end
timeout_cnt = 0;
while (packets_seen < exp_packet_count && timeout_cnt < 50 * PACKET_SIZE) begin
while (packets_seen < exp_packet_count && timeout_cnt < 50 * PACKET_RD_WORDS) begin
@(posedge eth_clk_in);
timeout_cnt = timeout_cnt + 1;
end
@@ -272,48 +280,40 @@ module tb_accumulator_top;
endtask
always @(posedge eth_clk_in) begin : CAPTURE_AXIS
integer idx;
logic [31:0] tmp_le;
logic [31:0] tmp_be;
if (rst) begin
current_packet_byte_count = 0;
end else if (m_axis_tvalid && m_axis_tready) begin
if (current_packet_byte_count < PACKET_SIZE)
packet_bytes[current_packet_byte_count] = m_axis_tdata;
current_packet_byte_count = current_packet_byte_count + 1;
if (rst) begin
current_packet_word_count <= 0;
total_words_captured <= 0;
end
else if (m_axis_tvalid && m_axis_tready) begin
if (m_axis_tlast) begin
packets_seen = packets_seen + 1;
// Ñîõðàíÿåì î÷åðåäíîå ñëîâî
if (total_words_captured < MAX_WORDS) begin
captured_words_le[total_words_captured] <= m_axis_tdata;
captured_words_be[total_words_captured] <= {
m_axis_tdata[7:0],
m_axis_tdata[15:8],
m_axis_tdata[23:16],
m_axis_tdata[31:24]
};
end
if (current_packet_byte_count != PACKET_SIZE) begin
$display("[packet] ERROR: packet size=%0d expected=%0d", current_packet_byte_count, PACKET_SIZE);
total_errors = total_errors + 1;
end
total_words_captured <= total_words_captured + 1;
current_packet_word_count <= current_packet_word_count + 1;
for (idx = 0; idx < READ_BATCH_SIZE; idx = idx + 1) begin
tmp_le = {
packet_bytes[idx*4 + 3],
packet_bytes[idx*4 + 2],
packet_bytes[idx*4 + 1],
packet_bytes[idx*4 + 0]
};
tmp_be = {
packet_bytes[idx*4 + 0],
packet_bytes[idx*4 + 1],
packet_bytes[idx*4 + 2],
packet_bytes[idx*4 + 3]
};
if (total_words_captured + idx < MAX_WORDS) begin
captured_words_le[total_words_captured + idx] = tmp_le;
captured_words_be[total_words_captured + idx] = tmp_be;
end
end
if (m_axis_tlast) begin
packets_seen <= packets_seen + 1;
total_words_captured = total_words_captured + READ_BATCH_SIZE;
current_packet_byte_count = 0;
if (current_packet_word_count + 1 != PACKET_RD_WORDS) begin
$display("[packet] ERROR: packet size=%0d expected=%0d",
current_packet_word_count + 1,
PACKET_RD_WORDS);
total_errors <= total_errors + 1;
end
current_packet_word_count <= 0;
end
end
end
initial begin
seed = 32'h1badf00d;