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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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