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

Subversion Repositories ethmac

[/] [ethmac/] [trunk/] [rtl/] [verilog/] [eth_txethmac.v] - Blame information for rev 72

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

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

powered by: WebSVN 2.1.0

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