source: XOpenSparcT1/trunk/OC-Ethernet/eth_rxethmac.v @ 6

Revision 6, 13.1 KB checked in by pntsvt00, 13 years ago (diff)

versione iniziale opensparc

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