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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_4/] [rtl/] [verilog/] [eth_top.v] - Blame information for rev 68

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

Line No. Rev Author Line
1 15 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_top.v                                                   ////
4
////                                                              ////
5
////  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
////                                                              ////
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 68 mohor
// Revision 1.18  2002/02/16 13:06:33  mohor
45
// EXTERNAL_DMA used instead of WISHBONE_DMA.
46
//
47 67 mohor
// Revision 1.17  2002/02/16 07:15:27  mohor
48
// Testbench fixed, code simplified, unused signals removed.
49
//
50 65 mohor
// Revision 1.16  2002/02/15 13:49:39  mohor
51
// RxAbort is connected differently.
52
//
53 63 mohor
// Revision 1.15  2002/02/15 11:38:26  mohor
54
// Changes that were lost when updating from 1.11 to 1.14 fixed.
55
//
56 59 mohor
// Revision 1.14  2002/02/14 20:19:11  billditt
57
// Modified for Address Checking,
58
// addition of eth_addrcheck.v
59
//
60
// Revision 1.13  2002/02/12 17:03:03  mohor
61
// HASH0 and HASH1 registers added. Registers address width was
62
// changed to 8 bits.
63
//
64
// Revision 1.12  2002/02/11 09:18:22  mohor
65
// Tx status is written back to the BD.
66
//
67 43 mohor
// Revision 1.11  2002/02/08 16:21:54  mohor
68
// Rx status is written back to the BD.
69
//
70 42 mohor
// Revision 1.10  2002/02/06 14:10:21  mohor
71
// non-DMA host interface added. Select the right configutation in eth_defines.
72
//
73 41 mohor
// Revision 1.9  2002/01/23 10:28:16  mohor
74
// Link in the header changed.
75
//
76 37 mohor
// Revision 1.8  2001/12/05 15:00:16  mohor
77
// RX_BD_NUM changed to TX_BD_NUM (holds number of TX descriptors
78
// instead of the number of RX descriptors).
79
//
80 34 mohor
// Revision 1.7  2001/12/05 10:45:59  mohor
81
// ETH_RX_BD_ADR register deleted. ETH_RX_BD_NUM is used instead.
82
//
83 33 mohor
// Revision 1.6  2001/10/19 11:24:29  mohor
84
// Number of addresses (wb_adr_i) minimized.
85
//
86 23 mohor
// Revision 1.5  2001/10/19 08:43:51  mohor
87
// eth_timescale.v changed to timescale.v This is done because of the
88
// simulation of the few cores in a one joined project.
89
//
90 22 mohor
// Revision 1.4  2001/10/18 12:07:11  mohor
91
// Status signals changed, Adress decoding changed, interrupt controller
92
// added.
93
//
94 21 mohor
// Revision 1.3  2001/09/24 15:02:56  mohor
95
// Defines changed (All precede with ETH_). Small changes because some
96
// tools generate warnings when two operands are together. Synchronization
97
// between two clocks domains in eth_wishbonedma.v is changed (due to ASIC
98
// demands).
99
//
100 20 mohor
// Revision 1.2  2001/08/15 14:03:59  mohor
101
// Signal names changed on the top level for easier pad insertion (ASIC).
102
//
103 17 mohor
// Revision 1.1  2001/08/06 14:44:29  mohor
104
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
105
// Include files fixed to contain no path.
106
// File names and module names changed ta have a eth_ prologue in the name.
107
// File eth_timescale.v is used to define timescale
108
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
109
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
110
// and Mdo_OE. The bidirectional signal must be created on the top level. This
111
// is done due to the ASIC tools.
112
//
113 15 mohor
// Revision 1.2  2001/08/02 09:25:31  mohor
114
// Unconnected signals are now connected.
115
//
116
// Revision 1.1  2001/07/30 21:23:42  mohor
117
// Directory structure changed. Files checked and joind together.
118
//
119
//
120
//
121 20 mohor
// 
122 15 mohor
 
123
 
124
`include "eth_defines.v"
125 22 mohor
`include "timescale.v"
126 15 mohor
 
127
 
