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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_17/] [rtl/] [verilog/] [eth_top.v] - Blame information for rev 255

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

powered by: WebSVN 2.1.0

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