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

Subversion Repositories ts7300_opencore

[/] [ts7300_opencore/] [trunk/] [ethernet/] [eth_rxethmac.v] - Blame information for rev 6

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

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

powered by: WebSVN 2.1.0

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