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 240

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

powered by: WebSVN 2.1.0

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