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 214

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

powered by: WebSVN 2.1.0

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