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

Subversion Repositories cheap_ethernet

[/] [cheap_ethernet/] [trunk/] [Ethernet_test/] [EthernetRX.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 graver
`timescale 1ns / 1ps
2
`include "const.vh"
3
//////////////////////////////////////////////////////////////////////////////////
4
// Company: 
5
// Engineer: Ivan Krutov (grvfrv@gmail.com)
6
// 
7
// Create Date:    10:39:30 08/29/2012 
8
// Design Name: 
9
// Module Name:    EthernetRX 
10
// Project Name:   Cheap Ethernet
11
// Target Devices: Spartan 3E
12
// Tool versions:  ISE 14.1
13
// Description:    Base functional or ARP, ICMP, UDP
14
//
15
// Dependencies:   TENBASET_RxD.v, const.vh
16
//
17
// Revision: 
18
// Revision 0.9 beta
19
// Additional Comments: 
20
//
21
//////////////////////////////////////////////////////////////////////////////////
22
module EthernetRX(clk50,
23
        Ethernet_RD,
24
        HostIP, HostMAC, HostPort,
25
        RcvStart, RcvStop, RcvData, RcvDataLen, RcvDataPos, RcvDataAvailable, RcvCRCValid, ReceivingPacket,
26
        RcvPacketType, RcvICMPId, RcvICMPSeq, RcvICMPCRC,
27
        RcvFromIP, RcvFromMAC, RcvFromPort);
28
 
29
input clk50;
30
input Ethernet_RD;
31
input [31:0] HostIP;
32
input [47:0] HostMAC;
33
input [15:0] HostPort;
34
 
35
output RcvStart;
36
output RcvStop;
37
output [7:0] RcvData;
38
output [9:0] RcvDataLen;
39
output [9:0] RcvDataPos;
40
output RcvDataAvailable;
41
output [31:0] RcvFromIP;
42
output [47:0] RcvFromMAC;
43
output [15:0] RcvFromPort;
44
output RcvCRCValid;
45
output ReceivingPacket;
46
output [2:0] RcvPacketType;
47
output [15:0] RcvICMPId;
48
output [15:0] RcvICMPSeq;
49
output [15:0] RcvICMPCRC;
50
 
51
 
52
wire [7:0] RcvData;
53
wire RcvStop;
54
wire new_bit_available;
55
wire new_byte_available;
56
wire end_of_Ethernet_frame;
57
wire [9:0] sync2;
58
reg [31:0] RcvFromIP = 0;
59
reg [47:0] RcvFromMAC = 0;
60
reg [15:0] RcvFromPort = 0;
61
//reg RcvStart = 0;
62
reg [9:0] RcvDataLen = 0;
63
reg [9:0] RcvDataPos = 0;
64
reg RcvDataAvailable = 0;
65
reg RcvUserData = 0;
66
reg RcvCRCValid = 0;
67
reg [2:0] RcvPacketType = 0;
68
reg [15:0] RcvICMPId = 0;
69
reg [15:0] RcvICMPSeq = 0;
70
reg [15:0] RcvICMPCRC = 0;
71
 
72
reg IgnorePacket = 0;
73
reg [7:0] tmp = 0;
74
reg CRCinit = 0;
75
reg [31:0] CRC = 0;
76
reg [4:0] CRCcnt = 0;
77
reg CRCflush = 0;
78
reg MACValid = 0;
79
reg BroadcastValid = 0;
80
reg Broadcast = 0;
81
reg ARP = 0;
82
reg ICMP = 0;
83
 
84
assign ReceivingPacket = |sync2[9:3]; //~end_of_Ethernet_frame;
85
 
86
TENBASET_RxD TENBASET_RxD1 (clk50,
87
        Ethernet_RD,
88
        RcvData,        RcvStart, RcvStop, new_bit_available, new_byte_available, end_of_Ethernet_frame, sync2);
89
 
90
// generate the CRC32
91
wire CRCinput = CRCflush ? 0 : RcvData[7] ^ CRC[31];
92
always @(posedge clk50) begin
93
        CRCinit <= (!RcvUserData && sync2 == 0);
94
        if (new_bit_available)
95
                CRC <= CRCinit ? ~0 : ({CRC[30:0], 1'b0} ^ ({32{CRCinput}} & 32'h04C11DB7));
96
 
97
        if (end_of_Ethernet_frame)
98
                begin
99
                CRCcnt <= 0;
100
                RcvCRCValid <= 0;
101
                end
102
 
103
        if (new_bit_available && CRCflush && (~CRC[31] == RcvData[7]))
104
                begin
105
                CRCcnt <= CRCcnt + 1;
106
                if (&CRCcnt)
107
                        RcvCRCValid <= 1;
108
                end
109
end
110
 
111
// Packet disasembling
112
always @(posedge clk50) begin
113
        RcvDataAvailable <= 0;
114
        if (end_of_Ethernet_frame)
115
                begin
116
                BroadcastValid <= 1;
117
                MACValid <= 1;
118
                ARP <= 0;
119
                ICMP <= 0;
120
                Broadcast <= 0;
121
                CRCflush <= 0;
122
                RcvUserData <= 0;
123
                RcvDataPos = 0;
124
                IgnorePacket <= 0;
125
                end
126
 
127
        if (new_byte_available && !IgnorePacket)
128
                begin
129
                if (!RcvUserData)
130
                        case (sync2[9:3])
131
                                01: begin
132
                                         RcvPacketType <= `Unknown;
133
                                         if (RcvData != 8'hFF)
134
                                                 BroadcastValid <= 0;
135
                                         if (RcvData != HostMAC[47:40])
136
                                                 MACValid <= 0;
137
                                         end
138
                                02: begin
139
                                         if (RcvData != 8'hFF)
140
                                                 BroadcastValid <= 0;
141
                                         if (RcvData != HostMAC[39:32])
142
                                                 MACValid <= 0; end
143
                                03: begin
144
                                         if (RcvData != 8'hFF)
145
                                                 BroadcastValid <= 0;
146
                                         if (RcvData != HostMAC[31:24])
147
                                                 MACValid <= 0;
148
                                         end
149
                                04: begin
150
                                         if (RcvData != 8'hFF)
151
                                                 BroadcastValid <= 0;
152
                                         if (RcvData != HostMAC[23:16])
153
                                                 MACValid <= 0;
154
                                         end
155
                                05: begin
156
                                         if (RcvData != 8'hFF)
157
                                                 BroadcastValid <= 0;
158
                                         if (RcvData != HostMAC[15:8])
159
                                                 MACValid <= 0;
160
                                         end
161
                                06: begin
162
                                         if (RcvData != 8'hFF)
163
                                                 BroadcastValid <= 0;
164
                                         if (RcvData != HostMAC[7:0])
165
                                                 MACValid <= 0;
166
                                         end
167
                                07: begin
168
                                         RcvFromMAC[47:40] <= RcvData;
169
                                         if (BroadcastValid)
170
                                                 Broadcast <= 1;
171
                                         else if (!MACValid)
172
                                                 IgnorePacket <= 1;
173
                                         end
174
                                08: RcvFromMAC[39:32] <= RcvData;
175
                                09: RcvFromMAC[31:24] <= RcvData;
176
                                10: RcvFromMAC[23:16] <= RcvData;
177
                                11: RcvFromMAC[15:8] <= RcvData;
178
                                12: RcvFromMAC[7:0] <= RcvData;
179
 
180
                                13: if (RcvData != 8) IgnorePacket <= 1;        // protocol type
181
                                14: if (RcvData == 6) ARP <= 1;
182
                                17: tmp <= RcvData;                                                             // ICMP length
183
                                18: RcvDataLen <= {tmp, RcvData} - 28;          // ICMP length
184
                                21: tmp <= RcvData;
185
                                22: if (ARP)
186
                                                 if (tmp == 8'h00)
187
                                                         begin
188
                                                         RcvDataLen <= 18;
189
                                                         if (RcvData == 8'h01 && Broadcast)
190
                                                                 RcvPacketType <= `ARPReq;
191
                                                         else if (RcvData == 8'h02)
192
                                                                 RcvPacketType <= `ARPReply;
193
                                                         end
194
                                23: if (ARP) RcvFromMAC[47:40] <= RcvData;
195
                                24: if (ARP)
196
                                                 RcvFromMAC[39:32] <= RcvData;
197
                                         else if (RcvData == 1)
198
                                                 ICMP <= 1;
199
                                         else if (RcvData == 17)
200
                                                 RcvPacketType <= `UDP;
201
                                25: if (ARP) RcvFromMAC[31:24] <= RcvData;
202
                                26: if (ARP) RcvFromMAC[23:16] <= RcvData;
203
                                27: if (ARP)
204
                                                 RcvFromMAC[15:8] <= RcvData;
205
                                         else
206
                                                 RcvFromIP[31:24] <= RcvData;
207
                                28: if (ARP)
208
                                                 RcvFromMAC[7:0] <= RcvData;
209
                                         else
210
                                                 RcvFromIP[23:16] <= RcvData;
211
                                29: if (ARP)
212
                                                 RcvFromIP[31:24] <= RcvData;
213
                                         else
214
                                                 RcvFromIP[15:8] <= RcvData;
215
                                30: if (ARP)
216
                                                 RcvFromIP[23:16] <= RcvData;
217
                                         else
218
                                                 RcvFromIP[7:0] <= RcvData;
219
                                31: if (ARP) RcvFromIP[15:8] <= RcvData;
220
                                32: if (ARP) RcvFromIP[7:0] <= RcvData;
221
 
222
                                35: if (ICMP) begin
223
                                                 if (RcvData == 8)
224
                                                         RcvPacketType <= `ICMPReq;
225
                                                 end
226
                                         else
227
                                                 RcvFromPort[15:8] <= RcvData;
228
                                36: RcvFromPort[7:0] <= RcvData;
229
                                37: if (!ARP)
230
                                                 if (ICMP)
231
                                                         RcvICMPCRC[15:8] <= RcvData;
232
                                                 else if (RcvData != HostPort[15:8])
233
                                                         IgnorePacket <= 1;
234
                                38: if (!ARP)
235
                                                 if (ICMP)
236
                                                         RcvICMPCRC[7:0] <= RcvData;
237
                                                 else if (RcvData != HostPort[7:0])
238
                                                         IgnorePacket <= 1;
239
                                39: if (ARP)
240
                                                 begin
241
                                                 if (RcvData != HostIP[31:24])
242
                                                         IgnorePacket <= 1;
243
                                                 end
244
                                         else if (ICMP)
245
                                                 RcvICMPId[15:8] <= RcvData;
246
                                         else
247
                                                 tmp <= RcvData;
248
                                40: if (ARP) begin
249
                                                 if (RcvData != HostIP[23:16])
250
                                                         IgnorePacket <= 1;
251
                                                 end
252
                                         else if (ICMP)
253
                                                 RcvICMPId[7:0] <= RcvData;
254
                                         else
255
                                                 RcvDataLen <= {tmp, RcvData} - 8;
256
                                41: if (ARP)
257
                                                 begin
258
                                                 if (RcvData != HostIP[15:8])
259
                                                         IgnorePacket <= 1;
260
                                                 end
261
                                         else if (ICMP)
262
                                                 RcvICMPSeq[15:8] <= RcvData;
263
                                42: if (ARP) begin
264
                                                 if (RcvData != HostIP[7:0])
265
                                                         IgnorePacket <= 1;
266
                                                 end
267
                                         else if (ICMP)
268
                                                 RcvICMPSeq[7:0] <= RcvData;
269
                                43: begin
270
                                         RcvDataAvailable <= 1;
271
                                         RcvUserData <= 1;
272
                                         end
273
                        endcase
274
                else
275
                        begin
276
                        RcvDataAvailable <= 1;
277
                        RcvDataPos = RcvDataPos + 1;
278
                        if (RcvDataPos + 1 == RcvDataLen)
279
                                CRCflush <= 1;
280
                        end
281
                end
282
end
283
 
284
endmodule

powered by: WebSVN 2.1.0

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