source: XOpenSparcT1/trunk/OC-Ethernet/eth_txethmac.v @ 6

Revision 6, 16.8 KB checked in by pntsvt00, 14 years ago (diff)

versione iniziale opensparc

Line 
1//////////////////////////////////////////////////////////////////////
2////                                                              ////
3////  eth_txethmac.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: not supported by cvs2svn $
46// Revision 1.8  2003/01/30 13:33:24  mohor
47// When padding was enabled and crc disabled, frame was not ended correctly.
48//
49// Revision 1.7  2002/02/26 16:24:01  mohor
50// RetryCntLatched was unused and removed from design
51//
52// Revision 1.6  2002/02/22 12:56:35  mohor
53// Retry is not activated when a Tx Underrun occured
54//
55// Revision 1.5  2002/02/11 09:18:22  mohor
56// Tx status is written back to the BD.
57//
58// Revision 1.4  2002/01/23 10:28:16  mohor
59// Link in the header changed.
60//
61// Revision 1.3  2001/10/19 08:43:51  mohor
62// eth_timescale.v changed to timescale.v This is done because of the
63// simulation of the few cores in a one joined project.
64//
65// Revision 1.2  2001/09/11 14:17:00  mohor
66// Few little NCSIM warnings fixed.
67//
68// Revision 1.1  2001/08/06 14:44:29  mohor
69// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
70// Include files fixed to contain no path.
71// File names and module names changed ta have a eth_ prologue in the name.
72// File eth_timescale.v is used to define timescale
73// All pin names on the top module are changed to contain _I, _O or _OE at the end.
74// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
75// and Mdo_OE. The bidirectional signal must be created on the top level. This
76// is done due to the ASIC tools.
77//
78// Revision 1.1  2001/07/30 21:23:42  mohor
79// Directory structure changed. Files checked and joind together.
80//
81// Revision 1.3  2001/06/19 18:16:40  mohor
82// TxClk changed to MTxClk (as discribed in the documentation).
83// Crc changed so only one file can be used instead of two.
84//
85// Revision 1.2  2001/06/19 10:38:08  mohor
86// Minor changes in header.
87//
88// Revision 1.1  2001/06/19 10:27:58  mohor
89// TxEthMAC initial release.
90//
91//
92//
93
94`include "timescale.v"
95
96
97module eth_txethmac (MTxClk, Reset, TxStartFrm, TxEndFrm, TxUnderRun, TxData, CarrierSense, 
98                     Collision, Pad, CrcEn, FullD, HugEn, DlyCrcEn, MinFL, MaxFL, IPGT, 
99                     IPGR1, IPGR2, CollValid, MaxRet, NoBckof, ExDfrEn, 
100                     MTxD, MTxEn, MTxErr, TxDone, TxRetry, TxAbort, TxUsedData, WillTransmit, 
101                     ResetCollision, RetryCnt, StartTxDone, StartTxAbort, MaxCollisionOccured,
102                     LateCollision, DeferIndication, StatePreamble, StateData
103
104                    );
105
106parameter Tp = 1;
107
108
109input MTxClk;                   // Transmit clock (from PHY)
110input Reset;                    // Reset
111input TxStartFrm;               // Transmit packet start frame
112input TxEndFrm;                 // Transmit packet end frame
113input TxUnderRun;               // Transmit packet under-run
114input [7:0] TxData;             // Transmit packet data byte
115input CarrierSense;             // Carrier sense (synchronized)
116input Collision;                // Collision (synchronized)
117input Pad;                      // Pad enable (from register)
118input CrcEn;                    // Crc enable (from register)
119input FullD;                    // Full duplex (from register)
120input HugEn;                    // Huge packets enable (from register)
121input DlyCrcEn;                 // Delayed Crc enabled (from register)
122input [15:0] MinFL;             // Minimum frame length (from register)
123input [15:0] MaxFL;             // Maximum frame length (from register)
124input [6:0] IPGT;               // Back to back transmit inter packet gap parameter (from register)
125input [6:0] IPGR1;              // Non back to back transmit inter packet gap parameter IPGR1 (from register)
126input [6:0] IPGR2;              // Non back to back transmit inter packet gap parameter IPGR2 (from register)
127input [5:0] CollValid;          // Valid collision window (from register)
128input [3:0] MaxRet;             // Maximum retry number (from register)
129input NoBckof;                  // No backoff (from register)
130input ExDfrEn;                  // Excessive defferal enable (from register)
131
132output [3:0] MTxD;              // Transmit nibble (to PHY)
133output MTxEn;                   // Transmit enable (to PHY)
134output MTxErr;                  // Transmit error (to PHY)
135output TxDone;                  // Transmit packet done (to RISC)
136output TxRetry;                 // Transmit packet retry (to RISC)
137output TxAbort;                 // Transmit packet abort (to RISC)
138output TxUsedData;              // Transmit packet used data (to RISC)
139output WillTransmit;            // Will transmit (to RxEthMAC)
140output ResetCollision;          // Reset Collision (for synchronizing collision)
141output [3:0] RetryCnt;          // Latched Retry Counter for tx status purposes
142output StartTxDone;
143output StartTxAbort;
144output MaxCollisionOccured;
145output LateCollision;
146output DeferIndication;
147output StatePreamble;
148output [1:0] StateData;
149
150reg [3:0] MTxD;
151reg MTxEn;
152reg MTxErr;
153reg TxDone;
154reg TxRetry;
155reg TxAbort;
156reg TxUsedData;
157reg WillTransmit;
158reg ColWindow;
159reg StopExcessiveDeferOccured;
160reg [3:0] RetryCnt;
161reg [3:0] MTxD_d;
162reg StatusLatch;
163reg PacketFinished_q;
164reg PacketFinished;
165
166
167wire ExcessiveDeferOccured;
168wire StartIPG;
169wire StartPreamble;
170wire [1:0] StartData;
171wire StartFCS;
172wire StartJam;
173wire StartDefer;
174wire StartBackoff;
175wire StateDefer;
176wire StateIPG;
177wire StateIdle;
178wire StatePAD;
179wire StateFCS;
180wire StateJam;
181wire StateJam_q;
182wire StateBackOff;
183wire StateSFD;
184wire StartTxRetry;
185wire UnderRun;
186wire TooBig;
187wire [31:0] Crc;
188wire CrcError;
189wire [2:0] DlyCrcCnt;
190wire [15:0] NibCnt;
191wire NibCntEq7;
192wire NibCntEq15;
193wire NibbleMinFl;
194wire ExcessiveDefer;
195wire [15:0] ByteCnt;
196wire MaxFrame;
197wire RetryMax;
198wire RandomEq0;
199wire RandomEqByteCnt;
200wire PacketFinished_d;
201
202
203
204assign ResetCollision = ~(StatePreamble | (|StateData) | StatePAD | StateFCS);
205
206assign ExcessiveDeferOccured = TxStartFrm & StateDefer & ExcessiveDefer & ~StopExcessiveDeferOccured;
207
208assign StartTxDone = ~Collision & (StateFCS & NibCntEq7 | StateData[1] & TxEndFrm & (~Pad | Pad & NibbleMinFl) & ~CrcEn);
209
210assign UnderRun = StateData[0] & TxUnderRun & ~Collision;
211
212assign TooBig = ~Collision & MaxFrame & (StateData[0] & ~TxUnderRun | StateFCS);
213
214// assign StartTxRetry = StartJam & (ColWindow & ~RetryMax);
215assign StartTxRetry = StartJam & (ColWindow & ~RetryMax) & ~UnderRun;
216
217assign LateCollision = StartJam & ~ColWindow & ~UnderRun;
218
219assign MaxCollisionOccured = StartJam & ColWindow & RetryMax;
220
221assign StateSFD = StatePreamble & NibCntEq15;
222
223assign StartTxAbort = TooBig | UnderRun | ExcessiveDeferOccured | LateCollision | MaxCollisionOccured;
224
225
226// StopExcessiveDeferOccured
227always @ (posedge MTxClk or posedge Reset)
228begin
229  if(Reset)
230    StopExcessiveDeferOccured <= #Tp 1'b0;
231  else
232    begin
233      if(~TxStartFrm)
234        StopExcessiveDeferOccured <= #Tp 1'b0;
235      else
236      if(ExcessiveDeferOccured)
237        StopExcessiveDeferOccured <= #Tp 1'b1;
238    end
239end
240
241
242// Collision Window
243always @ (posedge MTxClk or posedge Reset)
244begin
245  if(Reset)
246    ColWindow <= #Tp 1'b1;
247  else
248    begin 
249      if(~Collision & ByteCnt[5:0] == CollValid[5:0] & (StateData[1] | StatePAD & NibCnt[0] | StateFCS & NibCnt[0]))
250        ColWindow <= #Tp 1'b0;
251      else
252      if(StateIdle | StateIPG)
253        ColWindow <= #Tp 1'b1;
254    end
255end
256
257
258// Start Window
259always @ (posedge MTxClk or posedge Reset)
260begin
261  if(Reset)
262    StatusLatch <= #Tp 1'b0;
263  else
264    begin
265      if(~TxStartFrm)
266        StatusLatch <= #Tp 1'b0;
267      else
268      if(ExcessiveDeferOccured | StateIdle)
269        StatusLatch <= #Tp 1'b1;
270     end
271end
272
273
274// Transmit packet used data
275always @ (posedge MTxClk or posedge Reset)
276begin
277  if(Reset)
278    TxUsedData <= #Tp 1'b0;
279  else
280    TxUsedData <= #Tp |StartData;
281end
282
283
284// Transmit packet done
285always @ (posedge MTxClk or posedge Reset)
286begin
287  if(Reset)
288    TxDone <= #Tp 1'b0;
289  else
290    begin
291      if(TxStartFrm & ~StatusLatch)
292        TxDone <= #Tp 1'b0;
293      else
294      if(StartTxDone)
295        TxDone <= #Tp 1'b1;
296    end
297end
298
299
300// Transmit packet retry
301always @ (posedge MTxClk or posedge Reset)
302begin
303  if(Reset)
304    TxRetry <= #Tp 1'b0;
305  else
306    begin
307      if(TxStartFrm & ~StatusLatch)
308        TxRetry <= #Tp 1'b0;
309      else
310      if(StartTxRetry)
311        TxRetry <= #Tp 1'b1;
312     end
313end                                   
314
315
316// Transmit packet abort
317always @ (posedge MTxClk or posedge Reset)
318begin
319  if(Reset)
320    TxAbort <= #Tp 1'b0;
321  else
322    begin
323      if(TxStartFrm & ~StatusLatch & ~ExcessiveDeferOccured)
324        TxAbort <= #Tp 1'b0;
325      else
326      if(StartTxAbort)
327        TxAbort <= #Tp 1'b1;
328    end
329end
330
331
332// Retry counter
333always @ (posedge MTxClk or posedge Reset)
334begin
335  if(Reset)
336    RetryCnt[3:0] <= #Tp 4'h0;
337  else
338    begin
339      if(ExcessiveDeferOccured | UnderRun | TooBig | StartTxDone | TxUnderRun
340          | StateJam & NibCntEq7 & (~ColWindow | RetryMax))
341        RetryCnt[3:0] <= #Tp 4'h0;
342      else
343      if(StateJam & NibCntEq7 & ColWindow & (RandomEq0 | NoBckof) | StateBackOff & RandomEqByteCnt)
344        RetryCnt[3:0] <= #Tp RetryCnt[3:0] + 1'b1;
345    end
346end
347
348
349assign RetryMax = RetryCnt[3:0] == MaxRet[3:0];
350
351
352// Transmit nibble
353always @ (StatePreamble or StateData or StateData or StateFCS or StateJam or StateSFD or TxData or 
354          Crc or NibCntEq15)
355begin
356  if(StateData[0])
357    MTxD_d[3:0] = TxData[3:0];                                  // Lower nibble
358  else
359  if(StateData[1])
360    MTxD_d[3:0] = TxData[7:4];                                  // Higher nibble
361  else
362  if(StateFCS)
363    MTxD_d[3:0] = {~Crc[28], ~Crc[29], ~Crc[30], ~Crc[31]};     // Crc
364  else
365  if(StateJam)
366    MTxD_d[3:0] = 4'h9;                                         // Jam pattern
367  else
368  if(StatePreamble)
369    if(NibCntEq15)
370      MTxD_d[3:0] = 4'hd;                                       // SFD
371    else
372      MTxD_d[3:0] = 4'h5;                                       // Preamble
373  else
374    MTxD_d[3:0] = 4'h0;
375end
376
377
378// Transmit Enable
379always @ (posedge MTxClk or posedge Reset)
380begin
381  if(Reset)
382    MTxEn <= #Tp 1'b0;
383  else
384    MTxEn <= #Tp StatePreamble | (|StateData) | StatePAD | StateFCS | StateJam;
385end
386
387
388// Transmit nibble
389always @ (posedge MTxClk or posedge Reset)
390begin
391  if(Reset)
392    MTxD[3:0] <= #Tp 4'h0;
393  else
394    MTxD[3:0] <= #Tp MTxD_d[3:0];
395end
396
397
398// Transmit error
399always @ (posedge MTxClk or posedge Reset)
400begin
401  if(Reset)
402    MTxErr <= #Tp 1'b0;
403  else
404    MTxErr <= #Tp TooBig | UnderRun;
405end
406
407
408// WillTransmit
409always @ (posedge MTxClk or posedge Reset)
410begin
411  if(Reset)
412    WillTransmit <= #Tp  1'b0;
413  else
414    WillTransmit <= #Tp StartPreamble | StatePreamble | (|StateData) | StatePAD | StateFCS | StateJam;
415end
416
417
418assign PacketFinished_d = StartTxDone | TooBig | UnderRun | LateCollision | MaxCollisionOccured | ExcessiveDeferOccured;
419
420
421// Packet finished
422always @ (posedge MTxClk or posedge Reset)
423begin
424  if(Reset)
425    begin
426      PacketFinished <= #Tp 1'b0;
427      PacketFinished_q  <= #Tp 1'b0;
428    end
429  else
430    begin
431      PacketFinished <= #Tp PacketFinished_d;
432      PacketFinished_q  <= #Tp PacketFinished;
433    end
434end
435
436
437// Connecting module Counters
438eth_txcounters txcounters1 (.StatePreamble(StatePreamble), .StateIPG(StateIPG), .StateData(StateData), 
439                            .StatePAD(StatePAD), .StateFCS(StateFCS), .StateJam(StateJam), .StateBackOff(StateBackOff), 
440                            .StateDefer(StateDefer), .StateIdle(StateIdle), .StartDefer(StartDefer), .StartIPG(StartIPG), 
441                            .StartFCS(StartFCS), .StartJam(StartJam), .TxStartFrm(TxStartFrm), .MTxClk(MTxClk), 
442                            .Reset(Reset), .MinFL(MinFL), .MaxFL(MaxFL), .HugEn(HugEn), .ExDfrEn(ExDfrEn), 
443                            .PacketFinished_q(PacketFinished_q), .DlyCrcEn(DlyCrcEn), .StartBackoff(StartBackoff), 
444                            .StateSFD(StateSFD), .ByteCnt(ByteCnt), .NibCnt(NibCnt), .ExcessiveDefer(ExcessiveDefer), 
445                            .NibCntEq7(NibCntEq7), .NibCntEq15(NibCntEq15), .MaxFrame(MaxFrame), .NibbleMinFl(NibbleMinFl), 
446                            .DlyCrcCnt(DlyCrcCnt)
447                           );
448
449
450// Connecting module StateM
451eth_txstatem txstatem1 (.MTxClk(MTxClk), .Reset(Reset), .ExcessiveDefer(ExcessiveDefer), .CarrierSense(CarrierSense), 
452                        .NibCnt(NibCnt[6:0]), .IPGT(IPGT), .IPGR1(IPGR1), .IPGR2(IPGR2), .FullD(FullD), 
453                        .TxStartFrm(TxStartFrm), .TxEndFrm(TxEndFrm), .TxUnderRun(TxUnderRun), .Collision(Collision), 
454                        .UnderRun(UnderRun), .StartTxDone(StartTxDone), .TooBig(TooBig), .NibCntEq7(NibCntEq7), 
455                        .NibCntEq15(NibCntEq15), .MaxFrame(MaxFrame), .Pad(Pad), .CrcEn(CrcEn), 
456                        .NibbleMinFl(NibbleMinFl), .RandomEq0(RandomEq0), .ColWindow(ColWindow), .RetryMax(RetryMax), 
457                        .NoBckof(NoBckof), .RandomEqByteCnt(RandomEqByteCnt), .StateIdle(StateIdle), 
458                        .StateIPG(StateIPG), .StatePreamble(StatePreamble), .StateData(StateData), .StatePAD(StatePAD), 
459                        .StateFCS(StateFCS), .StateJam(StateJam), .StateJam_q(StateJam_q), .StateBackOff(StateBackOff), 
460                        .StateDefer(StateDefer), .StartFCS(StartFCS), .StartJam(StartJam), .StartBackoff(StartBackoff), 
461                        .StartDefer(StartDefer), .DeferIndication(DeferIndication), .StartPreamble(StartPreamble), .StartData(StartData), .StartIPG(StartIPG)
462                       );
463
464
465wire Enable_Crc;
466wire [3:0] Data_Crc;
467wire Initialize_Crc;
468
469assign Enable_Crc = ~StateFCS;
470
471assign Data_Crc[0] = StateData[0]? TxData[3] : StateData[1]? TxData[7] : 1'b0;
472assign Data_Crc[1] = StateData[0]? TxData[2] : StateData[1]? TxData[6] : 1'b0;
473assign Data_Crc[2] = StateData[0]? TxData[1] : StateData[1]? TxData[5] : 1'b0;
474assign Data_Crc[3] = StateData[0]? TxData[0] : StateData[1]? TxData[4] : 1'b0;
475
476assign Initialize_Crc = StateIdle | StatePreamble | (|DlyCrcCnt);
477
478
479// Connecting module Crc
480eth_crc txcrc (.Clk(MTxClk), .Reset(Reset), .Data(Data_Crc), .Enable(Enable_Crc), .Initialize(Initialize_Crc), 
481               .Crc(Crc), .CrcError(CrcError)
482              );
483
484
485// Connecting module Random
486eth_random random1 (.MTxClk(MTxClk), .Reset(Reset), .StateJam(StateJam), .StateJam_q(StateJam_q), .RetryCnt(RetryCnt), 
487                    .NibCnt(NibCnt), .ByteCnt(ByteCnt[9:0]), .RandomEq0(RandomEq0), .RandomEqByteCnt(RandomEqByteCnt));
488
489
490
491
492endmodule
Note: See TracBrowser for help on using the repository browser.