1 //////////////////////////////////////////////////////////////////////
3 //// eth_receivecontrol.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 avaliable in the Readme.txt ////
14 //////////////////////////////////////////////////////////////////////
16 //// Copyright (C) 2001 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_receivecontrol.v,v $
44 // Revision 1.1 2007-03-20 17:50:56 sithglan
47 // Revision 1.5 2003/01/22 13:49:26 tadejm
48 // When control packets were received, they were ignored in some cases.
50 // Revision 1.4 2002/11/22 01:57:06 mohor
51 // Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
54 // Revision 1.3 2002/01/23 10:28:16 mohor
55 // Link in the header changed.
57 // Revision 1.2 2001/10/19 08:43:51 mohor
58 // eth_timescale.v changed to timescale.v This is done because of the
59 // simulation of the few cores in a one joined project.
61 // Revision 1.1 2001/08/06 14:44:29 mohor
62 // A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
63 // Include files fixed to contain no path.
64 // File names and module names changed ta have a eth_ prologue in the name.
65 // File eth_timescale.v is used to define timescale
66 // All pin names on the top module are changed to contain _I, _O or _OE at the end.
67 // Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
68 // and Mdo_OE. The bidirectional signal must be created on the top level. This
69 // is done due to the ASIC tools.
71 // Revision 1.1 2001/07/30 21:23:42 mohor
72 // Directory structure changed. Files checked and joind together.
74 // Revision 1.1 2001/07/03 12:51:54 mohor
75 // Initial release of the MAC Control module.
83 `include "timescale.v"
86 module eth_receivecontrol (MTxClk, MRxClk, TxReset, RxReset, RxData, RxValid, RxStartFrm,
87 RxEndFrm, RxFlow, ReceiveEnd, MAC, DlyCrcEn, TxDoneIn,
88 TxAbortIn, TxStartFrmOut, ReceivedLengthOK, ReceivedPacketGood,
89 TxUsedDataOutDetected, Pause, ReceivedPauseFrm, AddressOK,
90 RxStatusWriteLatched_sync2, r_PassAll, SetPauseTimer
111 input ReceivedLengthOK;
112 input ReceivedPacketGood;
113 input TxUsedDataOutDetected;
114 input RxStatusWriteLatched_sync2;
118 output ReceivedPauseFrm;
120 output SetPauseTimer;
124 reg AddressOK; // Multicast or unicast address detected
125 reg TypeLengthOK; // Type/Length field contains 0x8808
126 reg DetectionWindow; // Detection of the PAUSE frame is possible within this window
127 reg OpCodeOK; // PAUSE opcode detected (0x0001)
130 reg [15:0] AssembledTimerValue;
131 reg [15:0] LatchedTimerValue;
132 reg ReceivedPauseFrm;
133 reg ReceivedPauseFrmWAddr;
134 reg PauseTimerEq0_sync1;
135 reg PauseTimerEq0_sync2;
136 reg [15:0] PauseTimer;
140 wire [47:0] ReservedMulticast; // 0x0180C2000001
141 wire [15:0] TypeLength; // 0x8808
142 wire ResetByteCnt; //
143 wire IncrementByteCnt; //
144 wire ByteCntEq0; // ByteCnt = 0
145 wire ByteCntEq1; // ByteCnt = 1
146 wire ByteCntEq2; // ByteCnt = 2
147 wire ByteCntEq3; // ByteCnt = 3
148 wire ByteCntEq4; // ByteCnt = 4
149 wire ByteCntEq5; // ByteCnt = 5
150 wire ByteCntEq12; // ByteCnt = 12
151 wire ByteCntEq13; // ByteCnt = 13
152 wire ByteCntEq14; // ByteCnt = 14
153 wire ByteCntEq15; // ByteCnt = 15
154 wire ByteCntEq16; // ByteCnt = 16
155 wire ByteCntEq17; // ByteCnt = 17
156 wire ByteCntEq18; // ByteCnt = 18
157 wire DecrementPauseTimer; //
158 wire PauseTimerEq0; //
159 wire ResetSlotTimer; //
160 wire IncrementSlotTimer; //
161 wire SlotFinished; //
165 // Reserved multicast address and Type/Length for PAUSE control
166 assign ReservedMulticast = 48'h0180C2000001;
167 assign TypeLength = 16'h8808;
170 // Address Detection (Multicast or unicast)
171 always @ (posedge MRxClk or posedge RxReset)
174 AddressOK <= #Tp 1'b0;
176 if(DetectionWindow & ByteCntEq0)
177 AddressOK <= #Tp RxData[7:0] == ReservedMulticast[47:40] | RxData[7:0] == MAC[47:40];
179 if(DetectionWindow & ByteCntEq1)
180 AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[39:32] | RxData[7:0] == MAC[39:32]) & AddressOK;
182 if(DetectionWindow & ByteCntEq2)
183 AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[31:24] | RxData[7:0] == MAC[31:24]) & AddressOK;
185 if(DetectionWindow & ByteCntEq3)
186 AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[23:16] | RxData[7:0] == MAC[23:16]) & AddressOK;
188 if(DetectionWindow & ByteCntEq4)
189 AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[15:8] | RxData[7:0] == MAC[15:8]) & AddressOK;
191 if(DetectionWindow & ByteCntEq5)
192 AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[7:0] | RxData[7:0] == MAC[7:0]) & AddressOK;
195 AddressOK <= #Tp 1'b0;
200 // TypeLengthOK (Type/Length Control frame detected)
201 always @ (posedge MRxClk or posedge RxReset )
204 TypeLengthOK <= #Tp 1'b0;
206 if(DetectionWindow & ByteCntEq12)
207 TypeLengthOK <= #Tp ByteCntEq12 & (RxData[7:0] == TypeLength[15:8]);
209 if(DetectionWindow & ByteCntEq13)
210 TypeLengthOK <= #Tp ByteCntEq13 & (RxData[7:0] == TypeLength[7:0]) & TypeLengthOK;
213 TypeLengthOK <= #Tp 1'b0;
218 // Latch Control Frame Opcode
219 always @ (posedge MRxClk or posedge RxReset )
222 OpCodeOK <= #Tp 1'b0;
225 OpCodeOK <= #Tp 1'b0;
228 if(DetectionWindow & ByteCntEq14)
229 OpCodeOK <= #Tp ByteCntEq14 & RxData[7:0] == 8'h00;
231 if(DetectionWindow & ByteCntEq15)
232 OpCodeOK <= #Tp ByteCntEq15 & RxData[7:0] == 8'h01 & OpCodeOK;
237 // ReceivedPauseFrmWAddr (+Address Check)
238 always @ (posedge MRxClk or posedge RxReset )
241 ReceivedPauseFrmWAddr <= #Tp 1'b0;
244 ReceivedPauseFrmWAddr <= #Tp 1'b0;
246 if(ByteCntEq16 & TypeLengthOK & OpCodeOK & AddressOK)
247 ReceivedPauseFrmWAddr <= #Tp 1'b1;
252 // Assembling 16-bit timer value from two 8-bit data
253 always @ (posedge MRxClk or posedge RxReset )
256 AssembledTimerValue[15:0] <= #Tp 16'h0;
259 AssembledTimerValue[15:0] <= #Tp 16'h0;
262 if(DetectionWindow & ByteCntEq16)
263 AssembledTimerValue[15:8] <= #Tp RxData[7:0];
264 if(DetectionWindow & ByteCntEq17)
265 AssembledTimerValue[7:0] <= #Tp RxData[7:0];
270 // Detection window (while PAUSE detection is possible)
271 always @ (posedge MRxClk or posedge RxReset )
274 DetectionWindow <= #Tp 1'b1;
277 DetectionWindow <= #Tp 1'b0;
280 DetectionWindow <= #Tp 1'b1;
285 // Latching Timer Value
286 always @ (posedge MRxClk or posedge RxReset )
289 LatchedTimerValue[15:0] <= #Tp 16'h0;
291 if(DetectionWindow & ReceivedPauseFrmWAddr & ByteCntEq18)
292 LatchedTimerValue[15:0] <= #Tp AssembledTimerValue[15:0];
295 LatchedTimerValue[15:0] <= #Tp 16'h0;
300 // Delayed CEC counter
301 always @ (posedge MRxClk or posedge RxReset)
304 DlyCrcCnt <= #Tp 3'h0;
306 if(RxValid & RxEndFrm)
307 DlyCrcCnt <= #Tp 3'h0;
309 if(RxValid & ~RxEndFrm & ~DlyCrcCnt[2])
310 DlyCrcCnt <= #Tp DlyCrcCnt + 1'b1;
314 assign ResetByteCnt = RxEndFrm;
315 assign IncrementByteCnt = RxValid & DetectionWindow & ~ByteCntEq18 & (~DlyCrcEn | DlyCrcEn & DlyCrcCnt[2]);
319 always @ (posedge MRxClk or posedge RxReset)
322 ByteCnt[4:0] <= #Tp 5'h0;
325 ByteCnt[4:0] <= #Tp 5'h0;
328 ByteCnt[4:0] <= #Tp ByteCnt[4:0] + 1'b1;
332 assign ByteCntEq0 = RxValid & ByteCnt[4:0] == 5'h0;
333 assign ByteCntEq1 = RxValid & ByteCnt[4:0] == 5'h1;
334 assign ByteCntEq2 = RxValid & ByteCnt[4:0] == 5'h2;
335 assign ByteCntEq3 = RxValid & ByteCnt[4:0] == 5'h3;
336 assign ByteCntEq4 = RxValid & ByteCnt[4:0] == 5'h4;
337 assign ByteCntEq5 = RxValid & ByteCnt[4:0] == 5'h5;
338 assign ByteCntEq12 = RxValid & ByteCnt[4:0] == 5'h0C;
339 assign ByteCntEq13 = RxValid & ByteCnt[4:0] == 5'h0D;
340 assign ByteCntEq14 = RxValid & ByteCnt[4:0] == 5'h0E;
341 assign ByteCntEq15 = RxValid & ByteCnt[4:0] == 5'h0F;
342 assign ByteCntEq16 = RxValid & ByteCnt[4:0] == 5'h10;
343 assign ByteCntEq17 = RxValid & ByteCnt[4:0] == 5'h11;
344 assign ByteCntEq18 = RxValid & ByteCnt[4:0] == 5'h12 & DetectionWindow;
347 assign SetPauseTimer = ReceiveEnd & ReceivedPauseFrmWAddr & ReceivedPacketGood & ReceivedLengthOK & RxFlow;
348 assign DecrementPauseTimer = SlotFinished & |PauseTimer;
352 always @ (posedge MRxClk or posedge RxReset)
355 PauseTimer[15:0] <= #Tp 16'h0;
358 PauseTimer[15:0] <= #Tp LatchedTimerValue[15:0];
360 if(DecrementPauseTimer)
361 PauseTimer[15:0] <= #Tp PauseTimer[15:0] - 1'b1;
364 assign PauseTimerEq0 = ~(|PauseTimer[15:0]);
368 // Synchronization of the pause timer
369 always @ (posedge MTxClk or posedge TxReset)
373 PauseTimerEq0_sync1 <= #Tp 1'b1;
374 PauseTimerEq0_sync2 <= #Tp 1'b1;
378 PauseTimerEq0_sync1 <= #Tp PauseTimerEq0;
379 PauseTimerEq0_sync2 <= #Tp PauseTimerEq0_sync1;
384 // Pause signal generation
385 always @ (posedge MTxClk or posedge TxReset)
390 if((TxDoneIn | TxAbortIn | ~TxUsedDataOutDetected) & ~TxStartFrmOut)
391 Pause <= #Tp RxFlow & ~PauseTimerEq0_sync2;
395 // Divider2 is used for incrementing the Slot timer every other clock
396 always @ (posedge MRxClk or posedge RxReset)
399 Divider2 <= #Tp 1'b0;
401 if(|PauseTimer[15:0] & RxFlow)
402 Divider2 <= #Tp ~Divider2;
404 Divider2 <= #Tp 1'b0;
408 assign ResetSlotTimer = RxReset;
409 assign IncrementSlotTimer = Pause & RxFlow & Divider2;
413 always @ (posedge MRxClk or posedge RxReset)
416 SlotTimer[5:0] <= #Tp 6'h0;
419 SlotTimer[5:0] <= #Tp 6'h0;
421 if(IncrementSlotTimer)
422 SlotTimer[5:0] <= #Tp SlotTimer[5:0] + 1'b1;
426 assign SlotFinished = &SlotTimer[5:0] & IncrementSlotTimer; // Slot is 512 bits (64 bytes)
430 // Pause Frame received
431 always @ (posedge MRxClk or posedge RxReset)
434 ReceivedPauseFrm <=#Tp 1'b0;
436 if(RxStatusWriteLatched_sync2 & r_PassAll | ReceivedPauseFrm & (~r_PassAll))
437 ReceivedPauseFrm <=#Tp 1'b0;
439 if(ByteCntEq16 & TypeLengthOK & OpCodeOK)
440 ReceivedPauseFrm <=#Tp 1'b1;