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

📄 tests.v

📁 USB v1.1 RTL and design specification
💻 V
📖 第 1 页 / 共 2 页
字号:
		16'h012,	// wValue
		16'h0,		// wIndex
		16'h0		// wLength
		);

// Status OK
data_in(	8'h0,		// Function Address
		8'h0		// Expected payload size
	);

$display("\n\nGetting device descriptor ...");
send_setup(	8'h12, 		// Function Address
		8'h80,		// Request Type
		GET_DESCRIPTOR,	// Request
		16'h0100,	// wValue
		16'h0,		// wIndex
		16'hff		// wLength
		);

data_in(	8'h12,		// Function Address
		8'd18		// Expected payload size
	);

// Status OK
data_out(	8'h12,		// Function Address
		8'h0		// Expected payload size
	);

$display("\n\nGetting config descriptor ...");
send_setup(	8'h12, 		// Function Address
		8'h80,		// Request Type
		GET_DESCRIPTOR,	// Request
		16'h0200,	// wValue
		16'h0,		// wIndex
		16'hff		// wLength
		);

data_in(	8'h12,		// Function Address
		8'd34		// Expected payload size
	);

// Status OK
data_out(	8'h12,		// Function Address
		8'h0		// Expected payload size
	);

#100000;

$display("\n\nSetting idle ...");
send_setup(	8'h12, 		// Function Address
		8'h21,		// Request Type
		8'h0a,	// Request
		16'h0000,	// wValue
		16'h0,		// wIndex
		16'h00		// wLength
		);

data_in(	8'h12,		// Function Address
		8'd0		// Expected payload size
	);

$display("\n\nGetting report descriptor ...");
send_setup(	8'h12, 		// Function Address
		8'h80,		// Request Type
		GET_DESCRIPTOR,	// Request
		16'h2200,	// wValue
		16'h0,		// wIndex
		16'hff		// wLength
		);

data_in(	8'h12,		// Function Address
		8'd28		// Expected payload size
	);

// Status OK
data_out(	8'h12,		// Function Address
		8'h0		// Expected payload size
	);

$display("\n\nGetting string2 descriptor ...");
send_setup(	8'h12, 		// Function Address
		8'h80,		// Request Type
		GET_DESCRIPTOR,	// Request
		16'h0302,	// wValue
		16'h0,		// wIndex
		16'h0102	// wLength
		);

data_in(	8'h12,		// Function Address
		8'd28		// Expected payload size
	);

// Status OK
data_out(	8'h12,		// Function Address
		8'h0		// Expected payload size
	);

#100000;

$display("\n\nSetting report 5a ...");
send_setup(	8'h12, 		// Function Address
		8'h21,		// Request Type
		8'h09,	// Request
		16'h0200,	// wValue
		16'h0,		// wIndex
		16'h0001	// wLength
		);

buffer1_last = 0;
buffer1[0] = 8'h5a;
data_out(	8'h12,
		8'd01
		);

setup_pid = 1;
data_in(	8'h12,		// Function Address
		8'd00		// Expected payload size
	);

#100000;

$display("\n\nSetting report 78 ...");
send_setup(	8'h12, 		// Function Address
		8'h21,		// Request Type
		8'h09,	// Request
		16'h0200,	// wValue
		16'h0,		// wIndex
		16'h0001	// wLength
		);

buffer1_last = 0;
buffer1[0] = 8'h78;
data_out(	8'h12,
		8'd01
		);

setup_pid = 1;
data_in(	8'h12,		// Function Address
		8'd00		// Expected payload size
	);

end
endtask

task in5;
reg	[6:0]	my_fa;
integer rlen;
reg	[3:0]	pid;
begin

