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

Subversion Repositories ts7300_opencore

[/] [ts7300_opencore/] [trunk/] [ethernet/] [eth_txethmac.v] - Blame information for rev 6

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

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

powered by: WebSVN 2.1.0

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