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

Subversion Repositories ethmac

[/] [ethmac/] [branches/] [unneback/] [rtl/] [verilog/] [eth_txethmac.v] - Blame information for rev 22

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

powered by: WebSVN 2.1.0

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