CRC计算VHDL代码级测试代码.docx
《CRC计算VHDL代码级测试代码.docx》由会员分享,可在线阅读,更多相关《CRC计算VHDL代码级测试代码.docx(27页珍藏版)》请在冰豆网上搜索。
![CRC计算VHDL代码级测试代码.docx](https://file1.bdocx.com/fileroot1/2023-2/28/b9c644e4-80a5-4f5e-85bd-ca8050a1949c/b9c644e4-80a5-4f5e-85bd-ca8050a1949c1.gif)
CRC计算VHDL代码级测试代码
CRCComputation
1CRCMatrixComputation(Ref[1])
1.1Dimensionofmatrixis4(Ref[1])
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitytestbenchis
GENERIC(DM:
INTEGER:
=3);------lengthofmatrixminus1-----------------------
endtestbench;
architecturemtestoftestbenchis
typematrix_typeISarray(DMdownto0)ofstd_logic_vector(DMdownto0);
typeintem_matrix_typeISarray(DMdownto0)ofmatrix_type;
signala,b,c:
matrix_type;
signaltm,tv:
intem_matrix_type;
--constantDM:
integer:
=3;------lengthofmatrixminus1-----------------------
signali,j,k,s,f:
integer;
begin
test:
process
begin
--a<=(('1','0','0','1'),('1','0','1','1'),('1','0','0','0'),('0','0','1','1'));
a<=(('1','1','0','0'),('0','0','1','0'),('0','0','0','1'),('1','0','0','0'));
waitfor20ns;
b<=a;
waitfor20ns;
b<=c;
waitfor20ns;
b<=c;
waitfor20ns;
b<=c;
wait;
endprocesstest;
-----------------the0line------------------------------------------------
Line_all:
FORkin0toDMGENERATE
Line_i:
FORiin0toDMGENERATE
Elem_all_0:
forjin0toDMGENERATE
tm(k)(j)(i)<=a(k)(i)andb(i)(j);
ENDGENERATEElem_all_0;
ENDGENERATELine_i;
ENDGENERATELine_all;
----c(0)(0)<=tm(0)(0)(0)xortm(0)(0)
(1)xortm(0)(0)
(2)xortm(0)(0)(3);-----
allc:
forkin0toDMgenerate
outc:
forjin0toDMgenerate
tv(k)(j)(0)<=tm(k)(j)(0);
c_computation:
foriin0toDM-1generate
tv(k)(j)(i+1)<=tv(k)(j)(i)xortm(k)(j)(i+1);
endgeneratec_computation;
c(k)(j)<=tv(k)(j)(DM);
endgenerateoutc;
endgenerateallc;
endmtest;
Figure1.计算结果图
1.2OriginalVersionofVHDLcode(Ref[1])
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitytestbenchis
endtestbench;
architecturemtestoftestbenchis
typematrix_typeISarray(3downto0)ofstd_logic_vector(3downto0);
typeintem_matrix_typeISarray(3downto0)ofmatrix_type;
signala,b,c:
matrix_type;
signaltm,tv:
intem_matrix_type;
constantDM:
integer:
=3;------lengthofmatrixminus1-----------------------
signali,j,k:
integer;
begin
test:
process
begin
--a<=(('1','0','0','1'),('1','0','1','1'),('1','0','0','0'),('0','0','1','1'));
a<=(('1','1','0','0'),('0','0','1','0'),('0','0','0','1'),('1','0','0','0'));
waitfor20ns;
b<=a;
waitfor20ns;
b<=c;
waitfor20ns;
b<=c;
waitfor20ns;
b<=c;
wait;
endprocesstest;
-----------------the0line------------------------------------------------
Line_0:
FORiin0toDMGENERATE
Elem_all_0:
forjin0toDMGENERATE
tm(0)(j)(i)<=a(0)(i)andb(i)(j);
ENDGENERATEElem_all_0;
ENDGENERATELine_0;
tv(0)(0)(0)<=tm(0)(0)(0);
c_computation:
foriin0toDM-1generate
tv(0)(0)(i+1)<=tv(0)(0)(i)xortm(0)(0)(i+1);
endgeneratec_computation;
c(0)(0)<=tv(0)(0)(DM);
--c(0)(0)<=tm(0)(0)(0)xortm(0)(0)
(1)xortm(0)(0)
(2)xortm(0)(0)(3);
c(0)
(1)<=tm(0)
(1)(0)xortm(0)
(1)
(1)xortm(0)
(1)
(2)xortm(0)
(1)(3);
c(0)
(2)<=tm(0)
(2)(0)xortm(0)
(2)
(1)xortm(0)
(2)
(2)xortm(0)
(2)(3);
c(0)(3)<=tm(0)(3)(0)xortm(0)(3)
(1)xortm(0)(3)
(2)xortm(0)(3)(3);
-----------------the1line------------------------------------------------
Line_1:
FORiin0toDMGENERATE
Elem_all_1:
forjin0toDMGENERATE
tm
(1)(j)(i)<=a
(1)(i)andb(i)(j);
ENDGENERATEElem_all_1;
ENDGENERATELine_1;
c
(1)(0)<=tm
(1)(0)(0)xortm
(1)(0)
(1)xortm
(1)(0)
(2)xortm
(1)(0)(3);
c
(1)
(1)<=tm
(1)
(1)(0)xortm
(1)
(1)
(1)xortm
(1)
(1)
(2)xortm
(1)
(1)(3);
c
(1)
(2)<=tm
(1)
(2)(0)xortm
(1)
(2)
(1)xortm
(1)
(2)
(2)xortm
(1)
(2)(3);
c
(1)(3)<=tm
(1)(3)(0)xortm
(1)(3)
(1)xortm
(1)(3)
(2)xortm
(1)(3)(3);
-----------------the2line------------------------------------------------
Line_2:
FORiin0toDMGENERATE
Elem_all_2:
forjin0toDMGENERATE
tm
(2)(j)(i)<=a
(2)(i)andb(i)(j);
ENDGENERATEElem_all_2;
ENDGENERATELine_2;
c
(2)(0)<=tm
(2)(0)(0)xortm
(2)(0)
(1)xortm
(2)(0)
(2)xortm
(2)(0)(3);
c
(2)
(1)<=tm
(2)
(1)(0)xortm
(2)
(1)
(1)xortm
(2)
(1)
(2)xortm
(2)
(1)(3);
c
(2)
(2)<=tm
(2)
(2)(0)xortm
(2)
(2)
(1)xortm
(2)
(2)
(2)xortm
(2)
(2)(3);
c
(2)(3)<=tm
(2)(3)(0)xortm
(2)(3)
(1)xortm
(2)(3)
(2)xortm
(2)(3)(3);
-----------------the3line------------------------------------------------
Line_3:
FORiin0toDMGENERATE
Elem_all_3:
forjin0toDMGENERATE
tm(3)(j)(i)<=a(3)(i)andb(i)(j);
ENDGENERATEElem_all_3;
ENDGENERATELine_3;
c(3)(0)<=tm(3)(0)(0)xortm(3)(0)
(1)xortm(3)(0)
(2)xortm(3)(0)(3);
c(3)
(1)<=tm(3)
(1)(0)xortm(3)
(1)
(1)xortm(3)
(1)
(2)xortm(3)
(1)(3);
c(3)
(2)<=tm(3)
(2)(0)xortm(3)
(2)
(1)xortm(3)
(2)
(2)xortm(3)
(2)(3);
c(3)(3)<=tm(3)(3)(0)xortm(3)(3)
(1)xortm(3)(3)
(2)xortm(3)(3)(3);
endmtest;
1.3Dimensionofmatrixis12(Ref[1])
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitytestbenchis
GENERIC(DM:
INTEGER:
=11);------lengthofmatrixminus1----------------
endtestbench;
architecturemtestoftestbenchis
typematrix_typeISarray(DMdownto0)ofstd_logic_vector(DMdownto0);
typeintem_matrix_typeISarray(DMdownto0)ofmatrix_type;
signala,b,c:
matrix_type;
signaltm,tv:
intem_matrix_type;
--constantDM:
integer:
=3;------lengthofmatrixminus1-----------------------
signali,j,k,s:
integer;
begin
test:
process
begin
a<=(('1','1','0','0','0','0','0','0','0','0','0','0'),------0----------------
('0','0','1','0','0','0','0','0','0','0','0','0'),------1----------------
('0','0','0','1','0','0','0','0','0','0','0','0'),------2----------------
('0','0','0','0','1','0','0','0','0','0','0','0'),------3----------------
('0','0','0','0','0','1','0','0','0','0','0','0'),------4----------------
('0','0','0','0','0','0','1','0','0','0','0','0'),------5----------------
('0','0','0','0','0','0','0','1','0','0','0','0'),------6----------------
('0','0','0','0','0','0','0','0','1','0','0','0'),------7----------------
('1','0','0','0','0','0','0','0','0','1','0','0'),------8----------------
('1','0','0','0','0','0','0','0','0','0','1','0'),------9----------------
('1','0','0','0','0','0','0','0','0','0','0','1'),------10----------------
('1','0','0','0','0','0','0','0','0','0','0','0')------11----------------
);
waitfor20ns;
b<=a;
s<=1;
waitfor20ns;
b<=c;
s<=2;
waitfor20ns;
b<=c;
s<=3;
waitfor20ns;
b<=c;
s<=4;
waitfor20ns;
b<=c;
s<=5;
waitfor20ns;
b<=c;
s<=6;
waitfor20ns;
b<=c;
s<=7;
waitfor20ns;
b<=c;
s<=8;
waitfor20ns;
b<=c;
s<=9;
waitfor20ns;
b<=c;
s<=10;
waitfor20ns;
b<=c;
s<=11;
waitfor20ns;
b<=c;
s<=12;
waitfor20ns;
wait;
endprocesstest;
-----------------the0line------------------------------------------------
Line_all:
FORkin0toDMGENERATE
Line_i:
FORiin0toDMGENERATE
Elem_all_0:
forjin0toDMGENERATE
tm(k)(j)(i)<=a(k)(i)andb(i)(j);
ENDGENERATEElem_all_0;
ENDGENERATELine_i;
ENDGENERATELine_all;
----c(0)(0)<=tm(0)(0)(0)xortm(0)(0)
(1)xortm(0)(0)
(2)xortm(0)(0)(3);-----
allc:
forkin0toDMgenerate
outc:
forjin0toDMgenerate
tv(k)(j)(0)<=tm(k)(j)(0);
c_computation:
foriin0toDM-1generate
tv(k)(j)(i+1)<=tv(k)(j)(i)xortm(k)(j)(i+1);
endgeneratec_computation;
c(k)(j)<=tv(k)(j)(DM);
endgenerateoutc;
endgenerateallc;
endmtest;
1.4Dimensionofmatrixis16(CCITT:
x16+x12+x5+1)(Ref[1])
Figure3.resultsofF16
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitytestbenchis
GENERIC(DM:
INTEGER:
=15);------lengthofmatrixminus1----------------
endtestbench;
architecturemtestoftestbenchis
typematrix_typeISarray(DMdownto0)ofstd_logic_vector(DMdownto0);
typeintem_matrix_typeISarray(DMdownto0)ofmatrix_type;
signala,b,c:
matrix_type;
signaltm,tv:
intem_matrix_type;
signali,j,k,s:
integer;
begin
test:
process
begin
a<=(('0','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0'),------0----------------
('0','0','1','0','0','0','0','0','0','0','0','0','0','0','0','0'),------1----------------
('0','0','0','1','0','0','0','0','0','0','0','0','0','0','0','0'),------2----------------
('1','0','0','0','1','0','0','0','0','0','0','0','0','0','0','0'),------3----------------
('0','0','0','0','0','1','0','0','0','0','0','0','0','0','0','0'),------4----------------
('0','0','0','0','0','0','1','0','0','0','0','0','0','0','0','0'),------5----------------
('0','0','0','0','0','0','0','1','0','0','0','0','0','0','0','0'),------6----------------
('0','0','0','0','0','0','0','0','1','0','0','0','0','0','0','0'),------7----------------
('0','0','0','0','0','0','0','0','0','1','0','0','0','0','0','0'),------8----------------
('0','0','0','0','0','0','0','0','0','0','1','0','0','0','0','0'),------9----------------
('1','0','0','0','0','0','0','0','0','0','0','1','0','0','0','0'),------a----------------
('0','0','0','0','0','0','0','0','0','0','0','0','1','0','0','0'),------b----------------
('0','0','0','0','0','0','0','0','0','0','0','0','0','1','0','0'),------c----------------
('0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','0'),------d----------------
('0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1'),------e----------------
('1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0')------f----------------
);
waitfor20ns;
b<=a;
s<=1;
waitfor20ns;
b<=c;
s<=2;
waitfor20ns;
b<=c;
s<=3;
waitfor20ns;
b<=c;
s<=4;
waitfor20ns;
b<=c;
s<=5;
waitfor20ns;
b<=c;
s<=6;
waitfor20ns;
b<=c;
s<=7;
waitfor20ns;
b<=c;
s<=8;
waitfor20ns;
b<=c;
s<=9;
waitfor20ns;
b<=c;
s<=1