d6bb22b5196adbb0e3b2aa332df001c38475cf58
[debian/gnuradio] / usrp2 / fpga / eth / rtl / verilog / MAC_rx / CRC_chk.v
1 //////////////////////////////////////////////////////////////////////\r
2 ////                                                              ////\r
3 ////  CRC_chk.v                                                   ////\r
4 ////                                                              ////\r
5 ////  This file is part of the Ethernet IP core project           ////\r
6 ////  http://www.opencores.org/projects.cgi/web/ethernet_tri_mode/////\r
7 ////                                                              ////\r
8 ////  Author(s):                                                  ////\r
9 ////      - Jon Gao (gaojon@yahoo.com)                            ////\r
10 ////                                                              ////\r
11 ////                                                              ////\r
12 //////////////////////////////////////////////////////////////////////\r
13 ////                                                              ////\r
14 //// Copyright (C) 2001 Authors                                   ////\r
15 ////                                                              ////\r
16 //// This source file may be used and distributed without         ////\r
17 //// restriction provided that this copyright statement is not    ////\r
18 //// removed from the file and that any derivative work contains  ////\r
19 //// the original copyright notice and the associated disclaimer. ////\r
20 ////                                                              ////\r
21 //// This source file is free software; you can redistribute it   ////\r
22 //// and/or modify it under the terms of the GNU Lesser General   ////\r
23 //// Public License as published by the Free Software Foundation; ////\r
24 //// either version 2.1 of the License, or (at your option) any   ////\r
25 //// later version.                                               ////\r
26 ////                                                              ////\r
27 //// This source is distributed in the hope that it will be       ////\r
28 //// useful, but WITHOUT ANY WARRANTY; without even the implied   ////\r
29 //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////\r
30 //// PURPOSE.  See the GNU Lesser General Public License for more ////\r
31 //// details.                                                     ////\r
32 ////                                                              ////\r
33 //// You should have received a copy of the GNU Lesser General    ////\r
34 //// Public License along with this source; if not, download it   ////\r
35 //// from http://www.opencores.org/lgpl.shtml                     ////\r
36 ////                                                              ////\r
37 //////////////////////////////////////////////////////////////////////\r
38 //                                                                    \r
39 // CVS Revision History                                               \r
40 //                                                                    \r
41 // $Log: CRC_chk.v,v $\r
42 // Revision 1.3  2006/01/19 14:07:54  maverickist\r
43 // verification is complete.\r
44 //\r
45 // Revision 1.2  2005/12/16 06:44:16  Administrator\r
46 // replaced tab with space.\r
47 // passed 9.6k length frame test.\r
48 //\r
49 // Revision 1.1.1.1  2005/12/13 01:51:45  Administrator\r
50 // no message\r
51 //                                           \r
52 \r
53 module CRC_chk(\r
54 Reset       ,\r
55 Clk         ,\r
56 CRC_data    ,\r
57 CRC_init    ,\r
58 CRC_en      ,\r
59 //From CPU  \r
60 CRC_chk_en  ,\r
61 CRC_err     \r
62 );\r
63 input       Reset       ;\r
64 input       Clk         ;\r
65 input[7:0]  CRC_data    ;\r
66 input       CRC_init    ;\r
67 input       CRC_en      ;\r
68             //From CPU\r
69 input       CRC_chk_en  ;\r
70 output      CRC_err     ; \r
71 //******************************************************************************   \r
72 //internal signals                                                              \r
73 //******************************************************************************\r
74 reg [31:0]  CRC_reg;\r
75 //******************************************************************************\r
76 //input data width is 8bit, and the first bit is bit[0]\r
77 function[31:0]  NextCRC;\r
78     input[7:0]      D;\r
79     input[31:0]     C;\r
80     reg[31:0]       NewCRC;\r
81     begin\r
82     NewCRC[0]=C[24]^C[30]^D[1]^D[7];\r
83     NewCRC[1]=C[25]^C[31]^D[0]^D[6]^C[24]^C[30]^D[1]^D[7];\r
84     NewCRC[2]=C[26]^D[5]^C[25]^C[31]^D[0]^D[6]^C[24]^C[30]^D[1]^D[7];\r
85     NewCRC[3]=C[27]^D[4]^C[26]^D[5]^C[25]^C[31]^D[0]^D[6];\r
86     NewCRC[4]=C[28]^D[3]^C[27]^D[4]^C[26]^D[5]^C[24]^C[30]^D[1]^D[7];\r
87     NewCRC[5]=C[29]^D[2]^C[28]^D[3]^C[27]^D[4]^C[25]^C[31]^D[0]^D[6]^C[24]^C[30]^D[1]^D[7];\r
88     NewCRC[6]=C[30]^D[1]^C[29]^D[2]^C[28]^D[3]^C[26]^D[5]^C[25]^C[31]^D[0]^D[6];\r
89     NewCRC[7]=C[31]^D[0]^C[29]^D[2]^C[27]^D[4]^C[26]^D[5]^C[24]^D[7];\r
90     NewCRC[8]=C[0]^C[28]^D[3]^C[27]^D[4]^C[25]^D[6]^C[24]^D[7];\r
91     NewCRC[9]=C[1]^C[29]^D[2]^C[28]^D[3]^C[26]^D[5]^C[25]^D[6];\r
92     NewCRC[10]=C[2]^C[29]^D[2]^C[27]^D[4]^C[26]^D[5]^C[24]^D[7];\r
93     NewCRC[11]=C[3]^C[28]^D[3]^C[27]^D[4]^C[25]^D[6]^C[24]^D[7];\r
94     NewCRC[12]=C[4]^C[29]^D[2]^C[28]^D[3]^C[26]^D[5]^C[25]^D[6]^C[24]^C[30]^D[1]^D[7];\r
95     NewCRC[13]=C[5]^C[30]^D[1]^C[29]^D[2]^C[27]^D[4]^C[26]^D[5]^C[25]^C[31]^D[0]^D[6];\r
96     NewCRC[14]=C[6]^C[31]^D[0]^C[30]^D[1]^C[28]^D[3]^C[27]^D[4]^C[26]^D[5];\r
97     NewCRC[15]=C[7]^C[31]^D[0]^C[29]^D[2]^C[28]^D[3]^C[27]^D[4];\r
98     NewCRC[16]=C[8]^C[29]^D[2]^C[28]^D[3]^C[24]^D[7];\r
99     NewCRC[17]=C[9]^C[30]^D[1]^C[29]^D[2]^C[25]^D[6];\r
100     NewCRC[18]=C[10]^C[31]^D[0]^C[30]^D[1]^C[26]^D[5];\r
101     NewCRC[19]=C[11]^C[31]^D[0]^C[27]^D[4];\r
102     NewCRC[20]=C[12]^C[28]^D[3];\r
103     NewCRC[21]=C[13]^C[29]^D[2];\r
104     NewCRC[22]=C[14]^C[24]^D[7];\r
105     NewCRC[23]=C[15]^C[25]^D[6]^C[24]^C[30]^D[1]^D[7];\r
106     NewCRC[24]=C[16]^C[26]^D[5]^C[25]^C[31]^D[0]^D[6];\r
107     NewCRC[25]=C[17]^C[27]^D[4]^C[26]^D[5];\r
108     NewCRC[26]=C[18]^C[28]^D[3]^C[27]^D[4]^C[24]^C[30]^D[1]^D[7];\r
109     NewCRC[27]=C[19]^C[29]^D[2]^C[28]^D[3]^C[25]^C[31]^D[0]^D[6];\r
110     NewCRC[28]=C[20]^C[30]^D[1]^C[29]^D[2]^C[26]^D[5];\r
111     NewCRC[29]=C[21]^C[31]^D[0]^C[30]^D[1]^C[27]^D[4];\r
112     NewCRC[30]=C[22]^C[31]^D[0]^C[28]^D[3];\r
113     NewCRC[31]=C[23]^C[29]^D[2];\r
114     NextCRC=NewCRC;\r
115     end\r
116         endfunction\r
117 \r
118 always @ (posedge Clk or posedge Reset)\r
119     if (Reset)\r
120         CRC_reg     <=32'hffffffff;\r
121     else if (CRC_init)\r
122         CRC_reg     <=32'hffffffff;\r
123     else if (CRC_en)\r
124         CRC_reg     <=NextCRC(CRC_data,CRC_reg);\r
125 \r
126 assign  CRC_err = CRC_chk_en&(CRC_reg[31:0] != 32'hc704dd7b);\r
127 \r
128 endmodule\r