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

Subversion Repositories mac_layer_switch

[/] [mac_layer_switch/] [trunk/] [rtl/] [verilog/] [eth_txstatem.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ranm11
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_txstatem.v                                              ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6
////  http://www.opencores.org/project,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.5  2002/10/30 12:54:50  mohor
47
// State machine goes from idle to the defer state when CarrierSense is 1. FCS (CRC appending) fixed to check the CrcEn bit also when padding is necessery.
48
//
49
// Revision 1.4  2002/01/23 10:28:16  mohor
50
// Link in the header changed.
51
//
52
// 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
// Revision 1.2  2001/09/11 14:17:00  mohor
57
// Few little NCSIM warnings fixed.
58
//
59
// 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
// 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:07  mohor
77
// Minor changes in header.
78
//
79
// Revision 1.1  2001/06/19 10:27:57  mohor
80
// TxEthMAC initial release.
81
//
82
//
83
//
84
//
85
 
86
 
87
`include "timescale.v"
88
 
89
 
90
module eth_txstatem  (MTxClk, Reset, ExcessiveDefer, CarrierSense, NibCnt, IPGT, IPGR1,
91
                      IPGR2, FullD, TxStartFrm, TxEndFrm, TxUnderRun, Collision, UnderRun,
92
                      StartTxDone, TooBig, NibCntEq7, NibCntEq15, MaxFrame, Pad, CrcEn,
93
                      NibbleMinFl, RandomEq0, ColWindow, RetryMax, NoBckof, RandomEqByteCnt,
94
                      StateIdle, StateIPG, StatePreamble, StateData, StatePAD, StateFCS,
95
                      StateJam, StateJam_q, StateBackOff, StateDefer, StartFCS, StartJam,
96
                      StartBackoff, StartDefer, DeferIndication, StartPreamble, StartData, StartIPG
97
                     );
98
 
99
input MTxClk;
100
input Reset;
101
input ExcessiveDefer;
102
input CarrierSense;
103
input [6:0] NibCnt;
104
input [6:0] IPGT;
105
input [6:0] IPGR1;
106
input [6:0] IPGR2;
107
input FullD;
108
input TxStartFrm;
109
input TxEndFrm;
110
input TxUnderRun;
111
input Collision;
112
input UnderRun;
113
input StartTxDone;
114
input TooBig;
115
input NibCntEq7;
116
input NibCntEq15;
117
input MaxFrame;
118
input Pad;
119
input CrcEn;
120
input NibbleMinFl;
121
input RandomEq0;
122
input ColWindow;
123
input RetryMax;
124
input NoBckof;
125
input RandomEqByteCnt;
126
 
127
 
128
output StateIdle;         // Idle state
129
output StateIPG;          // IPG state
130
output StatePreamble;     // Preamble state
131
output [1:0] StateData;   // Data state
132
output StatePAD;          // PAD state
133
output StateFCS;          // FCS state
134
output StateJam;          // Jam state
135
output StateJam_q;        // Delayed Jam state
136
output StateBackOff;      // Backoff state
137
output StateDefer;        // Defer state
138
 
139
output StartFCS;          // FCS state will be activated in next clock
140
output StartJam;          // Jam state will be activated in next clock
141
output StartBackoff;      // Backoff state will be activated in next clock
142
output StartDefer;        // Defer state will be activated in next clock
143
output DeferIndication;
144
output StartPreamble;     // Preamble state will be activated in next clock
145
output [1:0] StartData;   // Data state will be activated in next clock
146
output StartIPG;          // IPG state will be activated in next clock
147
 
148
wire StartIdle;           // Idle state will be activated in next clock
149
wire StartPAD;            // PAD state will be activated in next clock
150
 
151
 
152
reg StateIdle;
153
reg StateIPG;
154
reg StatePreamble;
155
reg [1:0] StateData;
156
reg StatePAD;
157
reg StateFCS;
158
reg StateJam;
159
reg StateJam_q;
160
reg StateBackOff;
161
reg StateDefer;
162
reg Rule1;
163
reg StateTraffic;
164
 
165
// Defining the next state
166
assign StartIPG = StateDefer & ~ExcessiveDefer & ~CarrierSense;
167
 
168
assign StartIdle = StateIPG & (Rule1 & NibCnt[6:0] >= IPGT | ~Rule1 & NibCnt[6:0] >= IPGR2);
169
 
170
assign StartPreamble = StateIdle & TxStartFrm & ~CarrierSense;
171
 
172
assign StartData[0] = ~Collision & (StatePreamble & NibCntEq15 | StateData[1] & ~TxEndFrm);
173
 
174
assign StartData[1] = ~Collision & StateData[0] & ~TxUnderRun & ~MaxFrame;
175
 
176
assign StartPAD = ~Collision & StateData[1] & TxEndFrm & Pad & ~NibbleMinFl;
177
 
178
assign StartFCS = ~Collision & StateData[1] & TxEndFrm & (~Pad | Pad & NibbleMinFl) & CrcEn
179
                | ~Collision & StatePAD & NibbleMinFl & CrcEn;
180
 
181
assign StartJam = (Collision | UnderRun) & ((StatePreamble & NibCntEq15) | (|StateData[1:0]) | StatePAD | StateFCS);
182
 
183
assign StartBackoff = StateJam & ~RandomEq0 & ColWindow & ~RetryMax & NibCntEq7 & ~NoBckof;
184
 
185
assign StartDefer = StateIPG & ~Rule1 & CarrierSense & NibCnt[6:0] <= IPGR1 & NibCnt[6:0] != IPGR2
186
                  | StateIdle & CarrierSense
187
                  | StateJam & NibCntEq7 & (NoBckof | RandomEq0 | ~ColWindow | RetryMax)
188
                  | StateBackOff & (TxUnderRun | RandomEqByteCnt)
189
                  | StartTxDone | TooBig;
190
 
191
assign DeferIndication = StateIdle & CarrierSense;
192
 
193
initial StateTraffic=0;
194
 
195
always @ (posedge TxStartFrm)
196
begin
197
    StateTraffic =1;
198
end
199
always @ (negedge TxEndFrm)
200
begin
201
     StateTraffic=0;
202
    end
203
 
204
// Tx State Machine
205
always @ (posedge MTxClk or posedge Reset)
206
begin
207
  if(Reset)
208
    begin
209
      StateIPG        <=  1'b0;
210
      StateIdle       <=  1'b0;
211
      StatePreamble   <=  1'b0;
212
      StateData[1:0]  <=  2'b0;
213
      StatePAD        <=  1'b0;
214
      StateFCS        <=  1'b0;
215
      StateJam        <=  1'b0;
216
      StateJam_q      <=  1'b0;
217
      StateBackOff    <=  1'b0;
218
      StateDefer      <=  1'b1;
219
    end
220
  else
221
    begin
222
      StateData[1:0] <=  StartData[1:0];
223
      StateJam_q <=  StateJam;
224
 
225
      if(StartDefer | StartIdle)
226
        StateIPG <=  1'b0;
227
      else
228
      if(StartIPG)
229
        StateIPG <=  1'b1;
230
 
231
      if(StartDefer | StartPreamble)
232
        StateIdle <=  1'b0;
233
      else
234
      if(StartIdle)
235
        StateIdle <=  1'b1;
236
 
237
      if(StartData[0] | StartJam)
238
        StatePreamble <=  1'b0;
239
      else
240
      if(StartPreamble)
241
        StatePreamble <=  1'b1;
242
 
243
      if(StartFCS | StartJam)
244
        StatePAD <=  1'b0;
245
      else
246
      if(StartPAD)
247
        StatePAD <=  1'b1;
248
 
249
      if(StartJam | StartDefer)
250
        StateFCS <=  1'b0;
251
      else
252
      if(StartFCS)
253
        StateFCS <=  1'b1;
254
 
255
      if(StartBackoff | StartDefer)
256
        StateJam <=  1'b0;
257
      else
258
      if(StartJam)
259
        StateJam <=  1'b1;
260
 
261
      if(StartDefer)
262
        StateBackOff <=  1'b0;
263
      else
264
      if(StartBackoff)
265
        StateBackOff <=  1'b1;
266
 
267
      if(StartIPG)
268
        StateDefer <=  1'b0;
269
      else
270
      if(StartDefer)
271
        StateDefer <=  1'b1;
272
    end
273
end
274
 
275
 
276
// This sections defines which interpack gap rule to use
277
always @ (posedge MTxClk or posedge Reset)
278
begin
279
  if(Reset)
280
    Rule1 <=  1'b0;
281
  else
282
    begin
283
      if(StateIdle | StateBackOff)
284
        Rule1 <=  1'b0;
285
      else
286
      if(StatePreamble | FullD)
287
        Rule1 <=  1'b1;
288
    end
289
end
290
 
291
 
292
 
293
endmodule

powered by: WebSVN 2.1.0

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