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

📄 tests_ocp.v

📁 这是usb1.1协议,对于了解通用串行总线有很好的帮助,
💻 V
📖 第 1 页 / 共 2 页
字号:
			);	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);   end   begin	repeat(10)	@(posedge clk2);	for(n=0;n<(no_pack_max*pl_sz);n=n+1)	// Compare Buffers	   begin			#4;		cmd = 3'b000;		repeat(1)	@(posedge clk2);		while(flags[0])		   begin			cmd = 3'b000;			repeat(2)	@(posedge clk2);		   end		#2;		if(buffer1[n] !== ep_f_dout)		   begin			$display("ERROR: DATA mismatch. Expected: %h, Got: %h (%t)",				buffer1[n], ep_f_dout, $time);			error_cnt = error_cnt + 1;		   end			cmd = 3'b010;		@(posedge clk2);	   end	#1;	cmd = 3'b000;	@(posedge clk2);    endjoinrepeat(1)	@(posedge clk);endcmd = 3'b100;ep_f_addr=32'h0;show_errors;$display("*****************************************************");$display("*** Test DONE ...                                 ***");$display("*****************************************************\n\n");endendtasktask in3;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 3                                  ***");$display("*****************************************************\n");send_sof(11'h000 );	// Send SOFpack_sz_max = 64;pack_cnt_max = 4;pid_cnt = 0;my_fa = 7'h12;ep_f_addr=32'h03;cmd=3'b000;for(pack_sz=0;pack_sz<=pack_sz_max;pack_sz=pack_sz+8)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(flags[1])	@(posedge clk);			#1;		//x = fc[7:0];		x = $random;		ep_f_din = x;		buffer0[fc] = x;		cmd = 3'b001;		@(posedge clk);		#1;		cmd = 3'b000;		@(posedge clk);	   end	#1;	cmd = 3'b000;	@(posedge clk);	// Send Data	repeat(1)	@(posedge clk);	send_sof(11'h000 );	// Send SOF	repeat(1)	@(posedge clk);	send_token(	my_fa,		// Function Address			3,		// 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;	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			3,		// 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, x, buffer1[fc], $time);			error_cnt = error_cnt + 1;		   end	   end   endrepeat(50)	@(posedge clk);endcmd = 3'b100;ep_f_addr=32'h0;show_errors;$display("*****************************************************");$display("*** Test DONE ...                                 ***");$display("*****************************************************\n\n");endendtasktask out4;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 4                                 ***");$display("*****************************************************\n");no_pack_max = 4;	// Number Of packets to transferpl_sz_max   = 64;	// Payload Sizeno_pack = 4;		// Number Of packets to transferpl_sz = 0;my_fa = 7'h12;ep_f_addr=32'h04;cmd=3'b000;for(pl_sz=0;pl_sz<=pl_sz_max;pl_sz=pl_sz+8)beginpid = 0;$display("PL size: %0d", pl_sz);for(n=0;n<4096;n=n+1)	//buffer1[n] = $random;	buffer1[n] = n;buffer1_last = 0;forkfor(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	if(len != 1)	   begin		$display("ERROR: Size mismatch. Expected: %d, Got: %d (%t)",			pl_sz, len, $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;		cmd = 3'b000;		repeat(1)	@(posedge clk2);		while(flags[0])		   begin			cmd = 3'b000;			repeat(2)	@(posedge clk2);		   end		#2;					// Comment this line for XILINX Timed Simulation		//@(posedge clk2);	// Comment this line for Standard Simulation		if(buffer1[n] !== ep_f_dout)		   begin			$display("ERROR: DATA mismatch. Expected: %h, Got: %h (%t)",				buffer1[n], ep_f_dout, $time);			error_cnt = error_cnt + 1;		   end			cmd = 3'b010;		@(posedge clk2);	   end	#1;	cmd = 3'b000;	@(posedge clk2);    endjoinrepeat(1)	@(posedge clk);endcmd=3'b100;ep_f_addr=32'h0;show_errors;$display("*****************************************************");$display("*** Test DONE ...                                 ***");$display("*****************************************************\n\n");endendtasktask in5;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 5                                  ***");$display("*****************************************************\n");send_sof(11'h000 );	// Send SOFpack_sz_max = 64;pack_cnt_max = 4;pid_cnt = 0;my_fa = 7'h12;ep_f_addr=32'h05;cmd=3'b000;for(pack_sz=0;pack_sz<=pack_sz_max;pack_sz=pack_sz+8)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(flags[1])	@(posedge clk);			#1;		//x = fc[7:0];		x = $random;		ep_f_din = x;		buffer0[fc] = x;		cmd = 3'b001;		@(posedge clk);		#1;		cmd = 3'b000;		@(posedge clk);	   end	#1;	cmd = 3'b000;	@(posedge clk);	// Send Data	repeat(1)	@(posedge clk);	send_sof(11'h000 );	// Send SOF	repeat(1)	@(posedge clk);	send_token(	my_fa,		// Function Address			5,		// Logical Endpoint Number			`USBF_T_PID_IN	// PID			);	repeat(1)	@(posedge clk);	recv_packet(pid,rlen);	if (pack_sz == 0)	expect_pid = 4'ha;	else if(pid_cnt)	expect_pid = 4'hb;	else			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);	if(pack_sz != 0)	   begin		send_token(	my_fa,		// Function Address				5,		// Logical Endpoint Number				`USBF_T_PID_ACK	// PID				);		repeat(5)	@(posedge clk);	   end	// 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, x, buffer1[fc], $time);			error_cnt = error_cnt + 1;		   end	   end   endrepeat(50)	@(posedge clk);endcmd=3'b100;ep_f_addr=32'h0;show_errors;$display("*****************************************************");$display("*** Test DONE ...                                 ***");$display("*****************************************************\n\n");endendtasktask out6;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 6                                 ***");$display("*****************************************************\n");no_pack_max = 4;	// Number Of packets to transferpl_sz_max   = 64;	// Payload Sizeno_pack = 4;		// Number Of packets to transferpl_sz = 0;my_fa = 7'h12;ep_f_addr=32'h06;cmd=3'b000;for(pl_sz=0;pl_sz<=pl_sz_max;pl_sz=pl_sz+8)beginpid = 0;$display("PL size: %0d", pl_sz);for(n=0;n<4096;n=n+1)	//buffer1[n] = $random;	buffer1[n] = n;buffer1_last = 0;forkfor(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			6,		// 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	if(len != 1)	   begin		$display("ERROR: Size mismatch. Expected: %d, Got: %d (%t)",			pl_sz, len, $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;		cmd = 3'b000;		repeat(1)	@(posedge clk2);		while(flags[0])		   begin			cmd = 3'b000;			repeat(2)	@(posedge clk2);		   end		#2;					// Comment this line for XILINX Timed Simulation		//@(posedge clk2);	// Comment this line for Standard Simulation		if(buffer1[n] !== ep_f_dout)		   begin			$display("ERROR: DATA mismatch. Expected: %h, Got: %h (%t)",				buffer1[n], ep_f_dout, $time);			error_cnt = error_cnt + 1;		   end			cmd = 3'b010;		@(posedge clk2);	   end	#1;	cmd = 3'b000;	@(posedge clk2);    endjoinrepeat(1)	@(posedge clk);endcmd=3'b100;ep_f_addr=8'h0;show_errors;$display("*****************************************************");$display("*** Test DONE ...                                 ***");$display("*****************************************************\n\n");endendtask

⌨️ 快捷键说明

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