OpenCores
URL https://opencores.org/ocsvn/openarty/openarty/trunk

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [rxecrc.v] - Blame information for rev 31

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 31 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    rxecrc.v
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     To detect any CRC errors in the packet as received.  The CRC
8
//              is not stripped as part of this process.
9
//
10
// Creator:     Dan Gisselquist, Ph.D.
11
//              Gisselquist Technology, LLC
12
//
13
////////////////////////////////////////////////////////////////////////////////
14
//
15
// Copyright (C) 2016, Gisselquist Technology, LLC
16
//
17
// This program is free software (firmware): you can redistribute it and/or
18
// modify it under the terms of  the GNU General Public License as published
19
// by the Free Software Foundation, either version 3 of the License, or (at
20
// your option) any later version.
21
//
22
// This program is distributed in the hope that it will be useful, but WITHOUT
23
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
24
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25
// for more details.
26
//
27
// You should have received a copy of the GNU General Public License along
28
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
29
// target there if the PDF file isn't present.)  If not, see
30
// <http://www.gnu.org/licenses/> for a copy.
31
//
32
// License:     GPL, v3, as defined and found on www.gnu.org,
33
//              http://www.gnu.org/licenses/gpl.html
34
//
35
//
36
////////////////////////////////////////////////////////////////////////////////
37
//
38
//
39
`define CRCBIT8 32'hedb88320
40
`define CRCBIT4 32'h76dc4190
41
`define CRCBIT2 32'h3b6e20c8
42
`define CRCBIT1 32'h1db71064
43
module  rxecrc(i_clk, i_ce, i_en, i_cancel, i_v, i_d, o_v, o_d, o_err);
44
        input                   i_clk, i_ce, i_en, i_cancel;
45
        input                   i_v;
46
        input           [3:0]    i_d;
47
        output  reg             o_v;
48
        output  reg     [3:0]    o_d;
49
        output  wire            o_err;
50
 
51
        reg     r_err;
52
        reg     [6:0]    r_mq; // Partial CRC matches
53
        reg     [3:0]    r_mp; // Prior CRC matches
54
 
55
        reg     [31:0]   r_crc;
56
        reg     [27:0]   r_crc_q0;
57
        reg     [23:0]   r_crc_q1;
58
        reg     [19:0]   r_crc_q2;
59
        reg     [15:0]   r_crc_q3;
60
        reg     [11:0]   r_crc_q4;
61
        reg     [ 7:0]   r_crc_q5;
62
        reg     [ 3:0]   r_crc_q6;
63
 
64
        reg     [14:0]   r_buf;
65
 
66
        wire    [3:0]    lownibble;
67
        assign  lownibble = r_crc[3:0] ^ i_d;
68
 
69
        wire    [31:0]   shifted_crc;
