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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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