OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [ethmac/] [eth_receivecontrol.v] - Blame information for rev 570

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_receivecontrol.v                                        ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6 570 olof
////  http://www.opencores.org/project,ethmac                     ////
7 6 julius
////                                                              ////
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 403 julius
// $Log: not supported by cvs2svn $
44 6 julius
// Revision 1.4  2002/11/22 01:57:06  mohor
45
// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
46
// synchronized.
47
//
48
// Revision 1.3  2002/01/23 10:28:16  mohor
49
// Link in the header changed.
50
//
51
// Revision 1.2  2001/10/19 08:43:51  mohor
52
// eth_timescale.v changed to timescale.v This is done because of the
53
// simulation of the few cores in a one joined project.
54
//
55
// Revision 1.1  2001/08/06 14:44:29  mohor
56
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
57
// Include files fixed to contain no path.
58
// File names and module names changed ta have a eth_ prologue in the name.
59
// File eth_timescale.v is used to define timescale
60
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
61
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
62
// and Mdo_OE. The bidirectional signal must be created on the top level. This
63
// is done due to the ASIC tools.
64
//
65
// Revision 1.1  2001/07/30 21:23:42  mohor
66
// Directory structure changed. Files checked and joind together.
67
//
68
// Revision 1.1  2001/07/03 12:51:54  mohor
69
// Initial release of the MAC Control module.
70
//
71
//
72
//
73
//
74
//
75
 
76
 