128
module eth_top
129
(
130
  // WISHBONE common
131 17 mohor
  wb_clk_i, wb_rst_i, wb_dat_i, wb_dat_o,
132 15 mohor
 
133
  // WISHBONE slave
134 17 mohor
  wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i, wb_stb_i, wb_ack_o, wb_err_o,
135 41 mohor
  wb_ack_i,
136 15 mohor
 
137 67 mohor
`ifdef EXTERNAL_DMA
138 41 mohor
  wb_req_o, wb_nd_o, wb_rd_o,
139
`else
140
  // WISHBONE master
141
  m_wb_adr_o, m_wb_sel_o, m_wb_we_o,
142
  m_wb_dat_o, m_wb_dat_i, m_wb_cyc_o,
143
  m_wb_stb_o, m_wb_ack_i, m_wb_err_i,
144
`endif
145
 
146 15 mohor
  //TX
147 20 mohor
  mtx_clk_pad_i, mtxd_pad_o, mtxen_pad_o, mtxerr_pad_o,
148 15 mohor
 
149
  //RX
150 20 mohor
  mrx_clk_pad_i, mrxd_pad_i, mrxdv_pad_i, mrxerr_pad_i, mcoll_pad_i, mcrs_pad_i,
151 15 mohor
 
152
  // MIIM
153 21 mohor
  mdc_pad_o, md_pad_i, md_pad_o, md_padoen_o,
154 17 mohor
 
155 21 mohor
  int_o
156 17 mohor
 
157 21 mohor
 
158 15 mohor
);
159
 
160
 
161
parameter Tp = 1;
162
 
163
 
164
// WISHBONE common
165 17 mohor
input           wb_clk_i;     // WISHBONE clock
166
input           wb_rst_i;     // WISHBONE reset
167
input   [31:0]  wb_dat_i;     // WISHBONE data input
168
output  [31:0]  wb_dat_o;     // WISHBONE data output
169
output          wb_err_o;     // WISHBONE error output
170 15 mohor
 
171
// WISHBONE slave
172 23 mohor
input   [11:2]  wb_adr_i;     // WISHBONE address input
173 17 mohor
input    [3:0]  wb_sel_i;     // WISHBONE byte select input
174
input           wb_we_i;      // WISHBONE write enable input
175
input           wb_cyc_i;     // WISHBONE cycle input
176
input           wb_stb_i;     // WISHBONE strobe input
177
output          wb_ack_o;     // WISHBONE acknowledge output
178 15 mohor
 
179 67 mohor
`ifdef EXTERNAL_DMA
180 15 mohor
// DMA
181 17 mohor
output   [1:0]  wb_req_o;     // DMA request output
182
output   [1:0]  wb_nd_o;      // DMA force new descriptor output
183
output          wb_rd_o;      // DMA restart descriptor output
184 41 mohor
`else
185
// WISHBONE master
186
output  [31:0]  m_wb_adr_o;
187
output   [3:0]  m_wb_sel_o;
188
output          m_wb_we_o;
189
input   [31:0]  m_wb_dat_i;
190
output  [31:0]  m_wb_dat_o;
191
output          m_wb_cyc_o;
192
output          m_wb_stb_o;
193
input           m_wb_ack_i;
194
input           m_wb_err_i;
195
`endif
196 15 mohor
 
197 41 mohor
input    [1:0]  wb_ack_i;     // DMA acknowledge input
198
 
199 15 mohor
// Tx
200 20 mohor
input           mtx_clk_pad_i; // Transmit clock (from PHY)
201 21 mohor
output   [3:0]  mtxd_pad_o;    // Transmit nibble (to PHY)
202
output          mtxen_pad_o;   // Transmit enable (to PHY)
203
output          mtxerr_pad_o;  // Transmit error (to PHY)
204 15 mohor
 
205
// Rx
206 20 mohor
input           mrx_clk_pad_i; // Receive clock (from PHY)
207 21 mohor
input    [3:0]  mrxd_pad_i;    // Receive nibble (from PHY)
208
input           mrxdv_pad_i;   // Receive data valid (from PHY)
209
input           mrxerr_pad_i;  // Receive data error (from PHY)
210 15 mohor
 
211
// Common Tx and Rx
212 21 mohor
input           mcoll_pad_i;   // Collision (from PHY)
213
input           mcrs_pad_i;    // Carrier sense (from PHY)
214 15 mohor
 
215
// MII Management interface
216 21 mohor
input           md_pad_i;      // MII data input (from I/O cell)
217
output          mdc_pad_o;     // MII Management data clock (to PHY)
218
output          md_pad_o;      // MII data output (to I/O cell)
219
output          md_padoen_o;   // MII data output enable (to I/O cell)
220 15 mohor
 
221 21 mohor
output          int_o;         // Interrupt output
222 15 mohor
 
223
wire     [7:0]  r_ClkDiv;
224
wire            r_MiiNoPre;
225
wire    [15:0]  r_CtrlData;
226
wire     [4:0]  r_FIAD;
227
wire     [4:0]  r_RGAD;
228
wire            r_WCtrlData;
229
wire            r_RStat;
230
wire            r_ScanStat;
231
wire            NValid_stat;
232
wire            Busy_stat;
233
wire            LinkFail;
234
wire            r_MiiMRst;
235
wire    [15:0]  Prsd;             // Read Status Data (data read from the PHY)
236
wire            WCtrlDataStart;
237
wire            RStatStart;
238
wire            UpdateMIIRX_DATAReg;
239
 
240
wire            TxStartFrm;
241
wire            TxEndFrm;
242
wire            TxUsedData;
243
wire     [7:0]  TxData;
244
wire            TxRetry;
245
wire            TxAbort;
246
wire            TxUnderRun;
247
wire            TxDone;
248 42 mohor
wire     [5:0]  CollValid;
249 15 mohor
 
250
 
251
 
252
 
253
// Connecting Miim module
254
eth_miim miim1
255
(
256 17 mohor
  .Clk(wb_clk_i),                         .Reset(r_MiiMRst),                  .Divider(r_ClkDiv),
257 15 mohor
  .NoPre(r_MiiNoPre),                     .CtrlData(r_CtrlData),              .Rgad(r_RGAD),
258
  .Fiad(r_FIAD),                          .WCtrlData(r_WCtrlData),            .RStat(r_RStat),
259 17 mohor
  .ScanStat(r_ScanStat),                  .Mdi(md_pad_i),                     .Mdo(md_pad_o),
260 23 mohor
  .MdoEn(md_padoen_o),                    .Mdc(mdc_pad_o),                    .Busy(Busy_stat),
261 15 mohor
  .Prsd(Prsd),                            .LinkFail(LinkFail),                .Nvalid(NValid_stat),
262
  .WCtrlDataStart(WCtrlDataStart),        .RStatStart(RStatStart),            .UpdateMIIRX_DATAReg(UpdateMIIRX_DATAReg)
263
);
264
 
265
 
266
 
267
 
268
wire        RegCs;          // Connected to registers
269 17 mohor
wire [31:0] RegDataOut;     // Multiplexed to wb_dat_o
270 42 mohor
wire        r_RecSmall;     // Receive small frames
271 15 mohor
wire        r_Rst;          // Reset
272
wire        r_LoopBck;      // Loopback
273
wire        r_TxEn;         // Tx Enable
274
wire        r_RxEn;         // Rx Enable
275
 
276
wire        MRxDV_Lb;       // Muxed MII receive data valid
277
wire        MRxErr_Lb;      // Muxed MII Receive Error
278
wire  [3:0] MRxD_Lb;        // Muxed MII Receive Data
279
wire        Transmitting;   // Indication that TxEthMAC is transmitting
280
wire        r_HugEn;        // Huge packet enable
281
wire        r_DlyCrcEn;     // Delayed CRC enabled
282
wire [15:0] r_MaxFL;        // Maximum frame length
283
 
284
wire [15:0] r_MinFL;        // Minimum frame length
285 42 mohor
wire        ShortFrame;
286
wire        DribbleNibble;  // Extra nibble received
287
wire        ReceivedPacketTooBig; // Received packet is too big
288 15 mohor
wire [47:0] r_MAC;          // MAC address
289 42 mohor
wire        LoadRxStatus;   // Rx status was loaded
290 52 billditt
wire [31:0] r_HASH0;        // HASH table, lower 4 bytes
291
wire [31:0] r_HASH1;        // HASH table, upper 4 bytes
292 34 mohor
wire  [7:0] r_TxBDNum;      // Receive buffer descriptor number
293 15 mohor
wire  [6:0] r_IPGT;         // 
294
wire  [6:0] r_IPGR1;        // 
295
wire  [6:0] r_IPGR2;        // 
296
wire  [5:0] r_CollValid;    // 
297
wire        r_TPauseRq;     // Transmit PAUSE request pulse
298
 
299
wire  [3:0] r_MaxRet;       //
300
wire        r_NoBckof;      // 
301
wire        r_ExDfrEn;      // 
302 34 mohor
wire        TX_BD_NUM_Wr;   // Write enable that writes RX_BD_NUM to the registers.
303 15 mohor
wire        TPauseRq;       // Sinhronized Tx PAUSE request
304
wire [15:0] TxPauseTV;      // Tx PAUSE timer value
305
wire        r_TxFlow;       // Tx flow control enable
306
wire        r_IFG;          // Minimum interframe gap for incoming packets
307
 
308 21 mohor
wire        TxB_IRQ;        // Interrupt Tx Buffer
309
wire        TxE_IRQ;        // Interrupt Tx Error
310
wire        RxB_IRQ;        // Interrupt Rx Buffer
311
wire        RxF_IRQ;        // Interrupt Rx Frame
312
wire        Busy_IRQ;       // Interrupt Busy (lack of buffers)
313 15 mohor
 
314
wire        DWord;
315
wire        BDAck;
316 17 mohor
wire [31:0] DMA_WB_DAT_O;   // wb_dat_o that comes from the WishboneDMA module
317 21 mohor
wire        BDCs;           // Buffer descriptor CS
318 15 mohor
 
319
 
320 17 mohor
assign DWord = &wb_sel_i;
321 23 mohor
assign RegCs = wb_stb_i & wb_cyc_i & DWord & ~wb_adr_i[11] & ~wb_adr_i[10];
322
assign BDCs  = wb_stb_i & wb_cyc_i & DWord & ~wb_adr_i[11] &  wb_adr_i[10];
323 21 mohor
assign wb_ack_o = RegCs | BDAck;
324
assign wb_err_o = wb_stb_i & wb_cyc_i & ~DWord;
325 15 mohor
 
326
 
327
// Selecting the WISHBONE output data
328 17 mohor
assign wb_dat_o[31:0] = (RegCs & ~wb_we_i)? RegDataOut : DMA_WB_DAT_O;
329 15 mohor
 
330
 
331
// Connecting Ethernet registers
332
eth_registers ethreg1
333
(
334 47 mohor
  .DataIn(wb_dat_i),                      .Address(wb_adr_i[9:2]),                    .Rw(wb_we_i),
335 17 mohor
  .Cs(RegCs),                             .Clk(wb_clk_i),                             .Reset(wb_rst_i),
336 68 mohor
  .DataOut(RegDataOut),                   .r_RecSmall(r_RecSmall),
337 15 mohor
  .r_Pad(r_Pad),                          .r_HugEn(r_HugEn),                          .r_CrcEn(r_CrcEn),
338
  .r_DlyCrcEn(r_DlyCrcEn),                .r_Rst(r_Rst),                              .r_FullD(r_FullD),
339
  .r_ExDfrEn(r_ExDfrEn),                  .r_NoBckof(r_NoBckof),                      .r_LoopBck(r_LoopBck),
340 52 billditt
  .r_IFG(r_IFG),                          .r_Pro(r_Pro),                              .r_Iam(),
341
  .r_Bro(r_Bro),                          .r_NoPre(r_NoPre),                          .r_TxEn(r_TxEn),
342 21 mohor
  .r_RxEn(r_RxEn),                        .Busy_IRQ(Busy_IRQ),                        .RxF_IRQ(RxF_IRQ),
343
  .RxB_IRQ(RxB_IRQ),                      .TxE_IRQ(TxE_IRQ),                          .TxB_IRQ(TxB_IRQ),
344
  .r_IPGT(r_IPGT),
345 15 mohor
  .r_IPGR1(r_IPGR1),                      .r_IPGR2(r_IPGR2),                          .r_MinFL(r_MinFL),
346
  .r_MaxFL(r_MaxFL),                      .r_MaxRet(r_MaxRet),                        .r_CollValid(r_CollValid),
347
  .r_TxFlow(r_TxFlow),                    .r_RxFlow(r_RxFlow),                        .r_PassAll(r_PassAll),
348
  .r_MiiMRst(r_MiiMRst),                  .r_MiiNoPre(r_MiiNoPre),                    .r_ClkDiv(r_ClkDiv),
349
  .r_WCtrlData(r_WCtrlData),              .r_RStat(r_RStat),                          .r_ScanStat(r_ScanStat),
350
  .r_RGAD(r_RGAD),                        .r_FIAD(r_FIAD),                            .r_CtrlData(r_CtrlData),
351
  .NValid_stat(NValid_stat),              .Busy_stat(Busy_stat),
352
  .LinkFail(LinkFail),                    .r_MAC(r_MAC),                              .WCtrlDataStart(WCtrlDataStart),
353
  .RStatStart(RStatStart),                .UpdateMIIRX_DATAReg(UpdateMIIRX_DATAReg),  .Prsd(Prsd),
354 47 mohor
  .r_TxBDNum(r_TxBDNum),                  .TX_BD_NUM_Wr(TX_BD_NUM_Wr),                .int_o(int_o),
355 52 billditt
  .r_HASH0(r_HASH0),                      .r_HASH1(r_HASH1)
356 15 mohor
);
357
 
358
 
359
 
360
wire  [7:0] RxData;
361
wire        RxValid;
362
wire        RxStartFrm;
363
wire        RxEndFrm;
364 41 mohor
wire        RxAbort;
365 15 mohor
 
366
wire        WillTransmit;            // Will transmit (to RxEthMAC)
367
wire        ResetCollision;          // Reset Collision (for synchronizing collision)
368
wire  [7:0] TxDataOut;               // Transmit Packet Data (to TxEthMAC)
369
wire        WillSendControlFrame;
370
wire        TxCtrlEndFrm;
371
wire        ReceivedPauseFrm;
372
wire        ReceiveEnd;
373
wire        ReceivedPacketGood;
374
wire        ReceivedLengthOK;
375 42 mohor
wire        InvalidSymbol;
376
wire        LatchedCrcError;
377
wire        RxLateCollision;
378 59 mohor
wire  [3:0] RetryCntLatched;
379
wire  [3:0] RetryCnt;
380
wire        StartTxDone;
381
wire        StartTxAbort;
382
wire        MaxCollisionOccured;
383
wire        RetryLimit;
384
wire        StatePreamble;
385
wire  [1:0] StateData;
386 15 mohor
 
387
// Connecting MACControl
388
eth_maccontrol maccontrol1
389
(
390 41 mohor
  .MTxClk(mtx_clk_pad_i),                       .TPauseRq(TPauseRq),
391 15 mohor
  .TxPauseTV(TxPauseTV),                        .TxDataIn(TxData),
392
  .TxStartFrmIn(TxStartFrm),                    .TxEndFrmIn(TxEndFrm),
393
  .TxUsedDataIn(TxUsedDataIn),                  .TxDoneIn(TxDoneIn),
394 20 mohor
  .TxAbortIn(TxAbortIn),                        .MRxClk(mrx_clk_pad_i),
395 15 mohor
  .RxData(RxData),                              .RxValid(RxValid),
396
  .RxStartFrm(RxStartFrm),                      .RxEndFrm(RxEndFrm),
397
  .ReceiveEnd(ReceiveEnd),                      .ReceivedPacketGood(ReceivedPacketGood),
398
  .PassAll(r_PassAll),                          .TxFlow(r_TxFlow),
399
  .RxFlow(r_RxFlow),                            .DlyCrcEn(r_DlyCrcEn),
400
  .MAC(r_MAC),                                  .PadIn(r_Pad | PerPacketPad),
401
  .PadOut(PadOut),                              .CrcEnIn(r_CrcEn | PerPacketCrcEn),
402
  .CrcEnOut(CrcEnOut),                          .TxReset(r_Rst),
403
  .RxReset(r_Rst),                              .ReceivedLengthOK(ReceivedLengthOK),
404
  .TxDataOut(TxDataOut),                        .TxStartFrmOut(TxStartFrmOut),
405
  .TxEndFrmOut(TxEndFrmOut),                    .TxUsedDataOut(TxUsedData),
406
  .TxDoneOut(TxDone),                           .TxAbortOut(TxAbort),
407
  .WillSendControlFrame(WillSendControlFrame),  .TxCtrlEndFrm(TxCtrlEndFrm),
408
  .ReceivedPauseFrm(ReceivedPauseFrm)
409
);
410
 
411
 
412
 
413
wire TxCarrierSense;          // Synchronized CarrierSense (to Tx clock)
414
wire Collision;               // Synchronized Collision
415
 
416
reg CarrierSense_Tx1;
417
reg CarrierSense_Tx2;
418
reg Collision_Tx1;
419
reg Collision_Tx2;
420
 
421
reg RxEnSync;                 // Synchronized Receive Enable
422
reg CarrierSense_Rx1;
423
reg RxCarrierSense;           // Synchronized CarrierSense (to Rx clock)
424
reg WillTransmit_q;
425
reg WillTransmit_q2;
426
 
427
 
428
 
429
// Muxed MII receive data valid
430 17 mohor
assign MRxDV_Lb = r_LoopBck? mtxen_pad_o : mrxdv_pad_i & RxEnSync;
431 15 mohor
 
432
// Muxed MII Receive Error
433 17 mohor
assign MRxErr_Lb = r_LoopBck? mtxerr_pad_o : mrxerr_pad_i & RxEnSync;
434 15 mohor
 
435
// Muxed MII Receive Data
436 17 mohor
assign MRxD_Lb[3:0] = r_LoopBck? mtxd_pad_o[3:0] : mrxd_pad_i[3:0];
437 15 mohor
 
438
 
439
 
440
// Connecting TxEthMAC
441
eth_txethmac txethmac1
442
(
443 21 mohor
  .MTxClk(mtx_clk_pad_i),             .Reset(r_Rst),                      .CarrierSense(TxCarrierSense),
444 15 mohor
  .Collision(Collision),              .TxData(TxDataOut),                 .TxStartFrm(TxStartFrmOut),
445
  .TxUnderRun(TxUnderRun),            .TxEndFrm(TxEndFrmOut),             .Pad(PadOut),
446
  .MinFL(r_MinFL),                    .CrcEn(CrcEnOut),                   .FullD(r_FullD),
447
  .HugEn(r_HugEn),                    .DlyCrcEn(r_DlyCrcEn),              .IPGT(r_IPGT),
448
  .IPGR1(r_IPGR1),                    .IPGR2(r_IPGR2),                    .CollValid(r_CollValid),
449
  .MaxRet(r_MaxRet),                  .NoBckof(r_NoBckof),                .ExDfrEn(r_ExDfrEn),
450 17 mohor
  .MaxFL(r_MaxFL),                    .MTxEn(mtxen_pad_o),                .MTxD(mtxd_pad_o),
451
  .MTxErr(mtxerr_pad_o),              .TxUsedData(TxUsedDataIn),          .TxDone(TxDoneIn),
452 15 mohor
  .TxRetry(TxRetry),                  .TxAbort(TxAbortIn),                .WillTransmit(WillTransmit),
453 59 mohor
  .ResetCollision(ResetCollision),    .RetryCnt(RetryCnt),                .StartTxDone(StartTxDone),
454
  .StartTxAbort(StartTxAbort),        .MaxCollisionOccured(MaxCollisionOccured), .LateCollision(LateCollision),
455
  .StartDefer(StartDefer),            .StatePreamble(StatePreamble),      .StateData(StateData)
456 15 mohor
);
457
 
458
 
459
 
460
 
461
wire  [15:0]  RxByteCnt;
462
wire          RxByteCntEq0;
463
wire          RxByteCntGreat2;
464
wire          RxByteCntMaxFrame;
465
wire          RxCrcError;
466
wire          RxStateIdle;
467
wire          RxStatePreamble;
468
wire          RxStateSFD;
469
wire   [1:0]  RxStateData;
470
 
471
 
472
 
473
 
474
// Connecting RxEthMAC
475
eth_rxethmac rxethmac1
476
(
477 21 mohor
  .MRxClk(mrx_clk_pad_i),               .MRxDV(MRxDV_Lb),                     .MRxD(MRxD_Lb),
478 15 mohor
  .Transmitting(Transmitting),          .HugEn(r_HugEn),                      .DlyCrcEn(r_DlyCrcEn),
479
  .MaxFL(r_MaxFL),                      .r_IFG(r_IFG),                        .Reset(r_Rst),
480
  .RxData(RxData),                      .RxValid(RxValid),                    .RxStartFrm(RxStartFrm),
481 65 mohor
  .RxEndFrm(RxEndFrm),                  .ByteCnt(RxByteCnt),
482 15 mohor
  .ByteCntEq0(RxByteCntEq0),            .ByteCntGreat2(RxByteCntGreat2),      .ByteCntMaxFrame(RxByteCntMaxFrame),
483
  .CrcError(RxCrcError),                .StateIdle(RxStateIdle),              .StatePreamble(RxStatePreamble),
484 52 billditt
  .StateSFD(RxStateSFD),                .StateData(RxStateData),
485 63 mohor
  .MAC(r_MAC),                          .r_Pro(r_Pro),                        .r_Bro(r_Bro),
486
  .r_HASH0(r_HASH0),                    .r_HASH1(r_HASH1),                    .RxAbort(RxAbort)
487 15 mohor
);
488
 
489
 
490
// MII Carrier Sense Synchronization
491 20 mohor
always @ (posedge mtx_clk_pad_i or posedge r_Rst)
492 15 mohor
begin
493
  if(r_Rst)
494
    begin
495
      CarrierSense_Tx1 <= #Tp 1'b0;
496
      CarrierSense_Tx2 <= #Tp 1'b0;
497
    end
498
  else
499
    begin
500 17 mohor
      CarrierSense_Tx1 <= #Tp mcrs_pad_i;
501 15 mohor
      CarrierSense_Tx2 <= #Tp CarrierSense_Tx1;
502
    end
503
end
504
 
505
assign TxCarrierSense = ~r_FullD & CarrierSense_Tx2;
506
 
507
 
508
// MII Collision Synchronization
509 20 mohor
always @ (posedge mtx_clk_pad_i or posedge r_Rst)
510 15 mohor
begin
511
  if(r_Rst)
512
    begin
513
      Collision_Tx1 <= #Tp 1'b0;
514
      Collision_Tx2 <= #Tp 1'b0;
515
    end
516
  else
517
    begin
518 17 mohor
      Collision_Tx1 <= #Tp mcoll_pad_i;
519 15 mohor
      if(ResetCollision)
520
        Collision_Tx2 <= #Tp 1'b0;
521
      else
522
      if(Collision_Tx1)
523
        Collision_Tx2 <= #Tp 1'b1;
524
    end
525
end
526
 
527
 
528
// Synchronized Collision
529
assign Collision = ~r_FullD & Collision_Tx2;
530
 
531
 
532
 
533
// Carrier sense is synchronized to receive clock.
534 20 mohor
always @ (posedge mrx_clk_pad_i or posedge r_Rst)
535 15 mohor
begin
536
  if(r_Rst)
537
    begin
538
      CarrierSense_Rx1 <= #Tp 1'h0;
539
      RxCarrierSense <= #Tp 1'h0;
540
    end
541
  else
542
    begin
543 17 mohor
      CarrierSense_Rx1 <= #Tp mcrs_pad_i;
544 15 mohor
      RxCarrierSense <= #Tp CarrierSense_Rx1;
545
    end
546
end
547
 
548
 
549
// Delayed WillTransmit
550 20 mohor
always @ (posedge mrx_clk_pad_i)
551 15 mohor
begin
552
  WillTransmit_q <= #Tp WillTransmit;
553
  WillTransmit_q2 <= #Tp WillTransmit_q;
554
end
555
 
556
 
557
assign Transmitting = ~r_FullD & WillTransmit_q2;
558
 
559
 
560
 
561
// Synchronized Receive Enable
562 20 mohor
always @ (posedge mrx_clk_pad_i or posedge r_Rst)
563 15 mohor
begin
564
  if(r_Rst)
565
    RxEnSync <= #Tp 1'b0;
566
  else
567
  if(~RxCarrierSense | RxCarrierSense & Transmitting)
568
    RxEnSync <= #Tp r_RxEn;
569
end
570
 
571
 
572
 
573
 
574
// Connecting WishboneDMA module
575 67 mohor
`ifdef EXTERNAL_DMA
576 41 mohor
eth_wishbonedma wishbone
577
`else
578
eth_wishbone wishbone
579
`endif
580 15 mohor
(
581 41 mohor
  .WB_CLK_I(wb_clk_i),                .WB_DAT_I(wb_dat_i),
582 15 mohor
  .WB_DAT_O(DMA_WB_DAT_O),
583
 
584
  // WISHBONE slave
585 23 mohor
  .WB_ADR_I(wb_adr_i[9:2]),           .WB_SEL_I(wb_sel_i),                      .WB_WE_I(wb_we_i),
586 21 mohor
  .BDCs(BDCs),                        .WB_ACK_O(BDAck),
587 15 mohor
 
588 41 mohor
  .Reset(wb_rst_i),
589
 
590 67 mohor
`ifdef EXTERNAL_DMA
591 41 mohor
  .WB_REQ_O(wb_req_o),                .WB_ND_O(wb_nd_o),                        .WB_RD_O(wb_rd_o),
592
  .WB_ACK_I(wb_ack_i),
593
`else
594
  // WISHBONE master
595
  .m_wb_adr_o(m_wb_adr_o),            .m_wb_sel_o(m_wb_sel_o),                  .m_wb_we_o(m_wb_we_o),
596
  .m_wb_dat_i(m_wb_dat_i),            .m_wb_dat_o(m_wb_dat_o),                  .m_wb_cyc_o(m_wb_cyc_o),
597
  .m_wb_stb_o(m_wb_stb_o),            .m_wb_ack_i(m_wb_ack_i),                  .m_wb_err_i(m_wb_err_i),
598
`endif
599
 
600
 
601
 
602 15 mohor
    //TX
603 21 mohor
  .MTxClk(mtx_clk_pad_i),             .TxStartFrm(TxStartFrm),                  .TxEndFrm(TxEndFrm),
604 59 mohor
  .TxUsedData(TxUsedData),            .TxData(TxData),
605 15 mohor
  .TxRetry(TxRetry),                  .TxAbort(TxAbort),                        .TxUnderRun(TxUnderRun),
606
  .TxDone(TxDone),                    .TPauseRq(TPauseRq),                      .TxPauseTV(TxPauseTV),
607
  .PerPacketCrcEn(PerPacketCrcEn),    .PerPacketPad(PerPacketPad),              .WillSendControlFrame(WillSendControlFrame),
608
  .TxCtrlEndFrm(TxCtrlEndFrm),
609
 
610
  // Register
611 34 mohor
  .r_TxEn(r_TxEn),                    .r_RxEn(r_RxEn),                          .r_TxBDNum(r_TxBDNum),
612 68 mohor
  .r_DmaEn(1'b1),                     .TX_BD_NUM_Wr(TX_BD_NUM_Wr),              .r_RecSmall(r_RecSmall),
613 15 mohor
 
614
  //RX
615 21 mohor
  .MRxClk(mrx_clk_pad_i),             .RxData(RxData),                          .RxValid(RxValid),
616 41 mohor
  .RxStartFrm(RxStartFrm),            .RxEndFrm(RxEndFrm),
617 21 mohor
  .Busy_IRQ(Busy_IRQ),                .RxF_IRQ(RxF_IRQ),                        .RxB_IRQ(RxB_IRQ),
618 42 mohor
  .TxE_IRQ(TxE_IRQ),                  .TxB_IRQ(TxB_IRQ),
619 21 mohor
 
620 67 mohor
`ifdef EXTERNAL_DMA
621 41 mohor
`else
622 42 mohor
  .RxAbort(RxAbort),
623 41 mohor
`endif
624
 
625 42 mohor
  .InvalidSymbol(InvalidSymbol),      .LatchedCrcError(LatchedCrcError),        .RxLength(RxByteCnt),
626
  .RxLateCollision(RxLateCollision),  .ShortFrame(ShortFrame),                  .DribbleNibble(DribbleNibble),
627 59 mohor
  .ReceivedPacketTooBig(ReceivedPacketTooBig), .LoadRxStatus(LoadRxStatus),     .RetryCntLatched(RetryCntLatched),
628
  .RetryLimit(RetryLimit),            .LateCollLatched(LateCollLatched),        .DeferLatched(DeferLatched),
629
  .CarrierSenseLost(CarrierSenseLost)
630
 
631
 
632
 
633 15 mohor
);
634
 
635
 
636
 
637
// Connecting MacStatus module
638
eth_macstatus macstatus1
639
(
640 42 mohor
  .MRxClk(mrx_clk_pad_i),             .Reset(r_Rst),
641
  .ReceiveEnd(ReceiveEnd),            .ReceivedPacketGood(ReceivedPacketGood),     .ReceivedLengthOK(ReceivedLengthOK),
642
  .RxCrcError(RxCrcError),            .MRxErr(MRxErr_Lb),                          .MRxDV(MRxDV_Lb),
643
  .RxStateSFD(RxStateSFD),            .RxStateData(RxStateData),                   .RxStatePreamble(RxStatePreamble),
644
  .RxStateIdle(RxStateIdle),          .Transmitting(Transmitting),                 .RxByteCnt(RxByteCnt),
645
  .RxByteCntEq0(RxByteCntEq0),        .RxByteCntGreat2(RxByteCntGreat2),           .RxByteCntMaxFrame(RxByteCntMaxFrame),
646
  .ReceivedPauseFrm(ReceivedPauseFrm),.InvalidSymbol(InvalidSymbol),
647
  .MRxD(MRxD_Lb),                     .LatchedCrcError(LatchedCrcError),           .Collision(mcoll_pad_i),
648
  .CollValid(r_CollValid),            .RxLateCollision(RxLateCollision),           .r_RecSmall(r_RecSmall),
649
  .r_MinFL(r_MinFL),                  .r_MaxFL(r_MaxFL),                           .ShortFrame(ShortFrame),
650
  .DribbleNibble(DribbleNibble),      .ReceivedPacketTooBig(ReceivedPacketTooBig), .r_HugEn(r_HugEn),
651 59 mohor
  .LoadRxStatus(LoadRxStatus),        .RetryCnt(RetryCnt),                         .StartTxDone(StartTxDone),
652
  .StartTxAbort(StartTxAbort),        .RetryCntLatched(RetryCntLatched),           .MTxClk(mtx_clk_pad_i),
653
  .MaxCollisionOccured(MaxCollisionOccured), .RetryLimit(RetryLimit),              .LateCollision(LateCollision),
654
  .LateCollLatched(LateCollLatched),  .StartDefer(StartDefer),                     .DeferLatched(DeferLatched),
655
  .TxStartFrm(TxStartFrmOut),         .StatePreamble(StatePreamble),               .StateData(StateData),
656
  .CarrierSense(CarrierSense_Tx2),    .CarrierSenseLost(CarrierSenseLost),         .TxUsedData(TxUsedDataIn)
657 15 mohor
);
658
 
659
 
660
endmodule

powered by: WebSVN 2.1.0

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