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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_19/] [rtl/] [verilog/] [eth_rxethmac.v] - Blame information for rev 53

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

powered by: WebSVN 2.1.0

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