📄 testblock_tb.v
字号:
`timescale 1ns / 1psmodule testblock_tb; // Inputs reg i_nreset; reg i_sclk; reg i_spi_cse; reg i_spi_clk; reg i_spi_sdi; reg i_spi_en; reg [7:0] dat1; reg [7:0] dat2; reg [7:0] dat3; reg [7:0] dat4; reg [7:0] dat5; reg [7:0] dat6; reg [7:0] dat7; // Outputs wire o_spi_sdo; ///////##### clock #### parameter clk_1Mhz = 1000; parameter clk_2Mhz = 500; parameter clk_4Mhz = 250; parameter clk_5Mhz = 200; parameter clk_10Mhz = 100; parameter clk_20Mhz = 50; parameter clk_50Mhz = 20; ////////##### clock #### parameter clk =10; ///////##### SPI clock #### parameter clock=50.0; integer data_out_file; always #(clk/2.0) i_sclk=~i_sclk; task write_memory; input [7:0] waddr; input [7:0] data1; input [7:0] data2; input [7:0] data3; reg [3:0] cnt; parameter [7:0] number =8'b10000011; begin cnt = 4'b1000; i_spi_clk= 1'b0; i_spi_cse =1'b1; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = waddr[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end // i_spi_cse =1'b1; cnt = 4'b1000; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = number[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end // i_spi_cse =1'b1; cnt = 4'b1000; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = data1[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end // i_spi_cse =1'b1; cnt = 4'b1000; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = data2[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end // i_spi_cse =1'b1; cnt = 4'b1000; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = data3[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end i_spi_cse =1'b1; end endtask task read_memory; input [7:0] raddr; reg [3:0] cnt; parameter [7:0] number =8'b00000011;begin i_spi_cse =1'b1; i_spi_clk= 1'b0; #1000; i_spi_cse =1'b0; cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = raddr[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end //i_spi_cse =1'b1; #1000; i_spi_cse =1'b0; cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = number[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end // i_spi_cse =1'b1; #1000; i_spi_cse =1'b0; cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat1[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end //i_spi_cse =1'b1; #1000; i_spi_cse =1'b0; cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat2[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end //i_spi_cse =1'b1; #1000; i_spi_cse =1'b0; cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat3[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end i_spi_cse =1'b1; end endtask task read1; input [7:0] raddr; reg [3:0] cnt; parameter [7:0] number =8'b00000001;begin i_spi_cse =1'b1; i_spi_clk= 1'b0; cnt = 4'b1000; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = raddr[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = number[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat1[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end i_spi_cse =1'b1; end endtask task read2; input [7:0] raddr; reg [3:0] cnt; parameter [7:0] number =8'b00000010; begin i_spi_cse =1'b1; i_spi_clk= 1'b0; cnt = 4'b1000; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = raddr[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = number[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat1[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat2[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end i_spi_cse =1'b1; end endtask task read3; input [7:0] raddr; reg [3:0] cnt; parameter [7:0] number =8'b00000011; begin i_spi_cse =1'b1; i_spi_clk= 1'b0; cnt = 4'b1000; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = raddr[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = number[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat1[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat2[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat3[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end i_spi_cse =1'b1; end endtask task read3_error_long; input [7:0] raddr; reg [3:0] cnt; parameter [7:0] number =8'b00000011; begin i_spi_cse =1'b1; i_spi_clk= 1'b0; cnt = 4'b1000; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = raddr[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = number[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat1[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat2[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat3[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat3[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end i_spi_cse =1'b1; end endtask task read3_error_short; input [7:0] raddr; reg [3:0] cnt; parameter [7:0] number =8'b00000011; begin i_spi_cse =1'b1; i_spi_clk= 1'b0; cnt = 4'b1000; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = raddr[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = number[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat1[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat2[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end i_spi_cse =1'b1; end endtask task read7; input [7:0] raddr; reg [3:0] cnt; parameter [7:0] number =8'b00000111; begin i_spi_cse =1'b1; i_spi_clk= 1'b0; cnt = 4'b1000; #1000; i_spi_cse =1'b0; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = raddr[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; i_spi_sdi = number[cnt]; #(clock/2.0); i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat1[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat2[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat3[cnt] = o_spi_sdo; i_spi_clk= 1'b0; #(clock/2.0); end cnt = 4'b1000; while (cnt > 4'b0000) begin cnt =cnt-1; i_spi_clk= 1'b1; #(clock/2.0); dat4[cnt] = o_spi_sdo;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -