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

Subversion Repositories ethmac

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

powered by: WebSVN 2.1.0

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