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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_7/] [rtl/] [verilog/] [eth_top.v] - Blame information for rev 95

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

powered by: WebSVN 2.1.0

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