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

Subversion Repositories openarty

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

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

powered by: WebSVN 2.1.0

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