]> git.zerfleddert.de Git - raggedstone/blame - ethernet/source/ethernet/eth_rxethmac.v
white space; fixme
[raggedstone] / ethernet / source / ethernet / eth_rxethmac.v
CommitLineData
40a1f26c 1//////////////////////////////////////////////////////////////////////
2//// ////
3//// eth_rxethmac.v ////
4//// ////
5//// This file is part of the Ethernet IP core project ////
6//// http://www.opencores.org/projects/ethmac/ ////
7//// ////
8//// Author(s): ////
9//// - Igor Mohor (igorM@opencores.org) ////
10//// - Novan Hartadi (novan@vlsi.itb.ac.id) ////
11//// - Mahmud Galela (mgalela@vlsi.itb.ac.id) ////
12//// ////
13//// All additional information is avaliable in the Readme.txt ////
14//// file. ////
15//// ////
16//////////////////////////////////////////////////////////////////////
17//// ////
18//// Copyright (C) 2001 Authors ////
19//// ////
20//// This source file may be used and distributed without ////
21//// restriction provided that this copyright statement is not ////
22//// removed from the file and that any derivative work contains ////
23//// the original copyright notice and the associated disclaimer. ////
24//// ////
25//// This source file is free software; you can redistribute it ////
26//// and/or modify it under the terms of the GNU Lesser General ////
27//// Public License as published by the Free Software Foundation; ////
28//// either version 2.1 of the License, or (at your option) any ////
29//// later version. ////
30//// ////
31//// This source is distributed in the hope that it will be ////
32//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
33//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
34//// PURPOSE. See the GNU Lesser General Public License for more ////
35//// details. ////
36//// ////
37//// You should have received a copy of the GNU Lesser General ////
38//// Public License along with this source; if not, download it ////
39//// from http://www.opencores.org/lgpl.shtml ////
40//// ////
41//////////////////////////////////////////////////////////////////////
42//
43// CVS Revision History
44//
45// $Log: eth_rxethmac.v,v $
46// Revision 1.1 2007-03-20 17:50:56 sithglan
47// add shit
48//
49// Revision 1.13 2005/02/21 12:48:07 igorm
50// Warning fixes.
51//
52// Revision 1.12 2004/04/26 15:26:23 igorm
53// - Bug connected to the TX_BD_NUM_Wr signal fixed (bug came in with the
54// previous update of the core.
55// - TxBDAddress is set to 0 after the TX is enabled in the MODER register.
56// - RxBDAddress is set to r_TxBDNum<<1 after the RX is enabled in the MODER
57// register. (thanks to Mathias and Torbjorn)
58// - Multicast reception was fixed. Thanks to Ulrich Gries
59//
60// Revision 1.11 2004/03/17 09:32:15 igorm
61// Multicast detection fixed. Only the LSB of the first byte is checked.
62//
63// Revision 1.10 2002/11/22 01:57:06 mohor
64// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
65// synchronized.
66//
67// Revision 1.9 2002/11/19 17:35:35 mohor
68// AddressMiss status is connecting to the Rx BD. AddressMiss is identifying
69// that a frame was received because of the promiscous mode.
70//
71// Revision 1.8 2002/02/16 07:15:27 mohor
72// Testbench fixed, code simplified, unused signals removed.
73//
74// Revision 1.7 2002/02/15 13:44:28 mohor
75// RxAbort is an output. No need to have is declared as wire.
76//
77// Revision 1.6 2002/02/15 11:17:48 mohor
78// File format changed.
79//
80// Revision 1.5 2002/02/14 20:48:43 billditt
81// Addition of new module eth_addrcheck.v
82//
83// Revision 1.4 2002/01/23 10:28:16 mohor
84// Link in the header changed.
85//
86// Revision 1.3 2001/10/19 08:43:51 mohor
87// eth_timescale.v changed to timescale.v This is done because of the
88// simulation of the few cores in a one joined project.
89//
90// Revision 1.2 2001/09/11 14:17:00 mohor
91// Few little NCSIM warnings fixed.
92//
93// Revision 1.1 2001/08/06 14:44:29 mohor
94// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
95// Include files fixed to contain no path.
96// File names and module names changed ta have a eth_ prologue in the name.
97// File eth_timescale.v is used to define timescale
98// All pin names on the top module are changed to contain _I, _O or _OE at the end.
99// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
100// and Mdo_OE. The bidirectional signal must be created on the top level. This
101// is done due to the ASIC tools.
102//
103// Revision 1.1 2001/07/30 21:23:42 mohor
104// Directory structure changed. Files checked and joind together.
105//
106// Revision 1.1 2001/06/27 21:26:19 mohor
107// Initial release of the RxEthMAC module.
108//
109//
110//
111//
112//
113
114`include "timescale.v"
115
116
117module eth_rxethmac (MRxClk, MRxDV, MRxD, Reset, Transmitting, MaxFL, r_IFG, HugEn, DlyCrcEn,
118 RxData, RxValid, RxStartFrm, RxEndFrm, ByteCnt, ByteCntEq0, ByteCntGreat2,
119 ByteCntMaxFrame, CrcError, StateIdle, StatePreamble, StateSFD, StateData,
120 MAC, r_Pro, r_Bro,r_HASH0, r_HASH1, RxAbort, AddressMiss, PassAll, ControlFrmAddressOK
121 );
122
123parameter Tp = 1;
124
125
126
127input MRxClk;
128input MRxDV;
129input [3:0] MRxD;
130input Transmitting;
131input HugEn;
132input DlyCrcEn;
133input [15:0] MaxFL;
134input r_IFG;
135input Reset;
136input [47:0] MAC; // Station Address
137input r_Bro; // broadcast disable
138input r_Pro; // promiscuous enable
139input [31:0] r_HASH0; // lower 4 bytes Hash Table
140input [31:0] r_HASH1; // upper 4 bytes Hash Table
141input PassAll;
142input ControlFrmAddressOK;
143
144output [7:0] RxData;
145output RxValid;
146output RxStartFrm;
147output RxEndFrm;
148output [15:0] ByteCnt;
149output ByteCntEq0;
150output ByteCntGreat2;
151output ByteCntMaxFrame;
152output CrcError;
153output StateIdle;
154output StatePreamble;
155output StateSFD;
156output [1:0] StateData;
157output RxAbort;
158output AddressMiss;
159
160reg [7:0] RxData;
161reg RxValid;
162reg RxStartFrm;
163reg RxEndFrm;
164reg Broadcast;
165reg Multicast;
166reg [5:0] CrcHash;
167reg CrcHashGood;
168reg DelayData;
169reg [7:0] LatchedByte;
170reg [7:0] RxData_d;
171reg RxValid_d;
172reg RxStartFrm_d;
173reg RxEndFrm_d;
174
175wire MRxDEqD;
176wire MRxDEq5;
177wire StateDrop;
178wire ByteCntEq1;
179wire ByteCntEq2;
180wire ByteCntEq3;
181wire ByteCntEq4;
182wire ByteCntEq5;
183wire ByteCntEq6;
184wire ByteCntEq7;
185wire ByteCntSmall7;
186wire [31:0] Crc;
187wire Enable_Crc;
188wire Initialize_Crc;
189wire [3:0] Data_Crc;
190wire GenerateRxValid;
191wire GenerateRxStartFrm;
192wire GenerateRxEndFrm;
193wire DribbleRxEndFrm;
194wire [3:0] DlyCrcCnt;
195wire IFGCounterEq24;
196
197assign MRxDEqD = MRxD == 4'hd;
198assign MRxDEq5 = MRxD == 4'h5;
199
200
201// Rx State Machine module
202eth_rxstatem rxstatem1 (.MRxClk(MRxClk), .Reset(Reset), .MRxDV(MRxDV), .ByteCntEq0(ByteCntEq0),
203 .ByteCntGreat2(ByteCntGreat2), .Transmitting(Transmitting), .MRxDEq5(MRxDEq5),
204 .MRxDEqD(MRxDEqD), .IFGCounterEq24(IFGCounterEq24), .ByteCntMaxFrame(ByteCntMaxFrame),
205 .StateData(StateData), .StateIdle(StateIdle), .StatePreamble(StatePreamble),
206 .StateSFD(StateSFD), .StateDrop(StateDrop)
207 );
208
209
210// Rx Counters module
211eth_rxcounters rxcounters1 (.MRxClk(MRxClk), .Reset(Reset), .MRxDV(MRxDV), .StateIdle(StateIdle),
212 .StateSFD(StateSFD), .StateData(StateData), .StateDrop(StateDrop),
213 .StatePreamble(StatePreamble), .MRxDEqD(MRxDEqD), .DlyCrcEn(DlyCrcEn),
214 .DlyCrcCnt(DlyCrcCnt), .Transmitting(Transmitting), .MaxFL(MaxFL), .r_IFG(r_IFG),
215 .HugEn(HugEn), .IFGCounterEq24(IFGCounterEq24), .ByteCntEq0(ByteCntEq0),
216 .ByteCntEq1(ByteCntEq1), .ByteCntEq2(ByteCntEq2), .ByteCntEq3(ByteCntEq3),
217 .ByteCntEq4(ByteCntEq4), .ByteCntEq5(ByteCntEq5), .ByteCntEq6(ByteCntEq6),
218 .ByteCntEq7(ByteCntEq7), .ByteCntGreat2(ByteCntGreat2),
219 .ByteCntSmall7(ByteCntSmall7), .ByteCntMaxFrame(ByteCntMaxFrame),
220 .ByteCntOut(ByteCnt)
221 );
222
223// Rx Address Check
224
225eth_rxaddrcheck rxaddrcheck1
226 (.MRxClk(MRxClk), .Reset( Reset), .RxData(RxData),
227 .Broadcast (Broadcast), .r_Bro (r_Bro), .r_Pro(r_Pro),
228 .ByteCntEq6(ByteCntEq6), .ByteCntEq7(ByteCntEq7), .ByteCntEq2(ByteCntEq2),
229 .ByteCntEq3(ByteCntEq3), .ByteCntEq4(ByteCntEq4), .ByteCntEq5(ByteCntEq5),
230 .HASH0(r_HASH0), .HASH1(r_HASH1),
231 .CrcHash(CrcHash), .CrcHashGood(CrcHashGood), .StateData(StateData),
232 .Multicast(Multicast), .MAC(MAC), .RxAbort(RxAbort),
233 .RxEndFrm(RxEndFrm), .AddressMiss(AddressMiss), .PassAll(PassAll),
234 .ControlFrmAddressOK(ControlFrmAddressOK)
235 );
236
237
238assign Enable_Crc = MRxDV & (|StateData & ~ByteCntMaxFrame);
239assign Initialize_Crc = StateSFD | DlyCrcEn & (|DlyCrcCnt[3:0]) & DlyCrcCnt[3:0] < 4'h9;
240
241assign Data_Crc[0] = MRxD[3];
242assign Data_Crc[1] = MRxD[2];
243assign Data_Crc[2] = MRxD[1];
244assign Data_Crc[3] = MRxD[0];
245
246
247// Connecting module Crc
248eth_crc crcrx (.Clk(MRxClk), .Reset(Reset), .Data(Data_Crc), .Enable(Enable_Crc), .Initialize(Initialize_Crc),
249 .Crc(Crc), .CrcError(CrcError)
250 );
251
252
253
254// Latching CRC for use in the hash table
255
256always @ (posedge MRxClk)
257begin
258 CrcHashGood <= #Tp StateData[0] & ByteCntEq6;
259end
260
261always @ (posedge MRxClk)
262begin
263 if(Reset | StateIdle)
264 CrcHash[5:0] <= #Tp 6'h0;
265 else
266 if(StateData[0] & ByteCntEq6)
267 CrcHash[5:0] <= #Tp Crc[31:26];
268end
269
270
271// Output byte stream
272always @ (posedge MRxClk or posedge Reset)
273begin
274 if(Reset)
275 begin
276 RxData_d[7:0] <= #Tp 8'h0;
277 DelayData <= #Tp 1'b0;
278 LatchedByte[7:0] <= #Tp 8'h0;
279 RxData[7:0] <= #Tp 8'h0;
280 end
281 else
282 begin
283 LatchedByte[7:0] <= #Tp {MRxD[3:0], LatchedByte[7:4]}; // Latched byte
284 DelayData <= #Tp StateData[0];
285
286 if(GenerateRxValid)
287 RxData_d[7:0] <= #Tp LatchedByte[7:0] & {8{|StateData}}; // Data goes through only in data state
288 else
289 if(~DelayData)
290 RxData_d[7:0] <= #Tp 8'h0; // Delaying data to be valid for two cycles. Zero when not active.
291
292 RxData[7:0] <= #Tp RxData_d[7:0]; // Output data byte
293 end
294end
295
296
297
298always @ (posedge MRxClk or posedge Reset)
299begin
300 if(Reset)
301 Broadcast <= #Tp 1'b0;
302 else
303 begin
304 if(StateData[0] & ~(&LatchedByte[7:0]) & ByteCntSmall7)
305 Broadcast <= #Tp 1'b0;
306 else
307 if(StateData[0] & (&LatchedByte[7:0]) & ByteCntEq1)
308 Broadcast <= #Tp 1'b1;
309 else
310 if(RxAbort | RxEndFrm)
311 Broadcast <= #Tp 1'b0;
312 end
313end
314
315
316always @ (posedge MRxClk or posedge Reset)
317begin
318 if(Reset)
319 Multicast <= #Tp 1'b0;
320 else
321 begin
322 if(StateData[0] & ByteCntEq1 & LatchedByte[0])
323 Multicast <= #Tp 1'b1;
324 else if(RxAbort | RxEndFrm)
325 Multicast <= #Tp 1'b0;
326 end
327end
328
329
330assign GenerateRxValid = StateData[0] & (~ByteCntEq0 | DlyCrcCnt >= 4'h3);
331
332always @ (posedge MRxClk or posedge Reset)
333begin
334 if(Reset)
335 begin
336 RxValid_d <= #Tp 1'b0;
337 RxValid <= #Tp 1'b0;
338 end
339 else
340 begin
341 RxValid_d <= #Tp GenerateRxValid;
342 RxValid <= #Tp RxValid_d;
343 end
344end
345
346
347assign GenerateRxStartFrm = StateData[0] & (ByteCntEq1 & ~DlyCrcEn | DlyCrcCnt == 4'h3 & DlyCrcEn);
348
349always @ (posedge MRxClk or posedge Reset)
350begin
351 if(Reset)
352 begin
353 RxStartFrm_d <= #Tp 1'b0;
354 RxStartFrm <= #Tp 1'b0;
355 end
356 else
357 begin
358 RxStartFrm_d <= #Tp GenerateRxStartFrm;
359 RxStartFrm <= #Tp RxStartFrm_d;
360 end
361end
362
363
364assign GenerateRxEndFrm = StateData[0] & (~MRxDV & ByteCntGreat2 | ByteCntMaxFrame);
365assign DribbleRxEndFrm = StateData[1] & ~MRxDV & ByteCntGreat2;
366
367
368always @ (posedge MRxClk or posedge Reset)
369begin
370 if(Reset)
371 begin
372 RxEndFrm_d <= #Tp 1'b0;
373 RxEndFrm <= #Tp 1'b0;
374 end
375 else
376 begin
377 RxEndFrm_d <= #Tp GenerateRxEndFrm;
378 RxEndFrm <= #Tp RxEndFrm_d | DribbleRxEndFrm;
379 end
380end
381
382
383endmodule
Impressum, Datenschutz