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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_17/] [rtl/] [verilog/] [eth_top.v] - Blame information for rev 168

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

powered by: WebSVN 2.1.0

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