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 103

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

powered by: WebSVN 2.1.0

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