my_fa = 7'h12;
	#100000;
		@(posedge clk);
		ep5_f_din = 8'h34;
		ep5_f_we = 1;
		@(posedge clk);
		#1;
		ep5_f_we = 0;

		@(posedge clk);
		ep5_f_din = 8'h78;
		ep5_f_we = 1;
		@(posedge clk);
		#1;
		ep5_f_we = 0;

	send_token(	my_fa,		// Function Address
			5,		// Logical Endpoint Number
			`USBF_T_PID_IN	// PID
			);

	repeat(1)	@(posedge clk);

	recv_packet(pid,rlen);
end
endtask

task in0;

reg	[6:0]	my_fa;
integer		quick, n, m, rlen,fc;
reg	[7:0]	fd;
integer		pack_cnt, pack_cnt_max;
reg	[7:0]	x;
reg	[3:0]	pid;
reg	[3:0]	expect_pid;
reg	[31:0]	data;
reg		pid_cnt;

begin

$display("\n\n");
$display("*****************************************************");
$display("*** IN ep test 0                                  ***");
$display("*****************************************************\n");

send_sof(11'h000 );	// Send SOF

pack_sz_max = 64;
pack_cnt_max = 4;

pid_cnt = 0;
my_fa = 7'h12;

for(pack_sz=0;pack_sz<pack_sz_max;pack_sz=pack_sz+1)
begin

$display("PL size: %0d", pack_sz);

for(pack_cnt=0;pack_cnt<pack_cnt_max;pack_cnt=pack_cnt+1)
   begin

	// Fill Buffer
	buffer1_last = 0;
	for(fc=0;fc<pack_sz;fc=fc+1)
	   begin
		#2;
		while(ep1_f_full)	@(posedge clk);
	
		#1;
		//x = fc[7:0];
		x = $random;
		ep1_f_din = x;
		buffer0[fc] = x;
		ep1_f_we = 1;
		@(posedge clk);
		#1;
		ep1_f_we = 0;
		@(posedge clk);
	   end
	#1;
	ep1_f_we = 0;
	@(posedge clk);

	// Send Data
	repeat(1)	@(posedge clk);
	send_sof(11'h000 );	// Send SOF
	repeat(1)	@(posedge clk);
	send_token(	my_fa,		// Function Address
			1,		// Logical Endpoint Number
			`USBF_T_PID_IN	// PID
			);

	repeat(1)	@(posedge clk);

	recv_packet(pid,rlen);

	if(pid_cnt)	expect_pid = 4'hb;
	else		expect_pid = 4'h3;
	expect_pid = 4'h3;

	if(pid !== expect_pid)
	   begin
		$display("ERROR: PID mismatch. Expected: %h, Got: %h (%t)",
			expect_pid, pid, $time);
		error_cnt = error_cnt + 1;
	   end
	pid_cnt = ~pid_cnt;

	if(rlen != pack_sz)
	   begin
		$display("ERROR: Size mismatch. Expected: %d, Got: %d (%t)",
			pack_sz, rlen, $time);
		error_cnt = error_cnt + 1;
	   end

	repeat(4)	@(posedge clk);
	send_token(	my_fa,		// Function Address
			1,		// Logical Endpoint Number
			`USBF_T_PID_ACK	// PID
			);
	repeat(5)	@(posedge clk);

	// Verify Data
	for(fc=0;fc<pack_sz;fc=fc+1)
	   begin
		x =  buffer0[fc];
		if( (buffer1[fc] !== x) | ( (^buffer1[fc] ^ ^x) === 1'hx) )
		   begin
			$display("ERROR: Data (%0d) mismatch. Expected: %h, Got: %h (%t)",
			fc, buffer1[fc], x, $time);
			error_cnt = error_cnt + 1;
		   end
	   end
   end

repeat(50)	@(posedge clk);
end

show_errors;
$display("*****************************************************");
$display("*** Test DONE ...                                 ***");
$display("*****************************************************\n\n");

end

endtask

task out0;
reg	[6:0]	my_fa;
reg	[31:0]	data;
integer		len, n, no_pack, pl_sz;
integer		no_pack_max, pl_sz_max;
reg		pid;

reg	[7:0]	x;

begin
$display("\n\n");
$display("*****************************************************");
$display("*** OUT ep test 0                                 ***");
$display("*****************************************************\n");


no_pack_max = 4;	// Number Of packets to transfer
pl_sz_max   = 128;	// Payload Size

no_pack = 4;		// Number Of packets to transfer
pl_sz = 0;
my_fa = 7'h12;


for(pl_sz=0;pl_sz<pl_sz_max;pl_sz=pl_sz+4)
begin
pid = 0;

$display("PL size: %0d", pl_sz);

for(n=0;n<4096;n=n+1)
	//buffer1[n] = $random;
	buffer1[n] = n;

buffer1_last = 0;

fork
for(no_pack=0;no_pack<no_pack_max;no_pack=no_pack+1)	// Send no_pack Out packets
   begin
	repeat(1)	@(posedge clk);
	send_sof(11'h000 );	// Send SOF
	repeat(1)	@(posedge clk);

	send_token(	my_fa,		// Function Address
			4,		// Logical Endpoint Number
			`USBF_T_PID_OUT	// PID
			);

	repeat(1)	@(posedge clk);

	if(pid==0)	send_data(`USBF_T_PID_DATA0, pl_sz, 1);
	else		send_data(`USBF_T_PID_DATA1, pl_sz, 1);

	pid = ~pid;

	// Wait for ACK
	utmi_recv_pack(len);

	if(8'hd2 !== txmem[0])
	   begin
		$display("ERROR: ACK mismatch. Expected: %h, Got: %h (%t)",
		8'hd2, txmem[0], $time);
		error_cnt = error_cnt + 1;
	   end
	
	repeat(1)	@(posedge clk);
   end

   begin
	repeat(10)	@(posedge clk2);
	for(n=0;n<(no_pack_max*pl_sz);n=n+1)	// Compare Buffers
	   begin
	
		#4;
		ep4_f_re = 0;
		repeat(1)	@(posedge clk2);

		while(ep4_f_empty)
		   begin
			ep4_f_re = 0;
			repeat(2)	@(posedge clk2);
		   end

		#2;
		if(buffer1[n] !== ep4_f_dout)
		   begin
			$display("ERROR: DATA mismatch. Expected: %h, Got: %h (%t)",
				buffer1[n], ep4_f_dout, $time);
			error_cnt = error_cnt + 1;
		   end
	
		ep4_f_re = 1;
		@(posedge clk2);
	   end
	#1;
	ep4_f_re = 0;
	@(posedge clk2);
    end

join

repeat(1)	@(posedge clk);
end

show_errors;
$display("*****************************************************");
$display("*** Test DONE ...                                 ***");
$display("*****************************************************\n\n");
end
endtask


⌨️ 快捷键说明

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