62 lines
2.6 KiB
Systemverilog
62 lines
2.6 KiB
Systemverilog
`timescale 1ns/1ps
|
|
module tb_adc_frontend4;
|
|
reg arst_n=1, mezz_ready=0, adc1_clk=0, adc2_clk=0, stream_clk=0;
|
|
reg coherent_epoch_valid=0, sample_ready=1;
|
|
reg [9:0] adc1_a=0, adc1_b=200, adc2_a=400, adc2_b=600;
|
|
wire [63:0] sample_data,sample_index;
|
|
wire sample_valid,session_fault;
|
|
wire [31:0] adc1_overflow_count,adc2_overflow_count;
|
|
reg [63:0] next_index=0;
|
|
reg [9:0] first_code;
|
|
integer received=0, cycles=0;
|
|
reg checking=1;
|
|
always #5 adc1_clk=~adc1_clk;
|
|
initial begin #0.8; forever #5 adc2_clk=~adc2_clk; end
|
|
always #3 stream_clk=~stream_clk;
|
|
// Model a known common epoch only in this test. Both domains see the
|
|
// same conversion before each capture edge; hardware still needs proof.
|
|
always @(negedge adc1_clk) begin
|
|
adc1_a<=adc1_a+1'b1; adc1_b<=adc1_b+1'b1;
|
|
adc2_a<=adc2_a+1'b1; adc2_b<=adc2_b+1'b1;
|
|
end
|
|
adc_frontend4 #(.FIFO_ADDR_BITS(4)) dut (.*);
|
|
always @(negedge stream_clk) begin
|
|
cycles=cycles+1;
|
|
if (checking) sample_ready=(cycles%7 != 0);
|
|
end
|
|
always @(posedge stream_clk) begin
|
|
if (checking && sample_valid && sample_ready) begin
|
|
if (sample_index!==next_index) $fatal(1,"frontend index gap");
|
|
if (received==0) first_code=sample_data[9:0];
|
|
if (sample_data[9:0] !== ((first_code+next_index)&1023) ||
|
|
sample_data[25:16] !== ((first_code+next_index+200)&1023) ||
|
|
sample_data[41:32] !== ((first_code+next_index+400)&1023) ||
|
|
sample_data[57:48] !== ((first_code+next_index+600)&1023))
|
|
$fatal(1,"four-channel conversion association");
|
|
if ((sample_data & 64'hfc00fc00fc00fc00) !== 0) $fatal(1,"zero alignment");
|
|
received=received+1; next_index=next_index+1;
|
|
end
|
|
end
|
|
initial begin
|
|
#1 arst_n=0;
|
|
#30 arst_n=1;
|
|
#40 mezz_ready=1;
|
|
#70;
|
|
if (sample_valid) $fatal(1,"pairing without epoch permission");
|
|
coherent_epoch_valid=1;
|
|
#7000;
|
|
if (session_fault || adc1_overflow_count || adc2_overflow_count || received<690)
|
|
$fatal(1,"continuous four-channel frontend");
|
|
checking=0; sample_ready=0;
|
|
#500;
|
|
if (!session_fault) $fatal(1,"backpressure overflow not invalidated");
|
|
arst_n=0; mezz_ready=0; coherent_epoch_valid=0;
|
|
#40 arst_n=1;
|
|
#40;
|
|
if (session_fault || sample_valid) $fatal(1,"joint reset not clearing frontend");
|
|
$display("PASS tb_adc_frontend4 samples=%0d four_channels CDC_stalls_epoch_guard_overflow",received);
|
|
$finish;
|
|
end
|
|
initial begin #15000; $fatal(1,"timeout"); end
|
|
endmodule
|