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

Subversion Repositories ethmac

[/] [ethmac/] [branches/] [unneback/] [rtl/] [verilog/] [eth_rxethmac.v] - Blame information for rev 62

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

powered by: WebSVN 2.1.0

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