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

Subversion Repositories ethmac

[/] [ethmac/] [trunk/] [rtl/] [verilog/] [eth_rxethmac.v] - Blame information for rev 330

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

Line No. Rev Author Line
1 15 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_rxethmac.v                                              ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6 37 mohor
////  http://www.opencores.org/projects/ethmac/                   ////
7 15 mohor
////                                                              ////
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 330 igorm
// 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 321 igorm
// 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 317 igorm
// 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 261 mohor
// 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 250 mohor
// Revision 1.8  2002/02/16 07:15:27  mohor
66
// Testbench fixed, code simplified, unused signals removed.
67
//
68 65 mohor
// 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 62 mohor
// Revision 1.6  2002/02/15 11:17:48  mohor
72
// File format changed.
73
//
74 58 mohor
// Revision 1.5  2002/02/14 20:48:43  billditt
75
// Addition  of new module eth_addrcheck.v
76
//
77 53 billditt
// Revision 1.4  2002/01/23 10:28:16  mohor
78
// Link in the header changed.
79
//
80 37 mohor
// 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 22 mohor
// Revision 1.2  2001/09/11 14:17:00  mohor
85
// Few little NCSIM warnings fixed.
86
//
87 18 mohor
// 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 15 mohor
// 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 22 mohor
`include "timescale.v"
109 15 mohor
 
110
 
111
module eth_rxethmac (MRxClk, MRxDV, MRxD, Reset, Transmitting, MaxFL, r_IFG, HugEn, DlyCrcEn,
112 65 mohor
                     RxData, RxValid, RxStartFrm, RxEndFrm, ByteCnt, ByteCntEq0, ByteCntGreat2,
113
                     ByteCntMaxFrame, CrcError, StateIdle, StatePreamble, StateSFD, StateData,
114 261 mohor
                     MAC, r_Pro, r_Bro,r_HASH0, r_HASH1, RxAbort, AddressMiss, PassAll, ControlFrmAddressOK
115 15 mohor
                    );
116
 
117
parameter Tp = 1;
118
 
119
 
120
 
121
input         MRxClk;
122
input         MRxDV;
123
input   [3:0] MRxD;
124
input         Transmitting;
125
input         HugEn;
126
input         DlyCrcEn;
127
input  [15:0] MaxFL;
128
input         r_IFG;
129
input         Reset;
130 53 billditt
input  [47:0] MAC;     //  Station Address  
131
input         r_Bro;   //  broadcast disable
132
input         r_Pro;   //  promiscuous enable 
133
input [31:0]  r_HASH0; //  lower 4 bytes Hash Table
134
input [31:0]  r_HASH1; //  upper 4 bytes Hash Table
135 261 mohor
input         PassAll;
136
input         ControlFrmAddressOK;
137
 
138 15 mohor
output  [7:0] RxData;
139
output        RxValid;
140
output        RxStartFrm;
141
output        RxEndFrm;
142
output [15:0] ByteCnt;
143
output        ByteCntEq0;
144
output        ByteCntGreat2;
145
output        ByteCntMaxFrame;
146
output        CrcError;
147
output        StateIdle;
148
output        StatePreamble;
149
output        StateSFD;
150
output  [1:0] StateData;
151 53 billditt
output        RxAbort;
152 250 mohor
output        AddressMiss;
153 15 mohor
 
154
reg     [7:0] RxData;
155
reg           RxValid;
156
reg           RxStartFrm;
157
reg           RxEndFrm;
158
reg           Broadcast;
159
reg           Multicast;
160 321 igorm
reg     [5:0] CrcHash;
161 15 mohor
reg           CrcHashGood;
162
reg           DelayData;
163
reg     [7:0] LatchedByte;
164
reg     [7:0] RxData_d;
165
reg           RxValid_d;
166
reg           RxStartFrm_d;
167
reg           RxEndFrm_d;
168
 
169
wire          MRxDEqD;
170
wire          MRxDEq5;
171
wire          StateDrop;
172
wire          ByteCntEq1;
173 53 billditt
wire          ByteCntEq2;
174
wire          ByteCntEq3;
175
wire          ByteCntEq4;
176
wire          ByteCntEq5;
177 15 mohor
wire          ByteCntEq6;
178 53 billditt
wire          ByteCntEq7;
179 15 mohor
wire          ByteCntSmall7;
180
wire   [31:0] Crc;
181
wire          Enable_Crc;
182
wire          Initialize_Crc;
183
wire    [3:0] Data_Crc;
184
wire          GenerateRxValid;
185
wire          GenerateRxStartFrm;
186
wire          GenerateRxEndFrm;
187
wire          DribbleRxEndFrm;
188
wire    [3:0] DlyCrcCnt;
189 330 igorm
wire          IFGCounterEq24;
190 15 mohor
 
191
assign MRxDEqD = MRxD == 4'hd;
192
assign MRxDEq5 = MRxD == 4'h5;
193
 
194
 
195
// Rx State Machine module
196
eth_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
205
eth_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 58 mohor
                            .ByteCntEq1(ByteCntEq1), .ByteCntEq2(ByteCntEq2), .ByteCntEq3(ByteCntEq3),
211
                            .ByteCntEq4(ByteCntEq4), .ByteCntEq5(ByteCntEq5), .ByteCntEq6(ByteCntEq6),
212
                            .ByteCntEq7(ByteCntEq7), .ByteCntGreat2(ByteCntGreat2),
213 15 mohor
                            .ByteCntSmall7(ByteCntSmall7), .ByteCntMaxFrame(ByteCntMaxFrame),
214 330 igorm
                            .ByteCntOut(ByteCnt)
215 15 mohor
                           );
216
 
217 53 billditt
// Rx Address Check
218 15 mohor
 
219 58 mohor
eth_rxaddrcheck rxaddrcheck1
220 261 mohor
              (.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 58 mohor
               .HASH0(r_HASH0),         .HASH1(r_HASH1),
225 321 igorm
               .CrcHash(CrcHash),       .CrcHashGood(CrcHashGood),  .StateData(StateData),
226 261 mohor
               .Multicast(Multicast),   .MAC(MAC),                  .RxAbort(RxAbort),
227
               .RxEndFrm(RxEndFrm),     .AddressMiss(AddressMiss),  .PassAll(PassAll),
228
               .ControlFrmAddressOK(ControlFrmAddressOK)
229 58 mohor
              );
230 15 mohor
 
231 53 billditt
 
232 15 mohor
assign Enable_Crc = MRxDV & (|StateData & ~ByteCntMaxFrame);
233
assign Initialize_Crc = StateSFD | DlyCrcEn & (|DlyCrcCnt[3:0]) & DlyCrcCnt[3:0] < 4'h9;
234
 
235
assign Data_Crc[0] = MRxD[3];
236
assign Data_Crc[1] = MRxD[2];
237
assign Data_Crc[2] = MRxD[1];
238
assign Data_Crc[3] = MRxD[0];
239
 
240
 
241
// Connecting module Crc
242
eth_crc crcrx (.Clk(MRxClk), .Reset(Reset), .Data(Data_Crc), .Enable(Enable_Crc), .Initialize(Initialize_Crc),
243
               .Crc(Crc), .CrcError(CrcError)
244 58 mohor
              );
245 15 mohor
 
246
 
247
 
248
// Latching CRC for use in the hash table
249
 
250
always @ (posedge MRxClk)
251
begin
252
  CrcHashGood <= #Tp StateData[0] & ByteCntEq6;
253
end
254
 
255
always @ (posedge MRxClk)
256
begin
257
  if(Reset | StateIdle)
258 321 igorm
    CrcHash[5:0] <= #Tp 6'h0;
259 15 mohor
  else
260
  if(StateData[0] & ByteCntEq6)
261 321 igorm
    CrcHash[5:0] <= #Tp Crc[31:26];
262 15 mohor
end
263
 
264
 
265
// Output byte stream
266
always @ (posedge MRxClk or posedge Reset)
267
begin
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 330 igorm
      LatchedByte[7:0]   <= #Tp {MRxD[3:0], LatchedByte[7:4]};  // Latched byte
278 15 mohor
      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
288
end
289
 
290
 
291
 
292
always @ (posedge MRxClk or posedge Reset)
293
begin
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 18 mohor
      if(StateData[0] & (&LatchedByte[7:0]) & ByteCntEq1)
302 15 mohor
        Broadcast <= #Tp 1'b1;
303 58 mohor
      else
304
      if(RxAbort | RxEndFrm)
305
        Broadcast <= #Tp 1'b0;
306 15 mohor
    end
307
end
308
 
309
 
310
always @ (posedge MRxClk or posedge Reset)
311
begin
312
  if(Reset)
313
    Multicast <= #Tp 1'b0;
314
  else
315
    begin
316 317 igorm
      if(StateData[0] & ByteCntEq1 & LatchedByte[0])
317 53 billditt
        Multicast <= #Tp 1'b1;
318 317 igorm
      else if(RxAbort | RxEndFrm)
319 58 mohor
      Multicast <= #Tp 1'b0;
320 15 mohor
    end
321
end
322
 
323
 
324
assign GenerateRxValid = StateData[0] & (~ByteCntEq0 | DlyCrcCnt >= 4'h3);
325
 
326
always @ (posedge MRxClk or posedge Reset)
327
begin
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
338
end
339
 
340
 
341
assign GenerateRxStartFrm = StateData[0] & (ByteCntEq1 & ~DlyCrcEn | DlyCrcCnt == 4'h3 & DlyCrcEn);
342
 
343
always @ (posedge MRxClk or posedge Reset)
344
begin
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
355
end
356
 
357
 
358
assign GenerateRxEndFrm = StateData[0] & (~MRxDV & ByteCntGreat2 | ByteCntMaxFrame);
359
assign DribbleRxEndFrm  = StateData[1] &  ~MRxDV & ByteCntGreat2;
360
 
361
 
362
always @ (posedge MRxClk or posedge Reset)
363
begin
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
374
end
375
 
376
 
377
endmodule

powered by: WebSVN 2.1.0

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