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 248

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

powered by: WebSVN 2.1.0

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