102 lines
3.8 KiB
Systemverilog
102 lines
3.8 KiB
Systemverilog
`timescale 1ns/1ps
|
|
module tb_zynq_la_stream;
|
|
reg clk=0;
|
|
always #5 clk=~clk;
|
|
reg aresetn=0;
|
|
reg [7:0] digital_inputs=0;
|
|
reg [11:0] s_axi_awaddr=0,s_axi_araddr=0;
|
|
reg [31:0] s_axi_wdata=0;
|
|
reg [3:0] s_axi_wstrb=15;
|
|
reg s_axi_awvalid=0,s_axi_wvalid=0,s_axi_bready=1;
|
|
reg s_axi_arvalid=0,s_axi_rready=1;
|
|
wire s_axi_awready,s_axi_wready,s_axi_bvalid,s_axi_arready,s_axi_rvalid;
|
|
wire [1:0] s_axi_bresp,s_axi_rresp;
|
|
wire [31:0] s_axi_rdata,m_axi_awaddr;
|
|
wire [7:0] m_axi_awlen,m_axi_wstrb;
|
|
wire [2:0] m_axi_awsize,m_axi_awprot;
|
|
wire [1:0] m_axi_awburst;
|
|
wire [3:0] m_axi_awcache;
|
|
wire m_axi_awvalid,m_axi_wlast,m_axi_wvalid,m_axi_bready;
|
|
wire [63:0] m_axi_wdata;
|
|
reg m_axi_bvalid=0;
|
|
reg [1:0] m_axi_bresp=0;
|
|
reg pause_data=0, check_bytes=1;
|
|
integer cycle=0;
|
|
wire m_axi_awready = cycle % 5 == 3;
|
|
wire m_axi_wready = !pause_data && cycle % 3 != 0;
|
|
zynq_la_stream dut(.*);
|
|
|
|
reg [7:0] expected[0:65535];
|
|
integer captured=0, transmitted=0, bursts=0, beat=0, i;
|
|
always @(negedge clk) begin
|
|
cycle=cycle+1;
|
|
digital_inputs=digital_inputs+1;
|
|
end
|
|
always @(posedge clk) if(aresetn) begin
|
|
if(dut.sample_now && check_bytes) begin
|
|
expected[captured]=digital_inputs-8'd2;
|
|
captured=captured+1;
|
|
end
|
|
if(m_axi_awvalid && m_axi_awready) begin
|
|
if(m_axi_awaddr!==32'h3e000000+128*bursts || m_axi_awlen!=15 ||
|
|
m_axi_awsize!=3 || m_axi_awburst!=1) $fatal(1,"bad DDR burst address/geometry");
|
|
bursts=bursts+1;
|
|
beat=0;
|
|
end
|
|
if(m_axi_wvalid && m_axi_wready) begin
|
|
if(m_axi_wlast !== (beat==15) || m_axi_wstrb!=255) $fatal(1,"bad DDR beat");
|
|
if(check_bytes) for(i=0;i<8;i=i+1)
|
|
if(m_axi_wdata[i*8+:8]!==expected[transmitted+i])
|
|
$fatal(1,"bad DDR data index=%d got=%h expected=%h",
|
|
transmitted+i,m_axi_wdata[i*8+:8],expected[transmitted+i]);
|
|
transmitted=transmitted+8;
|
|
beat=beat+1;
|
|
if(m_axi_wlast) m_axi_bvalid<=1;
|
|
end
|
|
if(m_axi_bvalid && m_axi_bready) m_axi_bvalid<=0;
|
|
end
|
|
|
|
task write_ctrl(input [11:0] address,input [31:0] value);
|
|
begin
|
|
@(negedge clk);
|
|
s_axi_awaddr=address; s_axi_awvalid=1;
|
|
@(posedge clk);
|
|
while(!s_axi_awready) @(posedge clk);
|
|
@(negedge clk);
|
|
s_axi_awvalid=0; s_axi_wdata=value; s_axi_wvalid=1;
|
|
@(posedge clk);
|
|
while(!s_axi_wready) @(posedge clk);
|
|
@(negedge clk);
|
|
s_axi_wvalid=0;
|
|
wait(s_axi_bvalid); #1;
|
|
if(s_axi_bresp!=0) $fatal(1,"register write failed");
|
|
@(negedge clk);
|
|
end
|
|
endtask
|
|
|
|
initial begin
|
|
repeat(4) @(negedge clk); aresetn=1;
|
|
write_ctrl(12'h010,10);
|
|
write_ctrl(12'h014,1);
|
|
wait(dut.produced==1); @(negedge clk);
|
|
if(transmitted!=16384 || captured<16384 || dut.fault!=0) $fatal(1,"bad block commit");
|
|
write_ctrl(12'h01c,1);
|
|
if(dut.consumed!=1) $fatal(1,"block not acknowledged");
|
|
write_ctrl(12'h014,2);
|
|
wait(dut.state==0); @(negedge clk);
|
|
if(dut.running || dut.fault!=0) $fatal(1,"stop did not drain");
|
|
bursts=0;
|
|
check_bytes=0;
|
|
pause_data=1;
|
|
write_ctrl(12'h014,1);
|
|
wait(dut.fault==1); @(negedge clk);
|
|
if(dut.running || dut.produced!=0 || bursts!=1) $fatal(1,"overflow did not stop sampling");
|
|
pause_data=0;
|
|
wait(dut.state==0); @(negedge clk);
|
|
if(dut.produced!=0 || dut.fault!=1) $fatal(1,"overflow published incomplete data");
|
|
$display("PASS tb_zynq_la_stream byte order, stalled AXI, commit, ACK, stop and overflow");
|
|
$finish;
|
|
end
|
|
initial begin #3000000; $fatal(1,"timeout"); end
|
|
endmodule
|