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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [runing_under_uclinux/] [rtl/] [verilog/] [eth_top.v] - Blame information for rev 338

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

powered by: WebSVN 2.1.0

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