]> git.zerfleddert.de Git - raggedstone/blame - ethernet/source/ethernet/eth_receivecontrol.v
clock
[raggedstone] / ethernet / source / ethernet / eth_receivecontrol.v
CommitLineData
40a1f26c 1//////////////////////////////////////////////////////////////////////
2//// ////
3//// eth_receivecontrol.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//// ////
11//// All additional information is avaliable in the Readme.txt ////
12//// file. ////
13//// ////
14//////////////////////////////////////////////////////////////////////
15//// ////
16//// Copyright (C) 2001 Authors ////
17//// ////
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. ////
22//// ////
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. ////
28//// ////
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 ////
33//// details. ////
34//// ////
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 ////
38//// ////
39//////////////////////////////////////////////////////////////////////
40//
41// CVS Revision History
42//
43// $Log: eth_receivecontrol.v,v $
44// Revision 1.1 2007-03-20 17:50:56 sithglan
45// add shit
46//
47// Revision 1.5 2003/01/22 13:49:26 tadejm
48// When control packets were received, they were ignored in some cases.
49//
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
52// synchronized.
53//
54// Revision 1.3 2002/01/23 10:28:16 mohor
55// Link in the header changed.
56//
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.
60//
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.
70//
71// Revision 1.1 2001/07/30 21:23:42 mohor
72// Directory structure changed. Files checked and joind together.
73//
74// Revision 1.1 2001/07/03 12:51:54 mohor
75// Initial release of the MAC Control module.
76//
77//
78//
79//
80//
81
82
83`include "timescale.v"
84
85
86module 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
91 );
92
93parameter Tp = 1;
94
95
96input MTxClk;
97input MRxClk;
98input TxReset;
99input RxReset;
100input [7:0] RxData;
101input RxValid;
102input RxStartFrm;
103input RxEndFrm;
104input RxFlow;
105input ReceiveEnd;
106input [47:0]MAC;
107input DlyCrcEn;
108input TxDoneIn;
109input TxAbortIn;
110input TxStartFrmOut;
111input ReceivedLengthOK;
112input ReceivedPacketGood;
113input TxUsedDataOutDetected;
114input RxStatusWriteLatched_sync2;
115input r_PassAll;
116
117output Pause;
118output ReceivedPauseFrm;
119output AddressOK;
120output SetPauseTimer;
121
122
123reg Pause;
124reg AddressOK; // Multicast or unicast address detected
125reg TypeLengthOK; // Type/Length field contains 0x8808
126reg DetectionWindow; // Detection of the PAUSE frame is possible within this window
127reg OpCodeOK; // PAUSE opcode detected (0x0001)
128reg [2:0] DlyCrcCnt;
129reg [4:0] ByteCnt;
130reg [15:0] AssembledTimerValue;
131reg [15:0] LatchedTimerValue;
132reg ReceivedPauseFrm;
133reg ReceivedPauseFrmWAddr;
134reg PauseTimerEq0_sync1;
135reg PauseTimerEq0_sync2;
136reg [15:0] PauseTimer;
137reg Divider2;
138reg [5:0] SlotTimer;
139
140wire [47:0] ReservedMulticast; // 0x0180C2000001
141wire [15:0] TypeLength; // 0x8808
142wire ResetByteCnt; //
143wire IncrementByteCnt; //
144wire ByteCntEq0; // ByteCnt = 0
145wire ByteCntEq1; // ByteCnt = 1
146wire ByteCntEq2; // ByteCnt = 2
147wire ByteCntEq3; // ByteCnt = 3
148wire ByteCntEq4; // ByteCnt = 4
149wire ByteCntEq5; // ByteCnt = 5
150wire ByteCntEq12; // ByteCnt = 12
151wire ByteCntEq13; // ByteCnt = 13
152wire ByteCntEq14; // ByteCnt = 14
153wire ByteCntEq15; // ByteCnt = 15
154wire ByteCntEq16; // ByteCnt = 16
155wire ByteCntEq17; // ByteCnt = 17
156wire ByteCntEq18; // ByteCnt = 18
157wire DecrementPauseTimer; //
158wire PauseTimerEq0; //
159wire ResetSlotTimer; //
160wire IncrementSlotTimer; //
161wire SlotFinished; //
162
163
164
165// Reserved multicast address and Type/Length for PAUSE control
166assign ReservedMulticast = 48'h0180C2000001;
167assign TypeLength = 16'h8808;
168
169
170// Address Detection (Multicast or unicast)
171always @ (posedge MRxClk or posedge RxReset)
172begin
173 if(RxReset)
174 AddressOK <= #Tp 1'b0;
175 else
176 if(DetectionWindow & ByteCntEq0)
177 AddressOK <= #Tp RxData[7:0] == ReservedMulticast[47:40] | RxData[7:0] == MAC[47:40];
178 else
179 if(DetectionWindow & ByteCntEq1)
180 AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[39:32] | RxData[7:0] == MAC[39:32]) & AddressOK;
181 else
182 if(DetectionWindow & ByteCntEq2)
183 AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[31:24] | RxData[7:0] == MAC[31:24]) & AddressOK;
184 else
185 if(DetectionWindow & ByteCntEq3)
186 AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[23:16] | RxData[7:0] == MAC[23:16]) & AddressOK;
187 else
188 if(DetectionWindow & ByteCntEq4)
189 AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[15:8] | RxData[7:0] == MAC[15:8]) & AddressOK;
190 else
191 if(DetectionWindow & ByteCntEq5)
192 AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[7:0] | RxData[7:0] == MAC[7:0]) & AddressOK;
193 else
194 if(ReceiveEnd)
195 AddressOK <= #Tp 1'b0;
196end
197
198
199
200// TypeLengthOK (Type/Length Control frame detected)
201always @ (posedge MRxClk or posedge RxReset )
202begin
203 if(RxReset)
204 TypeLengthOK <= #Tp 1'b0;
205 else
206 if(DetectionWindow & ByteCntEq12)
207 TypeLengthOK <= #Tp ByteCntEq12 & (RxData[7:0] == TypeLength[15:8]);
208 else
209 if(DetectionWindow & ByteCntEq13)
210 TypeLengthOK <= #Tp ByteCntEq13 & (RxData[7:0] == TypeLength[7:0]) & TypeLengthOK;
211 else
212 if(ReceiveEnd)
213 TypeLengthOK <= #Tp 1'b0;
214end
215
216
217
218// Latch Control Frame Opcode
219always @ (posedge MRxClk or posedge RxReset )
220begin
221 if(RxReset)
222 OpCodeOK <= #Tp 1'b0;
223 else
224 if(ByteCntEq16)
225 OpCodeOK <= #Tp 1'b0;
226 else
227 begin
228 if(DetectionWindow & ByteCntEq14)
229 OpCodeOK <= #Tp ByteCntEq14 & RxData[7:0] == 8'h00;
230
231 if(DetectionWindow & ByteCntEq15)
232 OpCodeOK <= #Tp ByteCntEq15 & RxData[7:0] == 8'h01 & OpCodeOK;
233 end
234end
235
236
237// ReceivedPauseFrmWAddr (+Address Check)
238always @ (posedge MRxClk or posedge RxReset )
239begin
240 if(RxReset)
241 ReceivedPauseFrmWAddr <= #Tp 1'b0;
242 else
243 if(ReceiveEnd)
244 ReceivedPauseFrmWAddr <= #Tp 1'b0;
245 else
246 if(ByteCntEq16 & TypeLengthOK & OpCodeOK & AddressOK)
247 ReceivedPauseFrmWAddr <= #Tp 1'b1;
248end
249
250
251
252// Assembling 16-bit timer value from two 8-bit data
253always @ (posedge MRxClk or posedge RxReset )
254begin
255 if(RxReset)
256 AssembledTimerValue[15:0] <= #Tp 16'h0;
257 else
258 if(RxStartFrm)
259 AssembledTimerValue[15:0] <= #Tp 16'h0;
260 else
261 begin
262 if(DetectionWindow & ByteCntEq16)
263 AssembledTimerValue[15:8] <= #Tp RxData[7:0];
264 if(DetectionWindow & ByteCntEq17)
265 AssembledTimerValue[7:0] <= #Tp RxData[7:0];
266 end
267end
268
269
270// Detection window (while PAUSE detection is possible)
271always @ (posedge MRxClk or posedge RxReset )
272begin
273 if(RxReset)
274 DetectionWindow <= #Tp 1'b1;
275 else
276 if(ByteCntEq18)
277 DetectionWindow <= #Tp 1'b0;
278 else
279 if(ReceiveEnd)
280 DetectionWindow <= #Tp 1'b1;
281end
282
283
284
285// Latching Timer Value
286always @ (posedge MRxClk or posedge RxReset )
287begin
288 if(RxReset)
289 LatchedTimerValue[15:0] <= #Tp 16'h0;
290 else
291 if(DetectionWindow & ReceivedPauseFrmWAddr & ByteCntEq18)
292 LatchedTimerValue[15:0] <= #Tp AssembledTimerValue[15:0];
293 else
294 if(ReceiveEnd)
295 LatchedTimerValue[15:0] <= #Tp 16'h0;
296end
297
298
299
300// Delayed CEC counter
301always @ (posedge MRxClk or posedge RxReset)
302begin
303 if(RxReset)
304 DlyCrcCnt <= #Tp 3'h0;
305 else
306 if(RxValid & RxEndFrm)
307 DlyCrcCnt <= #Tp 3'h0;
308 else
309 if(RxValid & ~RxEndFrm & ~DlyCrcCnt[2])
310 DlyCrcCnt <= #Tp DlyCrcCnt + 1'b1;
311end
312
313
314assign ResetByteCnt = RxEndFrm;
315assign IncrementByteCnt = RxValid & DetectionWindow & ~ByteCntEq18 & (~DlyCrcEn | DlyCrcEn & DlyCrcCnt[2]);
316
317
318// Byte counter
319always @ (posedge MRxClk or posedge RxReset)
320begin
321 if(RxReset)
322 ByteCnt[4:0] <= #Tp 5'h0;
323 else
324 if(ResetByteCnt)
325 ByteCnt[4:0] <= #Tp 5'h0;
326 else
327 if(IncrementByteCnt)
328 ByteCnt[4:0] <= #Tp ByteCnt[4:0] + 1'b1;
329end
330
331
332assign ByteCntEq0 = RxValid & ByteCnt[4:0] == 5'h0;
333assign ByteCntEq1 = RxValid & ByteCnt[4:0] == 5'h1;
334assign ByteCntEq2 = RxValid & ByteCnt[4:0] == 5'h2;
335assign ByteCntEq3 = RxValid & ByteCnt[4:0] == 5'h3;
336assign ByteCntEq4 = RxValid & ByteCnt[4:0] == 5'h4;
337assign ByteCntEq5 = RxValid & ByteCnt[4:0] == 5'h5;
338assign ByteCntEq12 = RxValid & ByteCnt[4:0] == 5'h0C;
339assign ByteCntEq13 = RxValid & ByteCnt[4:0] == 5'h0D;
340assign ByteCntEq14 = RxValid & ByteCnt[4:0] == 5'h0E;
341assign ByteCntEq15 = RxValid & ByteCnt[4:0] == 5'h0F;
342assign ByteCntEq16 = RxValid & ByteCnt[4:0] == 5'h10;
343assign ByteCntEq17 = RxValid & ByteCnt[4:0] == 5'h11;
344assign ByteCntEq18 = RxValid & ByteCnt[4:0] == 5'h12 & DetectionWindow;
345
346
347assign SetPauseTimer = ReceiveEnd & ReceivedPauseFrmWAddr & ReceivedPacketGood & ReceivedLengthOK & RxFlow;
348assign DecrementPauseTimer = SlotFinished & |PauseTimer;
349
350
351// PauseTimer[15:0]
352always @ (posedge MRxClk or posedge RxReset)
353begin
354 if(RxReset)
355 PauseTimer[15:0] <= #Tp 16'h0;
356 else
357 if(SetPauseTimer)
358 PauseTimer[15:0] <= #Tp LatchedTimerValue[15:0];
359 else
360 if(DecrementPauseTimer)
361 PauseTimer[15:0] <= #Tp PauseTimer[15:0] - 1'b1;
362end
363
364assign PauseTimerEq0 = ~(|PauseTimer[15:0]);
365
366
367
368// Synchronization of the pause timer
369always @ (posedge MTxClk or posedge TxReset)
370begin
371 if(TxReset)
372 begin
373 PauseTimerEq0_sync1 <= #Tp 1'b1;
374 PauseTimerEq0_sync2 <= #Tp 1'b1;
375 end
376 else
377 begin
378 PauseTimerEq0_sync1 <= #Tp PauseTimerEq0;
379 PauseTimerEq0_sync2 <= #Tp PauseTimerEq0_sync1;
380 end
381end
382
383
384// Pause signal generation
385always @ (posedge MTxClk or posedge TxReset)
386begin
387 if(TxReset)
388 Pause <= #Tp 1'b0;
389 else
390 if((TxDoneIn | TxAbortIn | ~TxUsedDataOutDetected) & ~TxStartFrmOut)
391 Pause <= #Tp RxFlow & ~PauseTimerEq0_sync2;
392end
393
394
395// Divider2 is used for incrementing the Slot timer every other clock
396always @ (posedge MRxClk or posedge RxReset)
397begin
398 if(RxReset)
399 Divider2 <= #Tp 1'b0;
400 else
401 if(|PauseTimer[15:0] & RxFlow)
402 Divider2 <= #Tp ~Divider2;
403 else
404 Divider2 <= #Tp 1'b0;
405end
406
407
408assign ResetSlotTimer = RxReset;
409assign IncrementSlotTimer = Pause & RxFlow & Divider2;
410
411
412// SlotTimer
413always @ (posedge MRxClk or posedge RxReset)
414begin
415 if(RxReset)
416 SlotTimer[5:0] <= #Tp 6'h0;
417 else
418 if(ResetSlotTimer)
419 SlotTimer[5:0] <= #Tp 6'h0;
420 else
421 if(IncrementSlotTimer)
422 SlotTimer[5:0] <= #Tp SlotTimer[5:0] + 1'b1;
423end
424
425
426assign SlotFinished = &SlotTimer[5:0] & IncrementSlotTimer; // Slot is 512 bits (64 bytes)
427
428
429
430// Pause Frame received
431always @ (posedge MRxClk or posedge RxReset)
432begin
433 if(RxReset)
434 ReceivedPauseFrm <=#Tp 1'b0;
435 else
436 if(RxStatusWriteLatched_sync2 & r_PassAll | ReceivedPauseFrm & (~r_PassAll))
437 ReceivedPauseFrm <=#Tp 1'b0;
438 else
439 if(ByteCntEq16 & TypeLengthOK & OpCodeOK)
440 ReceivedPauseFrm <=#Tp 1'b1;
441end
442
443
444endmodule
Impressum, Datenschutz