upd: new accum integration; secure data receive function

This commit is contained in:
2026-07-28 18:43:58 +03:00
parent 23731b95c3
commit c5bb953d81
+33 -27
View File
@@ -189,7 +189,8 @@ module reflectometer_tb;
input logic [31:0] pulse_period,
input logic [15:0] pulse_num,
input logic [13:0] pulse_height, // achtung! p_height strictly must have 14 bits of width
input logic [31:0] pulse_period_adc
input logic [31:0] pulse_period_adc,
input logic [31:0] window_size
);
// Создаем временный фиксированный массив и упаковываем всё одной строкой
logic [7:0] tx_packet[];
@@ -207,6 +208,9 @@ module reflectometer_tb;
};
vif.master_send(tx_packet);
// TODO remove for new controller
WINDOW_SIZE = window_size;
endtask
// Таски сбора статистики
@@ -218,13 +222,13 @@ module reflectometer_tb;
);
logic [7:0] rx_packet[];
logic [ACCUM_WIDTH-1:0] data_packet[];
int packet_num = $ceil(real'(sample_num / WINDOW_SIZE) / real'(PACKET_SIZE));
int numbers_per_packet = PACKET_SIZE/(ACCUM_WIDTH/8);
int idx = 0, timeout_flag = 0;
int packet_num = $ceil(real'(sample_num / WINDOW_SIZE) / real'(numbers_per_packet));
int timeout_flag = 0;
int packet_counter = 0;
if (sample_num % WINDOW_SIZE) begin
$display("[TB] -dut_read_output- Error, sample_num must be multiple of WINDOW_SIZE: %0d %% %0d = %0d", sample_num, WINDOW_SIZE, sample_num % WINDOW_SIZE);
$display("[ERROR] -dut_read_output- Sample_num must be multiple of WINDOW_SIZE: %0d %% %0d = %0d", sample_num, WINDOW_SIZE, sample_num % WINDOW_SIZE);
$finish;
end
@@ -246,7 +250,16 @@ module reflectometer_tb;
wait(processing_done == 1);
// recv loop
for (int i = 0; i < packet_num; i++) begin
// если число пакетов превышает заложенное предрассчитанное значение -- ошибка
fork : recv_loop_proc
begin
// packet recv loop
forever begin
if (packet_counter > packet_num) begin
$display("[ERROR] -dut_read_output- Packet overflow detected. Number of data packets exceeds expected amount of packets");
$finish;
end
if (randomize_recv_delays)
repeat($urandom_range(0, 500)) @(posedge clk_eth_phy);
@@ -264,7 +277,6 @@ module reflectometer_tb;
join_any
disable receive_packet_timeout;
if (timeout_flag) begin
$display("[ERROR] -dut_read_output- Timeout detected when receiving packet");
$finish;
@@ -272,17 +284,27 @@ module reflectometer_tb;
if (rx_packet.size() != PACKET_SIZE) begin
$display("[ERROR] -dut_read_output- Wrong packet size received: %0d bytes received, %0d bytes expected", rx_packet.size(), PACKET_SIZE);
$finish;
end
// unpack values
data_packet = {<< byte {rx_packet}};
data_packet = {<< ACCUM_WIDTH {data_packet}};
// copy and convert values
for (int j = 0; j < data_packet.size(); j++) begin
output_data[i * data_packet.size() + j] = int'(data_packet[j]);
end
output_data[(packet_counter-1) * data_packet.size() + j] = int'(data_packet[j]);
end
end
end
begin
// IP workflow completion event
wait(workflow_done == 1);
end
join_any
disable recv_loop_proc;
disable packet_counter_proc;
if (packet_counter != packet_num) begin
@@ -290,24 +312,6 @@ module reflectometer_tb;
$finish;
end
// Wait until full transaction of data is complete
timeout_flag = 0;
fork : workflow_timeout
begin
wait(workflow_done == 1);
end
begin
repeat(10) @(negedge clk_adc); // sampler clock
timeout_flag = 1;
end
join_any
disable workflow_timeout;
if (timeout_flag) begin
$display("[ERROR] -dut_read_output- Timeout detected when awaiting for finish pulse");
$finish;
end
endtask
// Основная таска типового теста
@@ -343,7 +347,8 @@ module reflectometer_tb;
.pulse_period(32'd5000),
.pulse_num(16'd1),
.pulse_height(14'd15000), // 0V
.pulse_period_adc(32'd2600)
.pulse_period_adc(32'd2600),
.window_size(1)
);
#100;
dut_start(control_vif);
@@ -354,6 +359,7 @@ module reflectometer_tb;
.randomize_recv_delays(0),
.output_data(output_data)
);
#1000;
$display("Received %0d numbers", output_data.size());
for (int i = 0; i < output_data.size(); i++) begin