1、CRC计算VHDL代码级测试代码CRC Computation1 CRC Matrix Computation (Ref 1)1.1 Dimension of matrix is 4 (Ref 1)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity testbench isGENERIC (DM : INTEGER := 3); -length of matrix minus 1-end testbench;architecture mtest of testbench istype m
2、atrix_type IS array (DM downto 0) of std_logic_vector (DM downto 0);type intem_matrix_type IS array (DM downto 0) of matrix_type;signal a,b,c: matrix_type;signal tm,tv:intem_matrix_type;-constant DM: integer:=3; -length of matrix minus 1-signal i,j,k,s,f: integer;begin test:process begin -a=(1,0,0,1
3、),(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); wait for 20 ns; b=a; wait for 20 ns; b=c; wait for 20 ns; b=c; wait for 20 ns; b=c; wait; end process test; -the 0 line- Line_all:FOR k in 0 to DM GENERATE Line_i:FOR i in 0 to DM GENERATE Elem_all_0: for j in 0 to DM GENERA
4、TE tm(k)(j)(i)=a(k)(i) and b(i)(j); END GENERATE Elem_all_0; END GENERATE Line_i; END GENERATE Line_all;-c(0)(0)=tm(0)(0)(0) xor tm(0)(0)(1) xor tm(0)(0)(2) xor tm(0)(0)(3);- allc: for k in 0 to DM generate outc: for j in 0 to DM generate tv(k)(j)(0)=tm(k)(j)(0); c_computation: for i in 0 to DM-1 ge
5、nerate tv(k)(j)(i+1)=tv(k)(j)(i) xor tm(k)(j)(i+1); end generate c_computation; c(k)(j)=tv(k)(j)(DM); end generate outc; end generate allc; end mtest;Figure 1. 计算结果图1.2 Original Version of VHDL code (Ref 1)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity testbench isen
6、d testbench;architecture mtest of testbench istype matrix_type IS array (3 downto 0) of std_logic_vector (3 downto 0);type intem_matrix_type IS array (3 downto 0) of matrix_type;signal a,b,c: matrix_type;signal tm,tv:intem_matrix_type;constant DM: integer:=3; -length of matrix minus 1-signal i,j,k:
7、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); wait for 20 ns; b=a; wait for 20 ns; b=c; wait for 20 ns; b=c; wait for 20 ns; b=c; wait; end process test; -the 0 line- Line_0:FOR i in 0 to DM GENERATE Elem_all_0: for j in 0 to
8、DM GENERATE tm(0)(j)(i)=a(0)(i) and b(i)(j); END GENERATE Elem_all_0; END GENERATE Line_0; tv(0)(0)(0)=tm(0)(0)(0); c_computation: for i in 0 to DM-1 generate tv(0)(0)(i+1)=tv(0)(0)(i) xor tm(0)(0)(i+1); end generate c_computation; c(0)(0)=tv(0)(0)(DM); -c(0)(0)=tm(0)(0)(0) xor tm(0)(0)(1) xor tm(0)
9、(0)(2) xor tm(0)(0)(3); c(0)(1)=tm(0)(1)(0) xor tm(0)(1)(1) xor tm(0)(1)(2) xor tm(0)(1)(3); c(0)(2)=tm(0)(2)(0) xor tm(0)(2)(1) xor tm(0)(2)(2) xor tm(0)(2)(3); c(0)(3)=tm(0)(3)(0) xor tm(0)(3)(1) xor tm(0)(3)(2) xor tm(0)(3)(3); -the 1 line- Line_1:FOR i in 0 to DM GENERATE Elem_all_1: for j in 0
10、to DM GENERATE tm(1)(j)(i)=a(1)(i) and b(i)(j); END GENERATE Elem_all_1; END GENERATE Line_1; c(1)(0)=tm(1)(0)(0) xor tm(1)(0)(1) xor tm(1)(0)(2) xor tm(1)(0)(3); c(1)(1)=tm(1)(1)(0) xor tm(1)(1)(1) xor tm(1)(1)(2) xor tm(1)(1)(3); c(1)(2)=tm(1)(2)(0) xor tm(1)(2)(1) xor tm(1)(2)(2) xor tm(1)(2)(3);
11、 c(1)(3)=tm(1)(3)(0) xor tm(1)(3)(1) xor tm(1)(3)(2) xor tm(1)(3)(3); -the 2 line- Line_2:FOR i in 0 to DM GENERATE Elem_all_2: for j in 0 to DM GENERATE tm(2)(j)(i)=a(2)(i) and b(i)(j); END GENERATE Elem_all_2; END GENERATE Line_2; c(2)(0)=tm(2)(0)(0) xor tm(2)(0)(1) xor tm(2)(0)(2) xor tm(2)(0)(3)
12、; c(2)(1)=tm(2)(1)(0) xor tm(2)(1)(1) xor tm(2)(1)(2) xor tm(2)(1)(3); c(2)(2)=tm(2)(2)(0) xor tm(2)(2)(1) xor tm(2)(2)(2) xor tm(2)(2)(3); c(2)(3)=tm(2)(3)(0) xor tm(2)(3)(1) xor tm(2)(3)(2) xor tm(2)(3)(3); -the 3 line- Line_3:FOR i in 0 to DM GENERATE Elem_all_3: for j in 0 to DM GENERATE tm(3)(j
13、)(i)=a(3)(i) and b(i)(j); END GENERATE Elem_all_3; END GENERATE Line_3; c(3)(0)=tm(3)(0)(0) xor tm(3)(0)(1) xor tm(3)(0)(2) xor tm(3)(0)(3); c(3)(1)=tm(3)(1)(0) xor tm(3)(1)(1) xor tm(3)(1)(2) xor tm(3)(1)(3); c(3)(2)=tm(3)(2)(0) xor tm(3)(2)(1) xor tm(3)(2)(2) xor tm(3)(2)(3); c(3)(3)=tm(3)(3)(0) x
14、or tm(3)(3)(1) xor tm(3)(3)(2) xor tm(3)(3)(3); end mtest;1.3 Dimension of matrix is 12 (Ref 1)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity testbench isGENERIC (DM : INTEGER := 11); -length of matrix minus 1-end testbench;architecture mtest of testbench istype matr
15、ix_type IS array (DM downto 0) of std_logic_vector (DM downto 0);type intem_matrix_type IS array (DM downto 0) of matrix_type;signal a,b,c: matrix_type;signal tm,tv:intem_matrix_type;-constant DM: integer:=3; -length of matrix minus 1-signal i,j,k,s: integer;begin test:process begin a=(1,1,0,0,0,0,0
16、,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
17、,0,0,0,0,0,0,0,0,0,1), -10- (1,0,0,0,0,0,0,0,0,0,0,0) -11- ); wait for 20 ns; b=a; s=1; wait for 20 ns; b=c; s=2; wait for 20 ns; b=c; s=3; wait for 20 ns; b=c; s=4; wait for 20 ns; b=c; s=5; wait for 20 ns; b=c; s=6; wait for 20 ns; b=c; s=7; wait for 20 ns; b=c; s=8; wait for 20 ns; b=c; s=9; wait
18、 for 20 ns; b=c; s=10; wait for 20 ns; b=c; s=11; wait for 20 ns; b=c; s=12; wait for 20 ns; wait; end process test; -the 0 line- Line_all:FOR k in 0 to DM GENERATE Line_i:FOR i in 0 to DM GENERATE Elem_all_0: for j in 0 to DM GENERATE tm(k)(j)(i)=a(k)(i) and b(i)(j); END GENERATE Elem_all_0; END GE
19、NERATE Line_i; END GENERATE Line_all;-c(0)(0)=tm(0)(0)(0) xor tm(0)(0)(1) xor tm(0)(0)(2) xor tm(0)(0)(3);- allc: for k in 0 to DM generate outc: for j in 0 to DM generate tv(k)(j)(0)=tm(k)(j)(0); c_computation: for i in 0 to DM-1 generate tv(k)(j)(i+1)=tv(k)(j)(i) xor tm(k)(j)(i+1); end generate c_
20、computation; c(k)(j)=tv(k)(j)(DM); end generate outc; end generate allc; end mtest;1.4 Dimension of matrix is 16(CCITT: x16+x12+x5+1) (Ref 1)Figure 3. results of F16library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity testbench isGENERIC (DM : INTEGER := 15); -length of ma
21、trix minus 1-end testbench;architecture mtest of testbench istype matrix_type IS array (DM downto 0) of std_logic_vector (DM downto 0);type intem_matrix_type IS array (DM downto 0) of matrix_type;signal a,b,c: matrix_type;signal tm,tv:intem_matrix_type;signal i,j,k,s: integer;begin test:process begi
22、n 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,
23、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- ); wait for 20 ns; b=a; s=1; wait for 20 ns; b=c; s=2; wait for 20 ns; b=c; s=3; wait for 20 ns; b=c; s=4; wait for 20 ns; b=c; s=5; wait for 20 ns; b=c; s=6; wait for 20 ns; b=c; s=7; wait for 20 ns; b=c; s=8; wait for 20 ns; b=c; s=9; wait for 20 ns; b=c; s=1
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1