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

📄 tests.v

📁 USB v1.1 RTL and design specification
💻 V
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////
////                                                             ////
////  Test Case Collection                                       ////
////                                                             ////
////                                                             ////
////  Author: Rudolf Usselmann                                   ////
////          rudi@asics.ws                                      ////
////                                                             ////
////                                                             ////
////  Downloaded from: http://www.opencores.org/cores/usb1_funct/////
////                                                             ////
/////////////////////////////////////////////////////////////////////
////                                                             ////
//// Copyright (C) 2000-2002 Rudolf Usselmann                    ////
////                         www.asics.ws                        ////
////                         rudi@asics.ws                       ////
////                                                             ////
//// This source file may be used and distributed without        ////
//// restriction provided that this copyright statement is not   ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer.////
////                                                             ////
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
////                                                             ////
/////////////////////////////////////////////////////////////////////

//  CVS Log
//
//  $Id: tests.v,v 1.1 2002/09/25 06:10:10 rudi Exp $
//
//  $Date: 2002/09/25 06:10:10 $
//  $Revision: 1.1 $
//  $Author: rudi $
//  $Locker:  $
//  $State: Exp $
//
// Change History:
//               $Log: tests.v,v $
//               Revision 1.1  2002/09/25 06:10:10  rudi
//               Added Test Bench
//
//
//
//
//
//
//


task send_setup;
input	[7:0]	fa;
input	[7:0]	req_type;
input	[7:0]	request;
input	[15:0]	wValue;
input	[15:0]	wIndex;
input	[15:0]	wLength;

integer		len;
begin

buffer1[0] = req_type;
buffer1[1] = request;
buffer1[3] = wValue[15:8];
buffer1[2] = wValue[7:0];
buffer1[5] = wIndex[15:8];
buffer1[4] = wIndex[7:0];
buffer1[7] = wLength[15:8];
buffer1[6] = wLength[7:0];

buffer1_last = 0;
send_token(	fa,			// Function Address
		0,			// Logical Endpoint Number
		`USBF_T_PID_SETUP	// PID
		);

repeat(1)	@(posedge clk);

send_data(`USBF_T_PID_DATA0, 8, 1);

// Wait for ACK
utmi_recv_pack(len);

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

if(len !== 1)
   begin
	$display("ERROR: SETUP: Length mismatch. Expected: %h, Got: %h (%t)",
	8'h1, len, $time);
	error_cnt = error_cnt + 1;
   end

repeat(1)	@(posedge clk);
setup_pid = 1;
repeat(1)	@(posedge clk);
end

endtask



task data_in;
input	[7:0]	fa;
input	[7:0]	pl_size;

integer		rlen;
reg	[3:0]	pid, expect_pid;
begin

	buffer1_last = 0;
	repeat(5)	@(posedge clk);
	send_token(	fa,		// Function Address
			0,		// Logical Endpoint Number
			`USBF_T_PID_IN	// PID
			);

	recv_packet(pid,rlen);
	if(setup_pid)	expect_pid = 4'hb; // DATA 1
	else		expect_pid = 4'h3; // DATA 0

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

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

	for(n=0;n<rlen;n=n+1)
		$display("RCV Data[%0d]: %h",n,buffer1[n]);

	repeat(5)	@(posedge clk);
	send_token(	fa,		// Function Address
			0,		// Logical Endpoint Number
			`USBF_T_PID_ACK	// PID
			);

	repeat(5)	@(posedge clk);

end
endtask



task data_out;
input	[7:0]	fa;
input	[7:0]	pl_size;

integer len;

begin
	send_token(	fa,		// Function Address
			0,		// Logical Endpoint Number
			`USBF_T_PID_OUT	// PID
			);

	repeat(1)	@(posedge clk);

	if(setup_pid==0)	send_data(`USBF_T_PID_DATA0, pl_size, 1);
	else			send_data(`USBF_T_PID_DATA1, pl_size, 1);

	setup_pid = ~setup_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

	if(len !== 1)
	   begin
		$display("ERROR: SETUP: Length mismatch. Expected: %h, Got: %h (%t)",
		8'h1, len, $time);
		error_cnt = error_cnt + 1;
	   end
	repeat(5)	@(posedge clk);

end
endtask


parameter	GET_STATUS	=	8'h0,
		CLEAR_FEATURE	=	8'h1,
		SET_FEATURE	=	8'h3,
		SET_ADDRESS	=	8'h5,
		GET_DESCRIPTOR	=	8'h6,
		SET_DESCRIPTOR	=	8'h7,
		GET_CONFIG	=	8'h8,
		SET_CONFIG	=	8'h9,
		GET_INTERFACE	=	8'ha,
		SET_INTERFACE	=	8'hb,
		SYNCH_FRAME	=	8'hc;


task setup1;

begin
$display("\n\n");
$display("*****************************************************");
$display("*** CTRL ep test 1                                ***");
$display("*****************************************************\n");


$display("\n\nSetting Address ...");

send_setup(	8'h0, 		// Function Address
		8'h00,		// Request Type
		SET_ADDRESS,	// Request
		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 descriptor ...");
send_setup(	8'h12, 		// Function Address
		8'h80,		// Request Type
		GET_DESCRIPTOR,	// Request
		16'h0100,	// wValue
		16'h0,		// wIndex
		16'h8		// wLength
		);

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

end
endtask

task msetup;
begin
$display("\n\n");
$display("*****************************************************");
$display("*** My setup test                                 ***");
$display("*****************************************************");

$display("\n\nSetting Address ...");

send_setup(	8'h0, 		// Function Address
		8'h00,		// Request Type
		SET_ADDRESS,	// Request

⌨️ 快捷键说明

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