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

Subversion Repositories ethmac

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

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

powered by: WebSVN 2.1.0

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