⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testblock_tb.v

📁 spi slave 8bit address 1bit r/w 7bit number data
💻 V
📖 第 1 页 / 共 2 页
字号:
	 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);	 dat5[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);	 dat6[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);	 dat7[cnt] = o_spi_sdo;	 i_spi_clk= 1'b0;  	 #(clock/2.0);	  end 	  		  i_spi_cse =1'b1;	 	     end   endtask 			  		   task write1; input [7:0] waddr;	  input [7:0] data1;  reg [3:0] cnt;  parameter [7:0] number =8'b10000001; begin 					  	          i_spi_clk= 1'b0;       i_spi_cse =1'b1;	   	      #1000;      cnt = 4'b1000;   	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     		       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; 	 	  i_spi_sdi = data1[cnt];	  #(clock/2.0);	  	  i_spi_clk= 1'b0;  	  #(clock/2.0);	 end   		    i_spi_cse =1'b1;   end  endtask 				 task write2; input [7:0] waddr;	  input [7:0] data1;  input [7:0] data2;  reg [3:0] cnt;					    parameter [7:0] number =8'b10000010;  begin 					  	          i_spi_clk= 1'b0;       i_spi_cse =1'b1;	   	      #1000;      cnt = 4'b1000;   	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     		       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; 	 	  i_spi_sdi = data1[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 = data2[cnt];	  #(clock/2.0);	  	  i_spi_clk= 1'b0;  	  #(clock/2.0);	 end   				 	 	   i_spi_cse =1'b1;   end  endtask 			   task write3; 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 	          i_spi_clk= 1'b0;       i_spi_cse =1'b1;	   	      #1000;  	    cnt = 4'b1000;    	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         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; 	 	  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;    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       cnt = 4'b1000;   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 write3_error_long; 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 	          i_spi_clk= 1'b0;       i_spi_cse =1'b1;	   	      #1000;  	    cnt = 4'b1000;    	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         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; 	 	  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;    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   	   	        cnt = 4'b1000;   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         cnt = 4'b1000;   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 write3_error_short; 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 	          i_spi_clk= 1'b0;       i_spi_cse =1'b1;	   	      #1000;  	    cnt = 4'b1000;    	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         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; 	 	  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;    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;   end  endtask 		task write7; input [7:0] waddr;	  input [7:0] data1; input [7:0] data2; input [7:0] data3; input [7:0] data4; input [7:0] data5;input  [7:0] data6; input  [7:0] data7;    reg [3:0] cnt;				 parameter [7:0] number =8'b10000111; begin 	          i_spi_clk= 1'b0;       i_spi_cse =1'b1;	   	      #1000;  	    cnt = 4'b1000;    	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         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; 	 	  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;    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       cnt = 4'b1000;   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   	        cnt = 4'b1000;   while (cnt  >  4'b0000) begin      cnt =cnt-1;	  i_spi_clk= 1'b1; 	 	  i_spi_sdi = data4[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 = data5[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 = data6[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 = data7[cnt];	  #(clock/2.0);	  	  i_spi_clk= 1'b0;	   #(clock/2.0);  end   			      i_spi_cse =1'b1;   end  endtask 														 // ------------ Port declarations --------- //	testblock u_testblock (		.i_nreset(i_nreset), 		.i_sclk(i_sclk), 		.i_spi_clk(i_spi_clk), 		.i_spi_cse(i_spi_cse), 		.i_spi_en(i_spi_en), 		.i_spi_sdi(i_spi_sdi), 		.o_spi_sdo(o_spi_sdo),		.o_done(o_done),		.o_busy(o_busy),		.o_error(o_error)			);	 			initial begin		// Initialize Inputs		i_nreset = 1;		i_sclk = 0;		i_spi_cse = 1;		i_spi_clk = 0;		i_spi_sdi = 0;		i_spi_en = 0;			// Wait 100 ns for global reset to finish		#100		i_nreset = 0;		#100		 		i_nreset = 1;			i_spi_en = 1;				 	// R/W 囱赁释 0: Transfer(READ) 1: receive data(WRITE)		data_out_file = $fopen("./READ_DATA.dat");	   				#1000; 																			 				write1(8'h00,8'h11); // address , data1									#1000; 																						read1(8'h00 ); 						$fdisplay( data_out_file ,"%h", dat1 );													#1000; 																			 				write2(8'h00, 8'h22,8'h33); // address , data1, data2 						#1000; 																						read2(8'h00 ); 										$fdisplay( data_out_file ,"%h", dat1," %h", dat2 );					#1000; 																			 				write3_error_short(8'h03, 8'h44,8'h55,8'h66); // address , data1, data2 ,data3 						#1000; 																						read3_error_long(8'h03 ); 										$fdisplay( data_out_file ,"%h", dat1," %h", dat2," %h", dat3 );							#1000; 																			 				write7(8'h00, 8'haa,8'hbb,8'hcc, 8'hdd,8'hee,8'hff, 8'hff); // address , data1, data2 ,data3 ,data4, data5 ,data6,,data7							#1000; 																						read7(8'h00 ); 										$fdisplay( data_out_file ,"%h", dat1," %h", dat2," %h", dat3," %h", dat4," %h", dat5," %h", dat6," %h", dat7   );											   				$fclose( data_out_file); 				#30000;		$finish;							  	end		 		initial begin        	$shm_open("./WAVE/rtl_spi.shm");        	$shm_probe("AS");	end					      endmodule

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -