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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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