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

📄 tests.v

📁 DMA的控制器的IP核,和ATA控制器配合,可以实现DMA方式高速传输数据.
💻 V
📖 第 1 页 / 共 4 页
字号:
endcasefor(rep=0;rep<4;rep=rep+1)   begin	ack_cnt_clr = 1;	@(posedge clk);	ack_cnt_clr = 0;	if(del==4)	del = 10;	s0.delay = del;	s1.delay = del;	if(chunk_sz==0)		k = 1;	else	   begin		k = tot_sz/chunk_sz;		if((k*chunk_sz) != tot_sz)	k = k + 1;	   end	s0.fill_mem(1);	s1.fill_mem(1);	fork	   begin		for(m=0;m < k;m=m+1)		   begin			repeat(del)	@(posedge clk);			#1;			req_i[0] = 1;			while(!ack_o[0])	@(posedge clk);			#1;			req_i[0] = 0;		   end	   end	   begin		repeat(1)	@(posedge clk);		while(!u0.dma_done_all)	@(posedge clk);/*	repeat(5)	@(posedge clk);	while(!inta_o)	@(posedge clk);	m0.wb_rd1(`REG_BASE + `INT_SRCA, 4'hf, d1);	d0 = 32'h0000_0002;	if( d1 !== d0 )	   begin		$display("ERROR: INT_SRC Mismatch: Expected: %x, Got: %x (%0t)",			d0, d1, $time);		error_cnt = error_cnt + 1;	   end	m0.wb_rd1(`REG_BASE + `CH0_CSR, 4'hf, d1);	d0 = {24'h0000_081, 1'b1, mode[1:0], 1'b0};	if( d1 !== d0 )	   begin		$display("ERROR: CH0_CSR Mismatch: Expected: %x, Got: %x (%0t)",			d0, d1, $time);		error_cnt = error_cnt + 1;	   end*/			for(n=0;n<tot_sz;n=n+1)		   begin			if(mode[1])	d0=s1.mem[ n ];			else		d0=s0.mem[ n ];			if(mode[0])	d1=s1.mem[32'h0000_1000 + n ];			else		d1=s0.mem[32'h0000_1000 + n ];					if( d1 !== d0 )			   begin				$display("ERROR: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",				n, d0, d1, $time);				error_cnt = error_cnt + 1;			   end		   end	   end	join	if(ack_cnt != ((tot_sz*2)) )	   begin		$display("ERROR: ACK count Mismatch: Expected: %0d, Got: %0d (%0t)",		((tot_sz*2)), ack_cnt, $time);		error_cnt = error_cnt + 1;	   end   endend	s0.delay = 0;	s1.delay = 0;show_errors;$display("*****************************************************");$display("*** Test DONE ...                                 ***");$display("*****************************************************\n\n");endendtasktask hw_dma2;input		quick;integer		quick, tot_sz_max, chunk_sz_max, del_max;reg	[7:0]	mode;reg	[15:0]	chunk_sz, tot_sz;integer		i, n,m0, m1, m2, m3, k,rep,del;reg	[31:0]	int_src, d0,d1;begin$display("\n\n");$display("*****************************************************");$display("*** HW DMA No Buffer Ext Descr. 4 Channels ...    ***");$display("*****************************************************\n");case(quick)	default:	   begin		del_max = 6;		tot_sz_max = 200;		chunk_sz_max = 8;	   end	 1:	   begin		del_max = 4;		tot_sz_max = 128;		chunk_sz_max = 4;	   end	 2:	   begin		del_max = 3;		tot_sz_max = 32;		chunk_sz_max = 4;	   endendcasemode = 0;tot_sz = 128;chunk_sz=2;del = 0;	m0.wb_wr1(`REG_BASE + `CH0_CSR,4'hf, 32'h0);	m0.wb_wr1(`REG_BASE + `CH1_CSR,4'hf, 32'h0);	m0.wb_wr1(`REG_BASE + `CH2_CSR,4'hf, 32'h0);	m0.wb_wr1(`REG_BASE + `CH3_CSR,4'hf, 32'h0);	m0.wb_rd1(`REG_BASE + `INT_SRCA, 4'hf, int_src);for(tot_sz=1;tot_sz<tot_sz_max;tot_sz=tot_sz+1)beginif(tot_sz>4)	tot_sz = tot_sz + 4;if(tot_sz>16)	tot_sz = tot_sz + 12;if(tot_sz>64)	tot_sz = tot_sz + 48;for(del=0;del<del_max;del=del+1)for(mode=0;mode<4;mode=mode+1)for(chunk_sz=0;chunk_sz<chunk_sz_max;chunk_sz=chunk_sz+1)begin	s0.delay = del;	s1.delay = del;	s0.fill_mem(1);	s1.fill_mem(1);	s0.mem[0] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz;	s0.mem[1] = 32'h0000_0100;	s0.mem[2] = 32'h0000_0900;	s0.mem[3] = 32'h0000_0010;	s0.mem[4] = (32'h001c_0000 | (mode[1:0]<<16)) + tot_sz;	s0.mem[5] = 32'h0000_0100 + (tot_sz * 4);	s0.mem[6] = 32'h0000_0900 + (tot_sz * 4);	s0.mem[7] = 32'h0000_0000;	s0.mem[8] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz;	s0.mem[9] = 32'h0000_1100;	s0.mem[10] = 32'h0000_1900;	s0.mem[11] = 32'h0000_0030;	s0.mem[12] = (32'h001c_0000 | (mode[1:0]<<16)) + tot_sz;	s0.mem[13] = 32'h0000_1100 + (tot_sz * 4);	s0.mem[14] = 32'h0000_1900 + (tot_sz * 4);	s0.mem[15] = 32'h0000_0000;	s0.mem[16] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz;	s0.mem[17] = 32'h0000_2100;	s0.mem[18] = 32'h0000_2900;	s0.mem[19] = 32'h0000_0050;	s0.mem[20] = (32'h001c_0000 | (mode[1:0]<<16)) + tot_sz;	s0.mem[21] = 32'h0000_2100 + (tot_sz * 4);	s0.mem[22] = 32'h0000_2900 + (tot_sz * 4);	s0.mem[23] = 32'h0000_0000;	s0.mem[24] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz;	s0.mem[25] = 32'h0000_3100;	s0.mem[26] = 32'h0000_3900;	s0.mem[27] = 32'h0000_0070;	s0.mem[28] = (32'h001c_0000 | (mode[1:0]<<16)) + tot_sz;	s0.mem[29] = 32'h0000_3100 + (tot_sz * 4);	s0.mem[30] = 32'h0000_3900 + (tot_sz * 4);	s0.mem[31] = 32'h0000_0000;	m0.wb_wr1(`REG_BASE + `INT_MASKA,4'hf,32'hffff_ffff);	m0.wb_wr1(`REG_BASE + `PTR0, 4'hf, 32'h0000_0000);	m0.wb_wr1(`REG_BASE + `CH0_TXSZ,4'hf, {chunk_sz, 16'h0fff});	m0.wb_wr1(`REG_BASE + `CH0_ADR0,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH0_ADR1,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH0_CSR,4'hf,			//{25'h0000001, 4'b0111, 2'b00, 1'b1});			{12'h0000, 3'b010, 1'b0, 9'h001, 4'b0111, 2'b00, 1'b1});	m0.wb_wr1(`REG_BASE + `PTR1, 4'hf, 32'h0000_0020);	m0.wb_wr1(`REG_BASE + `CH1_TXSZ,4'hf, {chunk_sz, 16'h0fff});	m0.wb_wr1(`REG_BASE + `CH1_ADR0,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH1_ADR1,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH1_CSR,4'hf,			//{25'h0000001, 4'b0111, 2'b00, 1'b1});			{12'h0000, 3'b010, 1'b0, 9'h001, 4'b0111, 2'b00, 1'b1});	m0.wb_wr1(`REG_BASE + `PTR2, 4'hf, 32'h0000_0040);	m0.wb_wr1(`REG_BASE + `CH2_TXSZ,4'hf, {chunk_sz, 16'h0fff});	m0.wb_wr1(`REG_BASE + `CH2_ADR0,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH2_ADR1,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH2_CSR,4'hf,			//{25'h0000001, 4'b0111, 2'b00, 1'b1});			{12'h0000, 3'b010, 1'b0, 9'h001, 4'b0111, 2'b00, 1'b1});	m0.wb_wr1(`REG_BASE + `PTR3, 4'hf, 32'h0000_0060);	m0.wb_wr1(`REG_BASE + `CH3_TXSZ,4'hf, {chunk_sz, 16'h0fff});	m0.wb_wr1(`REG_BASE + `CH3_ADR0,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH3_ADR1,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH3_CSR,4'hf,			//{25'h0000001, 4'b0111, 2'b00, 1'b1});			{12'h0000, 3'b010, 1'b0, 9'h001, 4'b0111, 2'b00, 1'b1});	$write("Total Size: %0d, Delay: %0d ",tot_sz, del);	case(mode)	   0: $display("Mode: 0->0, chunk_size: %0d", chunk_sz);	   1: $display("Mode: 0->1, chunk_size: %0d", chunk_sz);	   2: $display("Mode: 1->0, chunk_size: %0d", chunk_sz);	   3: $display("Mode: 1->1, chunk_size: %0d", chunk_sz);	endcase	ack_cnt_clr = 1;	@(posedge clk);	ack_cnt_clr = 0;	if(chunk_sz==0)		k = 1;	else	   begin		k = tot_sz/chunk_sz;		if((k*chunk_sz) != tot_sz)	k = k + 1;	   end	k = k * 2;	fork	   begin		repeat(5)	@(posedge clk);		for(m0=0;m0 < k;m0=m0+1)		   begin			repeat(del)	@(posedge clk);			#1;			req_i[0] = 1;			while(!ack_o[0])	@(posedge clk);			#1;			req_i[0] = 0;		   end	   end	   begin		repeat(5)	@(posedge clk);		for(m1=0;m1 < k;m1=m1+1)		   begin			repeat(del)	@(posedge clk);			#1;			req_i[1] = 1;			while(!ack_o[1])	@(posedge clk);			#1;			req_i[1] = 0;		   end	   end	   begin		repeat(5)	@(posedge clk);		for(m2=0;m2 < k;m2=m2+1)		   begin			repeat(del)	@(posedge clk);			#1;			req_i[2] = 1;			while(!ack_o[2])	@(posedge clk);			#1;			req_i[2] = 0;		   end	   end	   begin		repeat(5)	@(posedge clk);		for(m3=0;m3 < k;m3=m3+1)		   begin			repeat(del)	@(posedge clk);			#1;			req_i[3] = 1;			while(!ack_o[3])	@(posedge clk);			#1;			req_i[3] = 0;		   end	   end	   for(i=0;i<4;i=i)	   begin		repeat(5)	@(posedge clk);		while(!inta_o)	@(posedge clk);		m0.wb_rd1(`REG_BASE + `INT_SRCA, 4'hf, int_src);			if(int_src[0])		   begin			m0.wb_rd1(`REG_BASE + `CH0_CSR, 4'hf, d0);			i=i+1;			for(n=0;n<tot_sz*2;n=n+1)			   begin				if(mode[1])	d0=s1.mem[(s0.mem[1]>>2) + n ];				else		d0=s0.mem[(s0.mem[1]>>2) + n ];				if(mode[0])	d1=s1.mem[(s0.mem[2]>>2) + n ];				else		d1=s0.mem[(s0.mem[2]>>2) + n ];							if( d1 !== d0 )				   begin					$display("ERROR: CH0: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",					n, d0, d1, $time);					error_cnt = error_cnt + 1;				   end			   end		   end		if(int_src[1])		   begin			m0.wb_rd1(`REG_BASE + `CH1_CSR, 4'hf, d0);			i=i+1;			for(n=0;n<tot_sz*2;n=n+1)			   begin				if(mode[1])	d0=s1.mem[(s0.mem[9]>>2) + n ];				else		d0=s0.mem[(s0.mem[9]>>2) + n ];				if(mode[0])	d1=s1.mem[(s0.mem[10]>>2) + n ];				else		d1=s0.mem[(s0.mem[10]>>2) + n ];							if( d1 !== d0 )				   begin					$display("ERROR: CH1: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",					n, d0, d1, $time);					error_cnt = error_cnt + 1;				   end			   end		   end		if(int_src[2])		   begin			m0.wb_rd1(`REG_BASE + `CH2_CSR, 4'hf, d0);			i=i+1;			for(n=0;n<tot_sz*2;n=n+1)			   begin				if(mode[1])	d0=s1.mem[(s0.mem[17]>>2) + n ];				else		d0=s0.mem[(s0.mem[17]>>2) + n ];				if(mode[0])	d1=s1.mem[(s0.mem[18]>>2) + n ];				else		d1=s0.mem[(s0.mem[18]>>2) + n ];							if( d1 !== d0 )				   begin					$display("ERROR: CH2: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",					n, d0, d1, $time);					error_cnt = error_cnt + 1;				   end			   end		   end		if(int_src[3])		   begin			m0.wb_rd1(`REG_BASE + `CH3_CSR, 4'hf, d0);			i=i+1;			for(n=0;n<tot_sz*2;n=n+1)			   begin				if(mode[1])	d0=s1.mem[(s0.mem[25]>>2) + n ];				else		d0=s0.mem[(s0.mem[25]>>2) + n ];				if(mode[0])	d1=s1.mem[(s0.mem[26]>>2) + n ];				else		d1=s0.mem[(s0.mem[26]>>2) + n ];							if( d1 !== d0 )				   begin					$display("ERROR: CH3: Data[%0d] Mismatch: Expected: %x, Got: %x (%0t)",					n, d0, d1, $time);					error_cnt = error_cnt + 1;				   end			   end		   end	   end	join	if(ack_cnt != ((tot_sz*2*4*2)+(4*4*2)) )	   begin		$display("ERROR: ACK count Mismatch: Expected: %0d, Got: %0d (%0t)",		((tot_sz*2*4*2)+(4*4*2)), ack_cnt, $time);		error_cnt = error_cnt + 1;	   end	repeat(5)	@(posedge clk);endend	s0.delay = 0;	s1.delay = 0;show_errors;$display("*****************************************************");$display("*** Test DONE ...                                 ***");$display("*****************************************************\n\n");endendtasktask hw_dma3;input		quick;integer		quick, tot_sz_max, chunk_sz_max, del_max;reg	[7:0]	mode;reg	[15:0]	chunk_sz, tot_sz;integer		odd, i, iz, n,m0, m1, m2, m3, k, k1, rep,del;reg	[31:0]	int_src, d0,d1;begin$display("\n\n");$display("*****************************************************");$display("*** HW DMA Ext Descr. 4 Channels ND Test ...      ***");$display("*****************************************************\n");case(quick)	default:	   begin		del_max = 6;		chunk_sz_max = 8;	   end	 1:	   begin		del_max = 4;		chunk_sz_max = 4;	   end	 2:	   begin		del_max = 3;		chunk_sz_max = 4;	   endendcasemode = 0;tot_sz = 64;chunk_sz=4;del = 0;m0.wb_wr1(`REG_BASE + `CH0_CSR,4'hf, 32'h0);m0.wb_wr1(`REG_BASE + `CH1_CSR,4'hf, 32'h0);m0.wb_wr1(`REG_BASE + `CH2_CSR,4'hf, 32'h0);m0.wb_wr1(`REG_BASE + `CH3_CSR,4'hf, 32'h0);m0.wb_rd1(`REG_BASE + `INT_SRCA, 4'hf, int_src);for(del=0;del<del_max;del=del+1)for(mode=0;mode<4;mode=mode+1)for(chunk_sz=1;chunk_sz<chunk_sz_max;chunk_sz=chunk_sz+1)begin	repeat(50)	@(posedge clk);	s0.delay = del;	s1.delay = del;	s0.fill_mem(1);	s1.fill_mem(1);	// Channel 0 Descriptors	s0.mem[0] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[1] = 32'h0000_0400;	s0.mem[2] = 32'h0000_0800;	s0.mem[3] = 32'h0000_0010;	s0.mem[4] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[5] = 32'h0000_0400 + (tot_sz * 4);	s0.mem[6] = 32'h0000_0800 + (tot_sz * 4);	s0.mem[7] = 32'h0000_0020;	s0.mem[8] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[9] = 32'h0000_0400 + (tot_sz * 4);	s0.mem[10] = 32'h0000_0800 + (tot_sz * 4);	s0.mem[11] = 32'h0000_0030;	s0.mem[12] = (32'h001c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[13] = 32'h0000_0400 + (tot_sz * 4);	s0.mem[14] = 32'h0000_0800 + (tot_sz * 4);	s0.mem[15] = 32'h0000_0000;	// Channel 1 Descriptors	s0.mem[16] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[17] = 32'h0000_0c00;	s0.mem[18] = 32'h0000_1000;	s0.mem[19] = 32'h0000_0050;	s0.mem[20] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[21] = 32'h0000_0c00 + (tot_sz * 4);	s0.mem[22] = 32'h0000_1000 + (tot_sz * 4);	s0.mem[23] = 32'h0000_0060;	s0.mem[24] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[25] = 32'h0000_0c00 + (tot_sz * 4);	s0.mem[26] = 32'h0000_1000 + (tot_sz * 4);	s0.mem[27] = 32'h0000_0070;	s0.mem[28] = (32'h001c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[29] = 32'h0000_0c00 + (tot_sz * 4);	s0.mem[30] = 32'h0000_1000 + (tot_sz * 4);	s0.mem[31] = 32'h0000_0000;	// Channel 2 Descriptors	s0.mem[32] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[33] = 32'h0000_1400;	s0.mem[34] = 32'h0000_1800;	s0.mem[35] = 32'h0000_0090;	s0.mem[36] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[37] = 32'h0000_1400 + (tot_sz * 4);	s0.mem[38] = 32'h0000_1800 + (tot_sz * 4);	s0.mem[39] = 32'h0000_00a0;	s0.mem[40] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[41] = 32'h0000_1400 + (tot_sz * 4);	s0.mem[42] = 32'h0000_1800 + (tot_sz * 4);	s0.mem[43] = 32'h0000_00b0;	s0.mem[44] = (32'h001c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[45] = 32'h0000_1400 + (tot_sz * 4);	s0.mem[46] = 32'h0000_1800 + (tot_sz * 4);	s0.mem[47] = 32'h0000_0000;	// Channel 3 Descriptors	s0.mem[48] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[49] = 32'h0000_1c00;	s0.mem[50] = 32'h0000_2000;	s0.mem[51] = 32'h0000_00d0;	s0.mem[52] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[53] = 32'h0000_1c00 + (tot_sz * 4);	s0.mem[54] = 32'h0000_2000 + (tot_sz * 4);	s0.mem[55] = 32'h0000_00e0;	s0.mem[56] = (32'h000c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[57] = 32'h0000_1c00 + (tot_sz * 4);	s0.mem[58] = 32'h0000_2000 + (tot_sz * 4);	s0.mem[59] = 32'h0000_00f0;	s0.mem[60] = (32'h001c_0000 | (mode[1:0]<<16)) + tot_sz*4;	s0.mem[61] = 32'h0000_1c00 + (tot_sz * 4);	s0.mem[62] = 32'h0000_2000 + (tot_sz * 4);	s0.mem[63] = 32'h0000_0000;	m0.wb_wr1(`REG_BASE + `INT_MASKA,4'hf,32'hffff_ffff);	m0.wb_wr1(`REG_BASE + `PTR0, 4'hf, 32'h0000_0000);	m0.wb_wr1(`REG_BASE + `CH0_TXSZ,4'hf, {chunk_sz, 16'h0fff});	m0.wb_wr1(`REG_BASE + `CH0_ADR0,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH0_ADR1,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH0_CSR,4'hf,			{12'h0000, 3'b010, 1'b0, 9'h003, 4'b0111, 2'b00, 1'b1});	m0.wb_wr1(`REG_BASE + `PTR1, 4'hf, 32'h0000_0040);	m0.wb_wr1(`REG_BASE + `CH1_TXSZ,4'hf, {chunk_sz, 16'h0fff});	m0.wb_wr1(`REG_BASE + `CH1_ADR0,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH1_ADR1,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH1_CSR,4'hf,			{12'h0000, 3'b010, 1'b0, 9'h003, 4'b0111, 2'b00, 1'b1});	m0.wb_wr1(`REG_BASE + `PTR2, 4'hf, 32'h0000_0080);	m0.wb_wr1(`REG_BASE + `CH2_TXSZ,4'hf, {chunk_sz, 16'h0fff});	m0.wb_wr1(`REG_BASE + `CH2_ADR0,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH2_ADR1,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH2_CSR,4'hf,			{12'h0000, 3'b010, 1'b0, 9'h003, 4'b0111, 2'b00, 1'b1});	m0.wb_wr1(`REG_BASE + `PTR3, 4'hf, 32'h0000_00c0);	m0.wb_wr1(`REG_BASE + `CH3_TXSZ,4'hf, {chunk_sz, 16'h0fff});	m0.wb_wr1(`REG_BASE + `CH3_ADR0,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH3_ADR1,4'hf,32'h0000_ffff);	m0.wb_wr1(`REG_BASE + `CH3_CSR,4'hf,			{12'h0000, 3'b010, 1'b0, 9'h003, 4'b0111, 2'b00, 1'b1});	$write("Total Size: %0d, Delay: %0d ",tot_sz, del);	case(mode)

⌨️ 快捷键说明

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