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 218

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

powered by: WebSVN 2.1.0

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