source: XOpenSparcT1/trunk/OC-Ethernet/eth_transmitcontrol.v @ 6

Revision 6, 10.3 KB checked in by pntsvt00, 13 years ago (diff)

versione iniziale opensparc

Line 
1//////////////////////////////////////////////////////////////////////
2////                                                              ////
3////  eth_transmitcontrol.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////                                                              ////
11////  All additional information is avaliable in the Readme.txt   ////
12////  file.                                                       ////
13////                                                              ////
14//////////////////////////////////////////////////////////////////////
15////                                                              ////
16//// Copyright (C) 2001 Authors                                   ////
17////                                                              ////
18//// This source file may be used and distributed without         ////
19//// restriction provided that this copyright statement is not    ////
20//// removed from the file and that any derivative work contains  ////
21//// the original copyright notice and the associated disclaimer. ////
22////                                                              ////
23//// This source file is free software; you can redistribute it   ////
24//// and/or modify it under the terms of the GNU Lesser General   ////
25//// Public License as published by the Free Software Foundation; ////
26//// either version 2.1 of the License, or (at your option) any   ////
27//// later version.                                               ////
28////                                                              ////
29//// This source is distributed in the hope that it will be       ////
30//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
31//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
32//// PURPOSE.  See the GNU Lesser General Public License for more ////
33//// details.                                                     ////
34////                                                              ////
35//// You should have received a copy of the GNU Lesser General    ////
36//// Public License along with this source; if not, download it   ////
37//// from http://www.opencores.org/lgpl.shtml                     ////
38////                                                              ////
39//////////////////////////////////////////////////////////////////////
40//
41// CVS Revision History
42//
43// $Log: not supported by cvs2svn $
44// Revision 1.5  2002/11/19 17:37:32  mohor
45// When control frame (PAUSE) was sent, status was written in the
46// eth_wishbone module and both TXB and TXC interrupts were set. Fixed.
47// Only TXC interrupt is set.
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.1  2001/07/03 12:51:54  mohor
73// Initial release of the MAC Control module.
74//
75//
76//
77//
78//
79//
80
81
82`include "timescale.v"
83
84
85module eth_transmitcontrol (MTxClk, TxReset, TxUsedDataIn, TxUsedDataOut, TxDoneIn, TxAbortIn, 
86                            TxStartFrmIn, TPauseRq, TxUsedDataOutDetected, TxFlow, DlyCrcEn, 
87                            TxPauseTV, MAC, TxCtrlStartFrm, TxCtrlEndFrm, SendingCtrlFrm, CtrlMux, 
88                            ControlData, WillSendControlFrame, BlockTxDone
89                           );
90
91parameter Tp = 1;
92
93
94input         MTxClk;
95input         TxReset;
96input         TxUsedDataIn;
97input         TxUsedDataOut;
98input         TxDoneIn;
99input         TxAbortIn;
100input         TxStartFrmIn;
101input         TPauseRq;
102input         TxUsedDataOutDetected;
103input         TxFlow;
104input         DlyCrcEn;
105input  [15:0] TxPauseTV;
106input  [47:0] MAC;
107
108output        TxCtrlStartFrm;
109output        TxCtrlEndFrm;
110output        SendingCtrlFrm;
111output        CtrlMux;
112output [7:0]  ControlData;
113output        WillSendControlFrame;
114output        BlockTxDone;
115
116reg           SendingCtrlFrm;
117reg           CtrlMux;
118reg           WillSendControlFrame;
119reg    [3:0]  DlyCrcCnt;
120reg    [5:0]  ByteCnt;
121reg           ControlEnd_q;
122reg    [7:0]  MuxedCtrlData;
123reg           TxCtrlStartFrm;
124reg           TxCtrlStartFrm_q;
125reg           TxCtrlEndFrm;
126reg    [7:0]  ControlData;
127reg           TxUsedDataIn_q;
128reg           BlockTxDone;
129
130wire          IncrementDlyCrcCnt;
131wire          ResetByteCnt;
132wire          IncrementByteCnt;
133wire          ControlEnd;
134wire          IncrementByteCntBy2;
135wire          EnableCnt;
136
137
138// A command for Sending the control frame is active (latched)
139always @ (posedge MTxClk or posedge TxReset)
140begin
141  if(TxReset)
142    WillSendControlFrame <= #Tp 1'b0;
143  else
144  if(TxCtrlEndFrm & CtrlMux)
145    WillSendControlFrame <= #Tp 1'b0;
146  else
147  if(TPauseRq & TxFlow)
148    WillSendControlFrame <= #Tp 1'b1;
149end
150
151
152// Generation of the transmit control packet start frame
153always @ (posedge MTxClk or posedge TxReset)
154begin
155  if(TxReset)
156    TxCtrlStartFrm <= #Tp 1'b0;
157  else
158  if(TxUsedDataIn_q & CtrlMux)
159    TxCtrlStartFrm <= #Tp 1'b0;
160  else
161  if(WillSendControlFrame & ~TxUsedDataOut & (TxDoneIn | TxAbortIn | TxStartFrmIn | (~TxUsedDataOutDetected)))
162    TxCtrlStartFrm <= #Tp 1'b1;
163end
164
165
166
167// Generation of the transmit control packet end frame
168always @ (posedge MTxClk or posedge TxReset)
169begin
170  if(TxReset)
171    TxCtrlEndFrm <= #Tp 1'b0;
172  else
173  if(ControlEnd | ControlEnd_q)
174    TxCtrlEndFrm <= #Tp 1'b1;
175  else
176    TxCtrlEndFrm <= #Tp 1'b0;
177end
178
179
180// Generation of the multiplexer signal (controls muxes for switching between
181// normal and control packets)
182always @ (posedge MTxClk or posedge TxReset)
183begin
184  if(TxReset)
185    CtrlMux <= #Tp 1'b0;
186  else
187  if(WillSendControlFrame & ~TxUsedDataOut)
188    CtrlMux <= #Tp 1'b1;
189  else
190  if(TxDoneIn)
191    CtrlMux <= #Tp 1'b0;
192end
193
194
195
196// Generation of the Sending Control Frame signal (enables padding and CRC)
197always @ (posedge MTxClk or posedge TxReset)
198begin
199  if(TxReset)
200    SendingCtrlFrm <= #Tp 1'b0;
201  else
202  if(WillSendControlFrame & TxCtrlStartFrm)
203    SendingCtrlFrm <= #Tp 1'b1;
204  else
205  if(TxDoneIn)
206    SendingCtrlFrm <= #Tp 1'b0;
207end
208
209
210always @ (posedge MTxClk or posedge TxReset)
211begin
212  if(TxReset)
213    TxUsedDataIn_q <= #Tp 1'b0;
214  else
215    TxUsedDataIn_q <= #Tp TxUsedDataIn;
216end
217
218
219
220// Generation of the signal that will block sending the Done signal to the eth_wishbone module
221// While sending the control frame
222always @ (posedge MTxClk or posedge TxReset)
223begin
224  if(TxReset)
225    BlockTxDone <= #Tp 1'b0;
226  else
227  if(TxCtrlStartFrm)
228    BlockTxDone <= #Tp 1'b1;
229  else
230  if(TxStartFrmIn)
231    BlockTxDone <= #Tp 1'b0;
232end
233
234
235always @ (posedge MTxClk)
236begin
237  ControlEnd_q     <= #Tp ControlEnd;
238  TxCtrlStartFrm_q <= #Tp TxCtrlStartFrm;
239end
240
241
242assign IncrementDlyCrcCnt = CtrlMux & TxUsedDataIn &  ~DlyCrcCnt[2];
243
244
245// Delayed CRC counter
246always @ (posedge MTxClk or posedge TxReset)
247begin
248  if(TxReset)
249    DlyCrcCnt <= #Tp 4'h0;
250  else
251  if(ResetByteCnt)
252    DlyCrcCnt <= #Tp 4'h0;
253  else
254  if(IncrementDlyCrcCnt)
255    DlyCrcCnt <= #Tp DlyCrcCnt + 1'b1;
256end
257
258             
259assign ResetByteCnt = TxReset | (~TxCtrlStartFrm & (TxDoneIn | TxAbortIn));
260assign IncrementByteCnt = CtrlMux & (TxCtrlStartFrm & ~TxCtrlStartFrm_q & ~TxUsedDataIn | TxUsedDataIn & ~ControlEnd);
261assign IncrementByteCntBy2 = CtrlMux & TxCtrlStartFrm & (~TxCtrlStartFrm_q) & TxUsedDataIn;     // When TxUsedDataIn and CtrlMux are set at the same time
262
263assign EnableCnt = (~DlyCrcEn | DlyCrcEn & (&DlyCrcCnt[1:0]));
264// Byte counter
265always @ (posedge MTxClk or posedge TxReset)
266begin
267  if(TxReset)
268    ByteCnt <= #Tp 6'h0;
269  else
270  if(ResetByteCnt)
271    ByteCnt <= #Tp 6'h0;
272  else
273  if(IncrementByteCntBy2 & EnableCnt)
274    ByteCnt <= #Tp (ByteCnt[5:0] ) + 2'h2;
275  else
276  if(IncrementByteCnt & EnableCnt)
277    ByteCnt <= #Tp (ByteCnt[5:0] ) + 1'b1;
278end
279
280
281assign ControlEnd = ByteCnt[5:0] == 6'h22;
282
283
284// Control data generation (goes to the TxEthMAC module)
285always @ (ByteCnt or DlyCrcEn or MAC or TxPauseTV or DlyCrcCnt)
286begin
287  case(ByteCnt)
288    6'h0:    if(~DlyCrcEn | DlyCrcEn & (&DlyCrcCnt[1:0]))
289               MuxedCtrlData[7:0] = 8'h01;                   // Reserved Multicast Address
290             else
291                                                         MuxedCtrlData[7:0] = 8'h0;
292    6'h2:      MuxedCtrlData[7:0] = 8'h80;
293    6'h4:      MuxedCtrlData[7:0] = 8'hC2;
294    6'h6:      MuxedCtrlData[7:0] = 8'h00;
295    6'h8:      MuxedCtrlData[7:0] = 8'h00;
296    6'hA:      MuxedCtrlData[7:0] = 8'h01;
297    6'hC:      MuxedCtrlData[7:0] = MAC[47:40];
298    6'hE:      MuxedCtrlData[7:0] = MAC[39:32];
299    6'h10:     MuxedCtrlData[7:0] = MAC[31:24];
300    6'h12:     MuxedCtrlData[7:0] = MAC[23:16];
301    6'h14:     MuxedCtrlData[7:0] = MAC[15:8];
302    6'h16:     MuxedCtrlData[7:0] = MAC[7:0];
303    6'h18:     MuxedCtrlData[7:0] = 8'h88;                   // Type/Length
304    6'h1A:     MuxedCtrlData[7:0] = 8'h08;
305    6'h1C:     MuxedCtrlData[7:0] = 8'h00;                   // Opcode
306    6'h1E:     MuxedCtrlData[7:0] = 8'h01;
307    6'h20:     MuxedCtrlData[7:0] = TxPauseTV[15:8];         // Pause timer value
308    6'h22:     MuxedCtrlData[7:0] = TxPauseTV[7:0];
309    default:   MuxedCtrlData[7:0] = 8'h0;
310  endcase
311end
312
313
314// Latched Control data
315always @ (posedge MTxClk or posedge TxReset)
316begin
317  if(TxReset)
318    ControlData[7:0] <= #Tp 8'h0;
319  else
320  if(~ByteCnt[0])
321    ControlData[7:0] <= #Tp MuxedCtrlData[7:0];
322end
323
324
325
326endmodule
Note: See TracBrowser for help on using the repository browser.