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 149

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

powered by: WebSVN 2.1.0

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