Files
templates/hdl/scope-acquisition/tests/tb_capture_stream.sv
T

59 lines
2.3 KiB
Systemverilog

`timescale 1ns/1ps
module tb_capture_stream;
reg arst_n=1, adc_clk=0, ready_async=0, stream_clk=0, stream_ready=1;
reg [9:0] adc_data_a=0, adc_data_b=1023;
wire [95:0] stream_data;
wire stream_valid, session_fault;
wire [31:0] overflow_count_adc;
integer received=0;
reg [9:0] first_code;
reg [63:0] next_index=0;
reg checking=1;
always #5 adc_clk=~adc_clk;
always #3 stream_clk=~stream_clk;
always @(negedge adc_clk) begin
adc_data_a <= adc_data_a+1'b1;
adc_data_b <= adc_data_b-1'b1;
end
capture_stream #(.FIFO_ADDR_BITS(3)) dut (.*);
always @(posedge stream_clk) begin
if (stream_valid && stream_ready && checking) begin
if (stream_data[95:32] !== next_index) $fatal(1,"lost/reordered capture index");
if (received==0) first_code=stream_data[9:0];
if (stream_data[9:0] !== ((first_code+next_index) & 1023))
$fatal(1,"capture/FIFO data association");
if (stream_data[25:16] !== (~stream_data[9:0] & 1023))
$fatal(1,"channel association");
if ((stream_data[31:0] & 32'hfc00fc00) !== 0)
$fatal(1,"alignment");
next_index=next_index+1;
received=received+1;
end
end
initial begin
#1 arst_n=0;
#30 arst_n=1;
#40 ready_async=1;
#5000;
if (received<480 || session_fault || overflow_count_adc) $fatal(1,"continuous capture failed");
// A common READY gap does not produce an index gap: sticky sideband must catch it.
checking=0; ready_async=0;
#100;
if (!session_fault) $fatal(1,"READY loss not reported");
ready_async=1;
#100;
if (!session_fault) $fatal(1,"fault was not sticky");
// Joint reset discards this session and its queued data.
arst_n=0; stream_ready=0; ready_async=0;
#40 arst_n=1;
#40;
if (session_fault || overflow_count_adc) $fatal(1,"fault not reset");
ready_async=1;
#500;
if (!session_fault || overflow_count_adc==0) $fatal(1,"overflow not reported");
$display("PASS tb_capture_stream continuous_samples=%0d READY_loss_and_overflow",received);
$finish;
end
initial begin #10000; $fatal(1,"timeout"); end
endmodule