1 //////////////////////////////////////////////////////////////////////
3 //// eth_macstatus.v ////
5 //// This file is part of the Ethernet IP core project ////
6 //// http://www.opencores.org/projects/ethmac/ ////
9 //// - Igor Mohor (igorM@opencores.org) ////
11 //// All additional information is available in the Readme.txt ////
14 //////////////////////////////////////////////////////////////////////
16 //// Copyright (C) 2001, 2002 Authors ////
18 //// This source file may be used and distributed without ////
19 //// restriction provided that this copyright statement is not ////
20 //// removed from the file and that any derivative work contains ////
21 //// the original copyright notice and the associated disclaimer. ////
23 //// This source file is free software; you can redistribute it ////
24 //// and/or modify it under the terms of the GNU Lesser General ////
25 //// Public License as published by the Free Software Foundation; ////
26 //// either version 2.1 of the License, or (at your option) any ////
27 //// later version. ////
29 //// This source is distributed in the hope that it will be ////
30 //// useful, but WITHOUT ANY WARRANTY; without even the implied ////
31 //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
32 //// PURPOSE. See the GNU Lesser General Public License for more ////
35 //// You should have received a copy of the GNU Lesser General ////
36 //// Public License along with this source; if not, download it ////
37 //// from http://www.opencores.org/lgpl.shtml ////
39 //////////////////////////////////////////////////////////////////////
41 // CVS Revision History
43 // $Log: eth_macstatus.v,v $
44 // Revision 1.17 2005/03/21 20:07:18 igorm
45 // Some small fixes + some troubles fixed.
47 // Revision 1.16 2005/02/21 10:42:11 igorm
48 // Defer indication fixed.
50 // Revision 1.15 2003/01/30 13:28:19 tadejm
51 // Defer indication changed.
53 // Revision 1.14 2002/11/22 01:57:06 mohor
54 // Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
57 // Revision 1.13 2002/11/13 22:30:58 tadejm
58 // Late collision is reported only when not in the full duplex.
59 // Sample is taken (for status) as soon as MRxDV is not valid (regardless
60 // of the received byte cnt).
62 // Revision 1.12 2002/09/12 14:50:16 mohor
63 // CarrierSenseLost bug fixed when operating in full duplex mode.
65 // Revision 1.11 2002/09/04 18:38:03 mohor
66 // CarrierSenseLost status is not set when working in loopback mode.
68 // Revision 1.10 2002/07/25 18:17:46 mohor
69 // InvalidSymbol generation changed.
71 // Revision 1.9 2002/04/22 13:51:44 mohor
72 // Short frame and ReceivedLengthOK were not detected correctly.
74 // Revision 1.8 2002/02/18 10:40:17 mohor
77 // Revision 1.7 2002/02/15 17:07:39 mohor
78 // Status was not written correctly when frames were discarted because of
81 // Revision 1.6 2002/02/11 09:18:21 mohor
82 // Tx status is written back to the BD.
84 // Revision 1.5 2002/02/08 16:21:54 mohor
85 // Rx status is written back to the BD.
87 // Revision 1.4 2002/01/23 10:28:16 mohor
88 // Link in the header changed.
90 // Revision 1.3 2001/10/19 08:43:51 mohor
91 // eth_timescale.v changed to timescale.v This is done because of the
92 // simulation of the few cores in a one joined project.
94 // Revision 1.2 2001/09/11 14:17:00 mohor
95 // Few little NCSIM warnings fixed.
97 // Revision 1.1 2001/08/06 14:44:29 mohor
98 // A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
99 // Include files fixed to contain no path.
100 // File names and module names changed ta have a eth_ prologue in the name.
101 // File eth_timescale.v is used to define timescale
102 // All pin names on the top module are changed to contain _I, _O or _OE at the end.
103 // Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
104 // and Mdo_OE. The bidirectional signal must be created on the top level. This
105 // is done due to the ASIC tools.
107 // Revision 1.1 2001/07/30 21:23:42 mohor
108 // Directory structure changed. Files checked and joind together.
115 `include "timescale.v"
118 module eth_macstatus(
119 MRxClk
, Reset
, ReceivedLengthOK
, ReceiveEnd
, ReceivedPacketGood
, RxCrcError
,
120 MRxErr
, MRxDV
, RxStateSFD
, RxStateData
, RxStatePreamble
, RxStateIdle
, Transmitting
,
121 RxByteCnt
, RxByteCntEq0
, RxByteCntGreat2
, RxByteCntMaxFrame
,
122 InvalidSymbol
, MRxD
, LatchedCrcError
, Collision
, CollValid
, RxLateCollision
,
123 r_RecSmall
, r_MinFL
, r_MaxFL
, ShortFrame
, DribbleNibble
, ReceivedPacketTooBig
, r_HugEn
,
124 LoadRxStatus
, StartTxDone
, StartTxAbort
, RetryCnt
, RetryCntLatched
, MTxClk
, MaxCollisionOccured
,
125 RetryLimit
, LateCollision
, LateCollLatched
, DeferIndication
, DeferLatched
, RstDeferLatched
, TxStartFrm
,
126 StatePreamble
, StateData
, CarrierSense
, CarrierSenseLost
, TxUsedData
, LatchedMRxErr
, Loopback
,
142 input [1:0] RxStateData
;
143 input RxStatePreamble
;
146 input [15:0] RxByteCnt
;
148 input RxByteCntGreat2
;
149 input RxByteCntMaxFrame
;
152 input [5:0] CollValid
;
154 input [15:0] r_MinFL
;
155 input [15:0] r_MaxFL
;
159 input [3:0] RetryCnt
;
161 input MaxCollisionOccured
;
163 input DeferIndication
;
166 input [1:0] StateData
;
173 output ReceivedLengthOK
;
175 output ReceivedPacketGood
;
176 output InvalidSymbol
;
177 output LatchedCrcError
;
178 output RxLateCollision
;
180 output DribbleNibble
;
181 output ReceivedPacketTooBig
;
183 output [3:0] RetryCntLatched
;
185 output LateCollLatched
;
187 input RstDeferLatched
;
188 output CarrierSenseLost
;
189 output LatchedMRxErr
;
198 reg [3:0] RetryCntLatched
;
202 reg CarrierSenseLost
;
205 wire SetInvalidSymbol
; // Invalid symbol was received during reception in 100Mbps
208 always @ (posedge MRxClk
or posedge Reset
)
211 LatchedCrcError
<=#Tp
1'b0;
214 LatchedCrcError
<=#Tp
1'b0;
217 LatchedCrcError
<=#Tp RxCrcError
& ~RxByteCntEq0
;
222 always @ (posedge MRxClk
or posedge Reset
)
225 LatchedMRxErr
<=#Tp
1'b0;
227 if(MRxErr
& MRxDV
& (RxStatePreamble | RxStateSFD |
(|RxStateData
) | RxStateIdle
& ~Transmitting
))
228 LatchedMRxErr
<=#Tp
1'b1;
230 LatchedMRxErr
<=#Tp
1'b0;
234 // ReceivedPacketGood
235 assign ReceivedPacketGood
= ~LatchedCrcError
;
239 assign ReceivedLengthOK
= RxByteCnt
[15:0] >= r_MinFL
[15:0] & RxByteCnt
[15:0] <= r_MaxFL
[15:0];
245 // Time to take a sample
246 //assign TakeSample = |RxStateData & ~MRxDV & RxByteCntGreat2 |
247 assign TakeSample
= (|RxStateData
) & (~MRxDV
) |
248 RxStateData
[0] & MRxDV
& RxByteCntMaxFrame
;
252 always @ (posedge MRxClk
or posedge Reset
)
255 LoadRxStatus
<=#Tp
1'b0;
257 LoadRxStatus
<=#Tp TakeSample
;
263 always @ (posedge MRxClk
or posedge Reset
)
266 ReceiveEnd
<=#Tp
1'b0;
268 ReceiveEnd
<=#Tp LoadRxStatus
;
272 // Invalid Symbol received during 100Mbps mode
273 assign SetInvalidSymbol
= MRxDV
& MRxErr
& MRxD
[3:0] == 4'he
;
277 always @ (posedge MRxClk
or posedge Reset
)
280 InvalidSymbol
<=#Tp
1'b0;
282 if(LoadRxStatus
& ~SetInvalidSymbol
)
283 InvalidSymbol
<=#Tp
1'b0;
286 InvalidSymbol
<=#Tp
1'b1;
295 always @ (posedge MRxClk
or posedge Reset
)
298 RxLateCollision
<=#Tp
1'b0;
301 RxLateCollision
<=#Tp
1'b0;
303 if(Collision
& (~r_FullD
) & (~RxColWindow | r_RecSmall
))
304 RxLateCollision
<=#Tp
1'b1;
308 always @ (posedge MRxClk
or posedge Reset
)
311 RxColWindow
<=#Tp
1'b1;
313 if(~Collision
& RxByteCnt
[5:0] == CollValid
[5:0] & RxStateData
[1])
314 RxColWindow
<=#Tp
1'b0;
317 RxColWindow
<=#Tp
1'b1;
323 always @ (posedge MRxClk
or posedge Reset
)
326 ShortFrame
<=#Tp
1'b0;
329 ShortFrame
<=#Tp
1'b0;
332 ShortFrame
<=#Tp RxByteCnt
[15:0] < r_MinFL
[15:0];
338 always @ (posedge MRxClk
or posedge Reset
)
341 DribbleNibble
<=#Tp
1'b0;
344 DribbleNibble
<=#Tp
1'b0;
346 if(~MRxDV
& RxStateData
[1])
347 DribbleNibble
<=#Tp
1'b1;
351 reg ReceivedPacketTooBig
;
352 always @ (posedge MRxClk
or posedge Reset
)
355 ReceivedPacketTooBig
<=#Tp
1'b0;
358 ReceivedPacketTooBig
<=#Tp
1'b0;
361 ReceivedPacketTooBig
<=#Tp
~r_HugEn
& RxByteCnt
[15:0] > r_MaxFL
[15:0];
366 // Latched Retry counter for tx status
367 always @ (posedge MTxClk
or posedge Reset
)
370 RetryCntLatched
<=#Tp
4'h0
;
372 if(StartTxDone | StartTxAbort
)
373 RetryCntLatched
<=#Tp RetryCnt
;
377 // Latched Retransmission limit
378 always @ (posedge MTxClk
or posedge Reset
)
381 RetryLimit
<=#Tp
1'h0
;
383 if(StartTxDone | StartTxAbort
)
384 RetryLimit
<=#Tp MaxCollisionOccured
;
388 // Latched Late Collision
389 always @ (posedge MTxClk
or posedge Reset
)
392 LateCollLatched
<=#Tp
1'b0;
394 if(StartTxDone | StartTxAbort
)
395 LateCollLatched
<=#Tp LateCollision
;
400 // Latched Defer state
401 always @ (posedge MTxClk
or posedge Reset
)
404 DeferLatched
<=#Tp
1'b0;
407 DeferLatched
<=#Tp
1'b1;
410 DeferLatched
<=#Tp
1'b0;
415 always @ (posedge MTxClk
or posedge Reset
)
418 CarrierSenseLost
<=#Tp
1'b0;
420 if((StatePreamble |
(|StateData
)) & ~CarrierSense
& ~Loopback
& ~Collision
& ~r_FullD
)
421 CarrierSenseLost
<=#Tp
1'b1;
424 CarrierSenseLost
<=#Tp
1'b0;