77
`include "timescale.v"
78
 
79
 
80
module eth_receivecontrol (MTxClk, MRxClk, TxReset, RxReset, RxData, RxValid, RxStartFrm,
81
                           RxEndFrm, RxFlow, ReceiveEnd, MAC, DlyCrcEn, TxDoneIn,
82
                           TxAbortIn, TxStartFrmOut, ReceivedLengthOK, ReceivedPacketGood,
83
                           TxUsedDataOutDetected, Pause, ReceivedPauseFrm, AddressOK,
84
                           RxStatusWriteLatched_sync2, r_PassAll, SetPauseTimer
85
                          );
86
 
87
parameter Tp = 1;
88
 
89
 
90
input       MTxClk;
91
input       MRxClk;
92
input       TxReset;
93
input       RxReset;
94
input [7:0] RxData;
95
input       RxValid;
96
input       RxStartFrm;
97
input       RxEndFrm;
98
input       RxFlow;
99
input       ReceiveEnd;
100
input [47:0]MAC;
101
input       DlyCrcEn;
102
input       TxDoneIn;
103
input       TxAbortIn;
104
input       TxStartFrmOut;
105
input       ReceivedLengthOK;
106
input       ReceivedPacketGood;
107
input       TxUsedDataOutDetected;
108
input       RxStatusWriteLatched_sync2;
109
input       r_PassAll;
110
 
111
output      Pause;
112
output      ReceivedPauseFrm;
113
output      AddressOK;
114
output      SetPauseTimer;
115
 
116
 
117
reg         Pause;
118
reg         AddressOK;                // Multicast or unicast address detected
119
reg         TypeLengthOK;             // Type/Length field contains 0x8808
120
reg         DetectionWindow;          // Detection of the PAUSE frame is possible within this window
121
reg         OpCodeOK;                 // PAUSE opcode detected (0x0001)
122
reg  [2:0]  DlyCrcCnt;
123
reg  [4:0]  ByteCnt;
124
reg [15:0]  AssembledTimerValue;
125
reg [15:0]  LatchedTimerValue;
126
reg         ReceivedPauseFrm;
127
reg         ReceivedPauseFrmWAddr;
128
reg         PauseTimerEq0_sync1;
129
reg         PauseTimerEq0_sync2;
130
reg [15:0]  PauseTimer;
131
reg         Divider2;
132
reg  [5:0]  SlotTimer;
133
 
134
wire [47:0] ReservedMulticast;        // 0x0180C2000001
135
wire [15:0] TypeLength;               // 0x8808
136
wire        ResetByteCnt;             // 
137
wire        IncrementByteCnt;         // 
138
wire        ByteCntEq0;               // ByteCnt = 0
139
wire        ByteCntEq1;               // ByteCnt = 1
140
wire        ByteCntEq2;               // ByteCnt = 2
141
wire        ByteCntEq3;               // ByteCnt = 3
142
wire        ByteCntEq4;               // ByteCnt = 4
143
wire        ByteCntEq5;               // ByteCnt = 5
144
wire        ByteCntEq12;              // ByteCnt = 12
145
wire        ByteCntEq13;              // ByteCnt = 13
146
wire        ByteCntEq14;              // ByteCnt = 14
147
wire        ByteCntEq15;              // ByteCnt = 15
148
wire        ByteCntEq16;              // ByteCnt = 16
149
wire        ByteCntEq17;              // ByteCnt = 17
150
wire        ByteCntEq18;              // ByteCnt = 18
151
wire        DecrementPauseTimer;      // 
152
wire        PauseTimerEq0;            // 
153
wire        ResetSlotTimer;           // 
154
wire        IncrementSlotTimer;       // 
155
wire        SlotFinished;             // 
156
 
157
 
158
 
159
// Reserved multicast address and Type/Length for PAUSE control
160
assign ReservedMulticast = 48'h0180C2000001;
161
assign TypeLength = 16'h8808;
162
 
163
 
164
// Address Detection (Multicast or unicast)
165
always @ (posedge MRxClk or posedge RxReset)
166
begin
167
  if(RxReset)
168 403 julius
    AddressOK <=  1'b0;
169 6 julius
  else
170
  if(DetectionWindow & ByteCntEq0)
171 403 julius
    AddressOK <=   RxData[7:0] == ReservedMulticast[47:40] | RxData[7:0] == MAC[47:40];
172 6 julius
  else
173
  if(DetectionWindow & ByteCntEq1)
174 403 julius
    AddressOK <=  (RxData[7:0] == ReservedMulticast[39:32] | RxData[7:0] == MAC[39:32]) & AddressOK;
175 6 julius
  else
176
  if(DetectionWindow & ByteCntEq2)
177 403 julius
    AddressOK <=  (RxData[7:0] == ReservedMulticast[31:24] | RxData[7:0] == MAC[31:24]) & AddressOK;
178 6 julius
  else
179
  if(DetectionWindow & ByteCntEq3)
180 403 julius
    AddressOK <=  (RxData[7:0] == ReservedMulticast[23:16] | RxData[7:0] == MAC[23:16]) & AddressOK;
181 6 julius
  else
182
  if(DetectionWindow & ByteCntEq4)
183 403 julius
    AddressOK <=  (RxData[7:0] == ReservedMulticast[15:8]  | RxData[7:0] == MAC[15:8])  & AddressOK;
184 6 julius
  else
185
  if(DetectionWindow & ByteCntEq5)
186 403 julius
    AddressOK <=  (RxData[7:0] == ReservedMulticast[7:0]   | RxData[7:0] == MAC[7:0])   & AddressOK;
187 6 julius
  else
188
  if(ReceiveEnd)
189 403 julius
    AddressOK <=  1'b0;
190 6 julius
end
191
 
192
 
193
 
194
// TypeLengthOK (Type/Length Control frame detected)
195
always @ (posedge MRxClk or posedge RxReset )
196
begin
197
  if(RxReset)
198 403 julius
    TypeLengthOK <=  1'b0;
199 6 julius
  else
200
  if(DetectionWindow & ByteCntEq12)
201 403 julius
    TypeLengthOK <=  ByteCntEq12 & (RxData[7:0] == TypeLength[15:8]);
202 6 julius
  else
203
  if(DetectionWindow & ByteCntEq13)
204 403 julius
    TypeLengthOK <=  ByteCntEq13 & (RxData[7:0] == TypeLength[7:0]) & TypeLengthOK;
205 6 julius
  else
206
  if(ReceiveEnd)
207 403 julius
    TypeLengthOK <=  1'b0;
208 6 julius
end
209
 
210
 
211
 
212
// Latch Control Frame Opcode
213
always @ (posedge MRxClk or posedge RxReset )
214
begin
215
  if(RxReset)
216 403 julius
    OpCodeOK <=  1'b0;
217 6 julius
  else
218
  if(ByteCntEq16)
219 403 julius
    OpCodeOK <=  1'b0;
220 6 julius
  else
221
    begin
222
      if(DetectionWindow & ByteCntEq14)
223 403 julius
        OpCodeOK <=  ByteCntEq14 & RxData[7:0] == 8'h00;
224 6 julius
 
225
      if(DetectionWindow & ByteCntEq15)
226 403 julius
        OpCodeOK <=  ByteCntEq15 & RxData[7:0] == 8'h01 & OpCodeOK;
227 6 julius
    end
228
end
229
 
230
 
231
// ReceivedPauseFrmWAddr (+Address Check)
232
always @ (posedge MRxClk or posedge RxReset )
233
begin
234
  if(RxReset)
235 403 julius
    ReceivedPauseFrmWAddr <=  1'b0;
236 6 julius
  else
237
  if(ReceiveEnd)
238 403 julius
    ReceivedPauseFrmWAddr <=  1'b0;
239 6 julius
  else
240
  if(ByteCntEq16 & TypeLengthOK & OpCodeOK & AddressOK)
241 403 julius
    ReceivedPauseFrmWAddr <=  1'b1;
242 6 julius
end
243
 
244
 
245
 
246
// Assembling 16-bit timer value from two 8-bit data
247
always @ (posedge MRxClk or posedge RxReset )
248
begin
249
  if(RxReset)
250 403 julius
    AssembledTimerValue[15:0] <=  16'h0;
251 6 julius
  else
252
  if(RxStartFrm)
253 403 julius
    AssembledTimerValue[15:0] <=  16'h0;
254 6 julius
  else
255
    begin
256
      if(DetectionWindow & ByteCntEq16)
257 403 julius
        AssembledTimerValue[15:8] <=  RxData[7:0];
258 6 julius
      if(DetectionWindow & ByteCntEq17)
259 403 julius
        AssembledTimerValue[7:0] <=  RxData[7:0];
260 6 julius
    end
261
end
262
 
263
 
264
// Detection window (while PAUSE detection is possible)
265
always @ (posedge MRxClk or posedge RxReset )
266
begin
267
  if(RxReset)
268 403 julius
    DetectionWindow <=  1'b1;
269 6 julius
  else
270
  if(ByteCntEq18)
271 403 julius
    DetectionWindow <=  1'b0;
272 6 julius
  else
273
  if(ReceiveEnd)
274 403 julius
    DetectionWindow <=  1'b1;
275 6 julius
end
276
 
277
 
278
 
279
// Latching Timer Value
280
always @ (posedge MRxClk or posedge RxReset )
281
begin
282
  if(RxReset)
283 403 julius
    LatchedTimerValue[15:0] <=  16'h0;
284 6 julius
  else
285
  if(DetectionWindow &  ReceivedPauseFrmWAddr &  ByteCntEq18)
286 403 julius
    LatchedTimerValue[15:0] <=  AssembledTimerValue[15:0];
287 6 julius
  else
288
  if(ReceiveEnd)
289 403 julius
    LatchedTimerValue[15:0] <=  16'h0;
290 6 julius
end
291
 
292
 
293
 
294
// Delayed CEC counter
295
always @ (posedge MRxClk or posedge RxReset)
296
begin
297
  if(RxReset)
298 403 julius
    DlyCrcCnt <=  3'h0;
299 6 julius
  else
300
  if(RxValid & RxEndFrm)
301 403 julius
    DlyCrcCnt <=  3'h0;
302 6 julius
  else
303
  if(RxValid & ~RxEndFrm & ~DlyCrcCnt[2])
304 439 julius
    DlyCrcCnt <=  DlyCrcCnt + 3'd1;
305 6 julius
end
306
 
307
 
308
assign ResetByteCnt = RxEndFrm;
309 439 julius
assign IncrementByteCnt = RxValid & DetectionWindow & ~ByteCntEq18 &
310
                          (~DlyCrcEn | DlyCrcEn & DlyCrcCnt[2]);
311 6 julius
 
312
 
313
// Byte counter
314
always @ (posedge MRxClk or posedge RxReset)
315
begin
316
  if(RxReset)
317 403 julius
    ByteCnt[4:0] <=  5'h0;
318 6 julius
  else
319
  if(ResetByteCnt)
320 403 julius
    ByteCnt[4:0] <=  5'h0;
321 6 julius
  else
322
  if(IncrementByteCnt)
323 439 julius
    ByteCnt[4:0] <=  ByteCnt[4:0] + 5'd1;
324 6 julius
end
325
 
326
 
327
assign ByteCntEq0 = RxValid & ByteCnt[4:0] == 5'h0;
328
assign ByteCntEq1 = RxValid & ByteCnt[4:0] == 5'h1;
329
assign ByteCntEq2 = RxValid & ByteCnt[4:0] == 5'h2;
330
assign ByteCntEq3 = RxValid & ByteCnt[4:0] == 5'h3;
331
assign ByteCntEq4 = RxValid & ByteCnt[4:0] == 5'h4;
332
assign ByteCntEq5 = RxValid & ByteCnt[4:0] == 5'h5;
333
assign ByteCntEq12 = RxValid & ByteCnt[4:0] == 5'h0C;
334
assign ByteCntEq13 = RxValid & ByteCnt[4:0] == 5'h0D;
335
assign ByteCntEq14 = RxValid & ByteCnt[4:0] == 5'h0E;
336
assign ByteCntEq15 = RxValid & ByteCnt[4:0] == 5'h0F;
337
assign ByteCntEq16 = RxValid & ByteCnt[4:0] == 5'h10;
338
assign ByteCntEq17 = RxValid & ByteCnt[4:0] == 5'h11;
339
assign ByteCntEq18 = RxValid & ByteCnt[4:0] == 5'h12 & DetectionWindow;
340
 
341
 
342
assign SetPauseTimer = ReceiveEnd & ReceivedPauseFrmWAddr & ReceivedPacketGood & ReceivedLengthOK & RxFlow;
343
assign DecrementPauseTimer = SlotFinished & |PauseTimer;
344
 
345
 
346
// PauseTimer[15:0]
347
always @ (posedge MRxClk or posedge RxReset)
348
begin
349
  if(RxReset)
350 403 julius
    PauseTimer[15:0] <=  16'h0;
351 6 julius
  else
352
  if(SetPauseTimer)
353 403 julius
    PauseTimer[15:0] <=  LatchedTimerValue[15:0];
354 6 julius
  else
355
  if(DecrementPauseTimer)
356 439 julius
    PauseTimer[15:0] <=  PauseTimer[15:0] - 16'd1;
357 6 julius
end
358
 
359
assign PauseTimerEq0 = ~(|PauseTimer[15:0]);
360
 
361
 
362
 
363
// Synchronization of the pause timer
364
always @ (posedge MTxClk or posedge TxReset)
365
begin
366
  if(TxReset)
367
    begin
368 403 julius
      PauseTimerEq0_sync1 <=  1'b1;
369
      PauseTimerEq0_sync2 <=  1'b1;
370 6 julius
    end
371
  else
372
    begin
373 403 julius
      PauseTimerEq0_sync1 <=  PauseTimerEq0;
374
      PauseTimerEq0_sync2 <=  PauseTimerEq0_sync1;
375 6 julius
    end
376
end
377
 
378
 
379
// Pause signal generation
380
always @ (posedge MTxClk or posedge TxReset)
381
begin
382
  if(TxReset)
383 403 julius
    Pause <=  1'b0;
384 6 julius
  else
385
  if((TxDoneIn | TxAbortIn | ~TxUsedDataOutDetected) & ~TxStartFrmOut)
386 403 julius
    Pause <=  RxFlow & ~PauseTimerEq0_sync2;
387 6 julius
end
388
 
389
 
390
// Divider2 is used for incrementing the Slot timer every other clock
391
always @ (posedge MRxClk or posedge RxReset)
392
begin
393
  if(RxReset)
394 403 julius
    Divider2 <=  1'b0;
395 6 julius
  else
396
  if(|PauseTimer[15:0] & RxFlow)
397 403 julius
    Divider2 <=  ~Divider2;
398 6 julius
  else
399 403 julius
    Divider2 <=  1'b0;
400 6 julius
end
401
 
402
 
403
assign ResetSlotTimer = RxReset;
404
assign IncrementSlotTimer =  Pause & RxFlow & Divider2;
405
 
406
 
407
// SlotTimer
408
always @ (posedge MRxClk or posedge RxReset)
409
begin
410
  if(RxReset)
411 403 julius
    SlotTimer[5:0] <=  6'h0;
412 6 julius
  else
413
  if(ResetSlotTimer)
414 403 julius
    SlotTimer[5:0] <=  6'h0;
415 6 julius
  else
416
  if(IncrementSlotTimer)
417 439 julius
    SlotTimer[5:0] <=  SlotTimer[5:0] + 6'd1;
418 6 julius
end
419
 
420
 
421
assign SlotFinished = &SlotTimer[5:0] & IncrementSlotTimer;  // Slot is 512 bits (64 bytes)
422
 
423
 
424
 
425
// Pause Frame received
426
always @ (posedge MRxClk or posedge RxReset)
427
begin
428
  if(RxReset)
429 403 julius
    ReceivedPauseFrm <= 1'b0;
430 6 julius
  else
431
  if(RxStatusWriteLatched_sync2 & r_PassAll | ReceivedPauseFrm & (~r_PassAll))
432 403 julius
    ReceivedPauseFrm <= 1'b0;
433 6 julius
  else
434
  if(ByteCntEq16 & TypeLengthOK & OpCodeOK)
435 403 julius
    ReceivedPauseFrm <= 1'b1;
436 6 julius
end
437
 
438
 
439
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.