OpenCores
URL https://opencores.org/ocsvn/ethmac/ethmac/trunk

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_7/] [rtl/] [verilog/] [eth_top.v] - Blame information for rev 106

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

powered by: WebSVN 2.1.0

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