source: XOpenSparcT1/trunk/OC-Ethernet/eth_rxcounters.v @ 6

Revision 6, 8.2 KB checked in by pntsvt00, 13 years ago (diff)

versione iniziale opensparc

Line 
1//////////////////////////////////////////////////////////////////////
2////                                                              ////
3////  eth_rxcounters.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.5  2002/02/15 11:13:29  mohor
47// Format of the file changed a bit.
48//
49// Revision 1.4  2002/02/14 20:19:41  billditt
50// Modified for Address Checking,
51// addition of eth_addrcheck.v
52//
53// Revision 1.3  2002/01/23 10:28:16  mohor
54// Link in the header changed.
55//
56// Revision 1.2  2001/10/19 08:43:51  mohor
57// eth_timescale.v changed to timescale.v This is done because of the
58// simulation of the few cores in a one joined project.
59//
60// Revision 1.1  2001/08/06 14:44:29  mohor
61// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
62// Include files fixed to contain no path.
63// File names and module names changed ta have a eth_ prologue in the name.
64// File eth_timescale.v is used to define timescale
65// All pin names on the top module are changed to contain _I, _O or _OE at the end.
66// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
67// and Mdo_OE. The bidirectional signal must be created on the top level. This
68// is done due to the ASIC tools.
69//
70// Revision 1.1  2001/07/30 21:23:42  mohor
71// Directory structure changed. Files checked and joind together.
72//
73// Revision 1.1  2001/06/27 21:26:19  mohor
74// Initial release of the RxEthMAC module.
75//
76//
77//
78//
79//
80//
81
82
83`include "timescale.v"
84
85
86module eth_rxcounters (MRxClk, Reset, MRxDV, StateIdle, StateSFD, StateData, StateDrop, StatePreamble, 
87                       MRxDEqD, DlyCrcEn, DlyCrcCnt, Transmitting, MaxFL, r_IFG, HugEn, IFGCounterEq24, 
88                       ByteCntEq0, ByteCntEq1, ByteCntEq2,ByteCntEq3,ByteCntEq4,ByteCntEq5, ByteCntEq6,
89                       ByteCntEq7, ByteCntGreat2, ByteCntSmall7, ByteCntMaxFrame, ByteCntOut
90                      );
91
92parameter Tp = 1;
93
94input         MRxClk;
95input         Reset;
96input         MRxDV;
97input         StateSFD;
98input [1:0]   StateData;
99input         MRxDEqD;
100input         StateIdle;
101input         StateDrop;
102input         DlyCrcEn;
103input         StatePreamble;
104input         Transmitting;
105input         HugEn;
106input [15:0]  MaxFL;
107input         r_IFG;
108
109output        IFGCounterEq24;           // IFG counter reaches 9600 ns (960 ns)
110output [3:0]  DlyCrcCnt;                // Delayed CRC counter
111output        ByteCntEq0;               // Byte counter = 0
112output        ByteCntEq1;               // Byte counter = 1
113output        ByteCntEq2;               // Byte counter = 2 
114output        ByteCntEq3;               // Byte counter = 3 
115output        ByteCntEq4;               // Byte counter = 4 
116output        ByteCntEq5;               // Byte counter = 5 
117output        ByteCntEq6;               // Byte counter = 6
118output        ByteCntEq7;               // Byte counter = 7
119output        ByteCntGreat2;            // Byte counter > 2
120output        ByteCntSmall7;            // Byte counter < 7
121output        ByteCntMaxFrame;          // Byte counter = MaxFL
122output [15:0] ByteCntOut;               // Byte counter
123
124wire          ResetByteCounter;
125wire          IncrementByteCounter;
126wire          ResetIFGCounter;
127wire          IncrementIFGCounter;
128wire          ByteCntMax;
129
130reg   [15:0]  ByteCnt;
131reg   [3:0]   DlyCrcCnt;
132reg   [4:0]   IFGCounter;
133
134wire  [15:0]  ByteCntDelayed;
135
136
137
138assign ResetByteCounter = MRxDV & (StateSFD & MRxDEqD | StateData[0] & ByteCntMaxFrame);
139
140assign IncrementByteCounter = ~ResetByteCounter & MRxDV & 
141                              (StatePreamble | StateSFD | StateIdle & ~Transmitting |
142                               StateData[1] & ~ByteCntMax & ~(DlyCrcEn & |DlyCrcCnt)
143                              );
144
145
146always @ (posedge MRxClk or posedge Reset)
147begin
148  if(Reset)
149    ByteCnt[15:0] <= #Tp 16'h0;
150  else
151    begin
152      if(ResetByteCounter)
153        ByteCnt[15:0] <= #Tp 16'h0;
154      else
155      if(IncrementByteCounter)
156        ByteCnt[15:0] <= #Tp ByteCnt[15:0] + 1'b1;
157     end
158end
159
160assign ByteCntDelayed = ByteCnt + 3'h4;
161assign ByteCntOut = DlyCrcEn? ByteCntDelayed : ByteCnt;
162
163assign ByteCntEq0       = ByteCnt == 16'h0;
164assign ByteCntEq1       = ByteCnt == 16'h1;
165assign ByteCntEq2       = ByteCnt == 16'h2; 
166assign ByteCntEq3       = ByteCnt == 16'h3; 
167assign ByteCntEq4       = ByteCnt == 16'h4; 
168assign ByteCntEq5       = ByteCnt == 16'h5; 
169assign ByteCntEq6       = ByteCnt == 16'h6;
170assign ByteCntEq7       = ByteCnt == 16'h7;
171assign ByteCntGreat2    = ByteCnt >  16'h2;
172assign ByteCntSmall7    = ByteCnt <  16'h7;
173assign ByteCntMax       = ByteCnt == 16'hffff;
174assign ByteCntMaxFrame  = ByteCnt == MaxFL[15:0] & ~HugEn;
175
176
177assign ResetIFGCounter = StateSFD  &  MRxDV & MRxDEqD | StateDrop;
178
179assign IncrementIFGCounter = ~ResetIFGCounter & (StateDrop | StateIdle | StatePreamble | StateSFD) & ~IFGCounterEq24;
180
181always @ (posedge MRxClk or posedge Reset)
182begin
183  if(Reset)
184    IFGCounter[4:0] <= #Tp 5'h0;
185  else
186    begin
187      if(ResetIFGCounter)
188        IFGCounter[4:0] <= #Tp 5'h0;
189      else
190      if(IncrementIFGCounter)
191        IFGCounter[4:0] <= #Tp IFGCounter[4:0] + 1'b1; 
192    end
193end
194
195
196
197assign IFGCounterEq24 = (IFGCounter[4:0] == 5'h18) | r_IFG; // 24*400 = 9600 ns or r_IFG is set to 1
198
199
200always @ (posedge MRxClk or posedge Reset)
201begin
202  if(Reset)
203    DlyCrcCnt[3:0] <= #Tp 4'h0;
204  else
205    begin
206      if(DlyCrcCnt[3:0] == 4'h9)
207        DlyCrcCnt[3:0] <= #Tp 4'h0;
208      else
209      if(DlyCrcEn & StateSFD)
210        DlyCrcCnt[3:0] <= #Tp 4'h1;
211      else
212      if(DlyCrcEn & (|DlyCrcCnt[3:0]))
213        DlyCrcCnt[3:0] <= #Tp DlyCrcCnt[3:0] + 1'b1;
214    end
215end
216
217
218endmodule
Note: See TracBrowser for help on using the repository browser.