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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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