]> git.zerfleddert.de Git - raggedstone/blame - ethernet/source/ethernet/eth_txcounters.v
eth_cop
[raggedstone] / ethernet / source / ethernet / eth_txcounters.v
CommitLineData
40a1f26c 1//////////////////////////////////////////////////////////////////////
2//// ////
3//// eth_txcounters.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: eth_txcounters.v,v $
46// Revision 1.1 2007-03-20 17:50:56 sithglan
47// add shit
48//
49// Revision 1.6 2005/02/21 11:25:27 igorm
50// Delayed CRC fixed.
51//
52// Revision 1.5 2002/04/22 14:54:14 mohor
53// FCS should not be included in NibbleMinFl.
54//
55// Revision 1.4 2002/01/23 10:28:16 mohor
56// Link in the header changed.
57//
58// Revision 1.3 2001/10/19 08:43:51 mohor
59// eth_timescale.v changed to timescale.v This is done because of the
60// simulation of the few cores in a one joined project.
61//
62// Revision 1.2 2001/09/11 14:17:00 mohor
63// Few little NCSIM warnings fixed.
64//
65// Revision 1.1 2001/08/06 14:44:29 mohor
66// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
67// Include files fixed to contain no path.
68// File names and module names changed ta have a eth_ prologue in the name.
69// File eth_timescale.v is used to define timescale
70// All pin names on the top module are changed to contain _I, _O or _OE at the end.
71// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
72// and Mdo_OE. The bidirectional signal must be created on the top level. This
73// is done due to the ASIC tools.
74//
75// Revision 1.1 2001/07/30 21:23:42 mohor
76// Directory structure changed. Files checked and joind together.
77//
78// Revision 1.4 2001/06/27 21:27:45 mohor
79// Few typos fixed.
80//
81// Revision 1.2 2001/06/19 10:38:07 mohor
82// Minor changes in header.
83//
84// Revision 1.1 2001/06/19 10:27:57 mohor
85// TxEthMAC initial release.
86//
87//
88//
89
90
91`include "timescale.v"
92
93
94module eth_txcounters (StatePreamble, StateIPG, StateData, StatePAD, StateFCS, StateJam,
95 StateBackOff, StateDefer, StateIdle, StartDefer, StartIPG, StartFCS,
96 StartJam, StartBackoff, TxStartFrm, MTxClk, Reset, MinFL, MaxFL, HugEn,
97 ExDfrEn, PacketFinished_q, DlyCrcEn, StateSFD, ByteCnt, NibCnt,
98 ExcessiveDefer, NibCntEq7, NibCntEq15, MaxFrame, NibbleMinFl, DlyCrcCnt
99 );
100
101parameter Tp = 1;
102
103input MTxClk; // Tx clock
104input Reset; // Reset
105input StatePreamble; // Preamble state
106input StateIPG; // IPG state
107input [1:0] StateData; // Data state
108input StatePAD; // PAD state
109input StateFCS; // FCS state
110input StateJam; // Jam state
111input StateBackOff; // Backoff state
112input StateDefer; // Defer state
113input StateIdle; // Idle state
114input StateSFD; // SFD state
115input StartDefer; // Defer state will be activated in next clock
116input StartIPG; // IPG state will be activated in next clock
117input StartFCS; // FCS state will be activated in next clock
118input StartJam; // Jam state will be activated in next clock
119input StartBackoff; // Backoff state will be activated in next clock
120input TxStartFrm; // Tx start frame
121input [15:0] MinFL; // Minimum frame length (in bytes)
122input [15:0] MaxFL; // Miximum frame length (in bytes)
123input HugEn; // Pakets bigger then MaxFL enabled
124input ExDfrEn; // Excessive deferral enabled
125input PacketFinished_q;
126input DlyCrcEn; // Delayed CRC enabled
127
128output [15:0] ByteCnt; // Byte counter
129output [15:0] NibCnt; // Nibble counter
130output ExcessiveDefer; // Excessive Deferral occuring
131output NibCntEq7; // Nibble counter is equal to 7
132output NibCntEq15; // Nibble counter is equal to 15
133output MaxFrame; // Maximum frame occured
134output NibbleMinFl; // Nibble counter is greater than the minimum frame length
135output [2:0] DlyCrcCnt; // Delayed CRC Count
136
137wire ExcessiveDeferCnt;
138wire ResetNibCnt;
139wire IncrementNibCnt;
140wire ResetByteCnt;
141wire IncrementByteCnt;
142wire ByteCntMax;
143
144reg [15:0] NibCnt;
145reg [15:0] ByteCnt;
146reg [2:0] DlyCrcCnt;
147
148
149
150assign IncrementNibCnt = StateIPG | StatePreamble | (|StateData) | StatePAD
151 | StateFCS | StateJam | StateBackOff | StateDefer & ~ExcessiveDefer & TxStartFrm;
152
153
154assign ResetNibCnt = StateDefer & ExcessiveDefer & ~TxStartFrm | StatePreamble & NibCntEq15
155 | StateJam & NibCntEq7 | StateIdle | StartDefer | StartIPG | StartFCS | StartJam;
156
157// Nibble Counter
158always @ (posedge MTxClk or posedge Reset)
159begin
160 if(Reset)
161 NibCnt <= #Tp 16'h0;
162 else
163 begin
164 if(ResetNibCnt)
165 NibCnt <= #Tp 16'h0;
166 else
167 if(IncrementNibCnt)
168 NibCnt <= #Tp NibCnt + 1'b1;
169 end
170end
171
172
173assign NibCntEq7 = &NibCnt[2:0];
174assign NibCntEq15 = &NibCnt[3:0];
175
176assign NibbleMinFl = NibCnt >= (((MinFL-3'h4)<<1) -1); // FCS should not be included in NibbleMinFl
177
178assign ExcessiveDeferCnt = NibCnt[13:0] == 16'h17b7;
179
180assign ExcessiveDefer = NibCnt[13:0] == 16'h17b7 & ~ExDfrEn; // 6071 nibbles
181
182assign IncrementByteCnt = StateData[1] & ~ByteCntMax
183 | StateBackOff & (&NibCnt[6:0])
184 | (StatePAD | StateFCS) & NibCnt[0] & ~ByteCntMax;
185
186assign ResetByteCnt = StartBackoff | StateIdle & TxStartFrm | PacketFinished_q;
187
188
189// Transmit Byte Counter
190always @ (posedge MTxClk or posedge Reset)
191begin
192 if(Reset)
193 ByteCnt[15:0] <= #Tp 16'h0;
194 else
195 begin
196 if(ResetByteCnt)
197 ByteCnt[15:0] <= #Tp 16'h0;
198 else
199 if(IncrementByteCnt)
200 ByteCnt[15:0] <= #Tp ByteCnt[15:0] + 1'b1;
201 end
202end
203
204
205assign MaxFrame = ByteCnt[15:0] == MaxFL[15:0] & ~HugEn;
206
207assign ByteCntMax = &ByteCnt[15:0];
208
209
210// Delayed CRC counter
211always @ (posedge MTxClk or posedge Reset)
212begin
213 if(Reset)
214 DlyCrcCnt <= #Tp 3'h0;
215 else
216 begin
217 if(StateData[1] & DlyCrcCnt == 3'h4 | StartJam | PacketFinished_q)
218 DlyCrcCnt <= #Tp 3'h0;
219 else
220 if(DlyCrcEn & (StateSFD | StateData[1] & (|DlyCrcCnt[2:0])))
221 DlyCrcCnt <= #Tp DlyCrcCnt + 1'b1;
222 end
223end
224
225
226
227endmodule
Impressum, Datenschutz