70
        assign  shifted_crc = { 4'h0, r_crc[27:0] };
71
        always @(posedge i_clk)
72
        if (i_ce)
73
        begin
74
 
75
                r_crc_q0 <= r_crc[31:4];
76
                r_crc_q1 <= r_crc_q0[27:4];
77
                r_crc_q2 <= r_crc_q1[23:4];
78
                r_crc_q3 <= r_crc_q2[19:4];
79
                r_crc_q4 <= r_crc_q3[15:4];
80
                r_crc_q5 <= r_crc_q4[11:4];
81
                r_crc_q6 <= r_crc_q5[ 7:4];
82
 
83
                r_buf <= { r_buf[9:0], i_v, i_d };
84
                if (((!i_ce)&&(!o_v))||(i_cancel))
85
                begin
86
                        r_crc <= 32'hffff_ffff;
87
                        r_err <= 1'b0;
88
 
89
                        r_mq[6:0] <= 7'h0;
90
 
91
                        r_mp <= 4'h0;
92
 
93
                        r_buf[ 4] <= 1'b0;
94
                        r_buf[ 9] <= 1'b0;
95
                        r_buf[14] <= 1'b0;
96
                end else
97
                begin
98
                        /// Calculate the CRC
99
                        case(lownibble)
100
                        4'h0: r_crc <= shifted_crc;
101
                        4'h1: r_crc <= shifted_crc ^ `CRCBIT1;
102
                        4'h2: r_crc <= shifted_crc ^ `CRCBIT2;
103
                        4'h3: r_crc <= shifted_crc ^ `CRCBIT2 ^ `CRCBIT1;
104
                        4'h4: r_crc <= shifted_crc ^ `CRCBIT4;
105
                        4'h5: r_crc <= shifted_crc ^ `CRCBIT4 ^ `CRCBIT1;
106
                        4'h6: r_crc <= shifted_crc ^ `CRCBIT4 ^ `CRCBIT2;
107
                        4'h7: r_crc <= shifted_crc ^ `CRCBIT4 ^ `CRCBIT2 ^ `CRCBIT1;
108
                        4'h8: r_crc <= shifted_crc ^ `CRCBIT8;
109
                        4'h9: r_crc <= shifted_crc ^ `CRCBIT8 ^ `CRCBIT1;
110
                        4'ha: r_crc <= shifted_crc ^ `CRCBIT8 ^ `CRCBIT2;
111
                        4'hb: r_crc <= shifted_crc ^ `CRCBIT8 ^ `CRCBIT2 ^ `CRCBIT1;
112
                        4'hc: r_crc <= shifted_crc ^ `CRCBIT8 ^ `CRCBIT4;
113
                        4'hd: r_crc <= shifted_crc ^ `CRCBIT8 ^ `CRCBIT4 ^ `CRCBIT1;
114
                        4'he: r_crc <= shifted_crc ^ `CRCBIT8 ^ `CRCBIT4 ^ `CRCBIT2;
115
                        4'hf: r_crc <= shifted_crc ^ `CRCBIT8 ^ `CRCBIT4 ^ `CRCBIT2 ^ `CRCBIT1;
116
                        endcase
117
 
118
                        r_mq[0] <=          (i_v)&&(i_d == r_crc[3:0]);
119
                        r_mq[1] <= (r_mq[0])&&(i_v)&&(i_d == r_crc_q0[3:0]);
120
                        r_mq[2] <= (r_mq[1])&&(i_v)&&(i_d == r_crc_q1[3:0]);
121
                        r_mq[3] <= (r_mq[2])&&(i_v)&&(i_d == r_crc_q2[3:0]);
122
                        r_mq[4] <= (r_mq[3])&&(i_v)&&(i_d == r_crc_q3[3:0]);
123
                        r_mq[5] <= (r_mq[4])&&(i_v)&&(i_d == r_crc_q4[3:0]);
124
                        r_mq[6] <= (r_mq[5])&&(i_v)&&(i_d == r_crc_q5[3:0]);
125
                        //r_mq7<=(r_mq6)&&(i_v)&&(i_d == r_crc_q6[3:0]);
126
 
127
                        r_mp <= { r_mp[2:0],
128
                                (r_mq[6])&&(i_v)&&(i_d == r_crc_q6[3:0]) };
129
 
130
                        // Now, we have an error if ...
131
                        // On the first empty, none of the prior N matches
132
                        // matched.
133
                        r_err <= (r_err)||((i_en)&&(!i_v)&&(r_buf[4])&&(r_mp == 4'h0));
134
                        if ((!i_v)&&(r_buf[4]))
135
                        begin
136
                                if (r_mp[3])
137
                                begin
138
                                        r_buf[ 4] <= 1'b0;
139
                                        r_buf[ 9] <= 1'b0;
140
                                        r_buf[14] <= 1'b0;
141
                                end else if (r_mp[2])
142
                                begin
143
                                        r_buf[4] <= 1'b0;
144
                                        r_buf[9] <= 1'b0;
145
                                end else if (r_mp[1])
146
                                        r_buf[4] <= 1'b0;
147
                                // else if (r_mp[0]) ... keep everything
148
                        end
149
 
150
                        o_v <= r_buf[14];
151
                        o_d <= r_buf[13:10];
152
                end
153
        end
154
 
155
        assign o_err = r_err;
156
 
157
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.