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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [ethmac/] [ethmac.v] - Blame information for rev 409

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 408 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth.v                                                       ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6 409 julius
////  http://www.opencores.org/project,ethmac                   ////
7 408 julius
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Igor Mohor (igorM@opencores.org)                      ////
10
////                                                              ////
11
////  All additional information is available in the Readme.txt   ////
12
////  file.                                                       ////
13
////                                                              ////
14
//////////////////////////////////////////////////////////////////////
15
////                                                              ////
16
//// Copyright (C) 2001, 2002 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
 
42
 
43 409 julius
`include "ethmac_defines.v"
44 408 julius
`include "timescale.v"
45
 
46
 
47 409 julius
module ethmac // renamed jb
48 408 julius
(
49
  // WISHBONE common
50
  wb_clk_i, wb_rst_i, wb_dat_i, wb_dat_o,
51
 
52
  // WISHBONE slave
53
  wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i, wb_stb_i, wb_ack_o, wb_err_o,
54
 
55
  // WISHBONE master
56
  m_wb_adr_o, m_wb_sel_o, m_wb_we_o,
57
  m_wb_dat_o, m_wb_dat_i, m_wb_cyc_o,
58
  m_wb_stb_o, m_wb_ack_i, m_wb_err_i,
59
 
60
`ifdef ETH_WISHBONE_B3
61
  m_wb_cti_o, m_wb_bte_o,
62
`endif
63
 
64
  //TX
65
  mtx_clk_pad_i, mtxd_pad_o, mtxen_pad_o, mtxerr_pad_o,
66
 
67
  //RX
68
  mrx_clk_pad_i, mrxd_pad_i, mrxdv_pad_i, mrxerr_pad_i, mcoll_pad_i, mcrs_pad_i,
69
 
70
  // MIIM
71
  mdc_pad_o, md_pad_i, md_pad_o, md_padoe_o,
72
 
73
  int_o
74
 
75
  // Bist
76
`ifdef ETH_BIST
77
  ,
78
  // debug chain signals
79
  mbist_si_i,       // bist scan serial in
80
  mbist_so_o,       // bist scan serial out
81
  mbist_ctrl_i        // bist chain shift control
82
`endif
83
 
84
);
85
 
86
 
87
parameter Tp = 1;
88
 
89
 
90
// WISHBONE common
91
input           wb_clk_i;     // WISHBONE clock
92
input           wb_rst_i;     // WISHBONE reset
93
input   [31:0]  wb_dat_i;     // WISHBONE data input
94
output  [31:0]  wb_dat_o;     // WISHBONE data output
95
output          wb_err_o;     // WISHBONE error output
96
 
97
// WISHBONE slave
98
input   [11:2]  wb_adr_i;     // WISHBONE address input
99
input    [3:0]  wb_sel_i;     // WISHBONE byte select input
100
input           wb_we_i;      // WISHBONE write enable input
101
input           wb_cyc_i;     // WISHBONE cycle input
102
input           wb_stb_i;     // WISHBONE strobe input
103
output          wb_ack_o;     // WISHBONE acknowledge output
104
 
105
// WISHBONE master
106
output  [31:0]  m_wb_adr_o;
107
output   [3:0]  m_wb_sel_o;
108
output          m_wb_we_o;
109
input   [31:0]  m_wb_dat_i;
110
output  [31:0]  m_wb_dat_o;
111
output          m_wb_cyc_o;
112
output          m_wb_stb_o;
113
input           m_wb_ack_i;
114
input           m_wb_err_i;
115
 
116
wire    [29:0]  m_wb_adr_tmp;
117
 
118
`ifdef ETH_WISHBONE_B3
119
output   [2:0]  m_wb_cti_o;   // Cycle Type Identifier
120
output   [1:0]  m_wb_bte_o;   // Burst Type Extension
121
`endif
122
 
123
// Tx
124
input           mtx_clk_pad_i; // Transmit clock (from PHY)
125
output   [3:0]  mtxd_pad_o;    // Transmit nibble (to PHY)
126
output          mtxen_pad_o;   // Transmit enable (to PHY)
127
output          mtxerr_pad_o;  // Transmit error (to PHY)
128
 
129
// Rx
130
input           mrx_clk_pad_i; // Receive clock (from PHY)
131
input    [3:0]  mrxd_pad_i;    // Receive nibble (from PHY)
132
input           mrxdv_pad_i;   // Receive data valid (from PHY)
133
input           mrxerr_pad_i;  // Receive data error (from PHY)
134
 
135
// Common Tx and Rx
136
input           mcoll_pad_i;   // Collision (from PHY)
137
input           mcrs_pad_i;    // Carrier sense (from PHY)
138
 
139
// MII Management interface
140
input           md_pad_i;      // MII data input (from I/O cell)
141
output          mdc_pad_o;     // MII Management data clock (to PHY)
142
output          md_pad_o;      // MII data output (to I/O cell)
143
output          md_padoe_o;    // MII data output enable (to I/O cell)
144
 
145
output          int_o;         // Interrupt output
146
 
147
// Bist
148
`ifdef ETH_BIST
149
input   mbist_si_i;       // bist scan serial in
150
output  mbist_so_o;       // bist scan serial out
151
input [`ETH_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;       // bist chain shift control
152
`endif
153
 
154
`ifdef WISHBONE_DEBUG
155
   wire [31:0]                       wb_dbg_dat0;
156
`endif
157
 
158
 
159
wire     [7:0]  r_ClkDiv;
160
wire            r_MiiNoPre;
161
wire    [15:0]  r_CtrlData;
162
wire     [4:0]  r_FIAD;
163
wire     [4:0]  r_RGAD;
164
wire            r_WCtrlData;
165
wire            r_RStat;
166
wire            r_ScanStat;
167
wire            NValid_stat;
168
wire            Busy_stat;
169
wire            LinkFail;
170
wire    [15:0]  Prsd;             // Read Status Data (data read from the PHY)
171
wire            WCtrlDataStart;
172
wire            RStatStart;
173
wire            UpdateMIIRX_DATAReg;
174
 
175
wire            TxStartFrm;
176
wire            TxEndFrm;
177
wire            TxUsedData;
178
wire     [7:0]  TxData;
179
wire            TxRetry;
180
wire            TxAbort;
181
wire            TxUnderRun;
182
wire            TxDone;
183
 
184
 
185
reg             WillSendControlFrame_sync1;
186
reg             WillSendControlFrame_sync2;
187
reg             WillSendControlFrame_sync3;
188
reg             RstTxPauseRq;
189
 
190
reg             TxPauseRq_sync1;
191
reg             TxPauseRq_sync2;
192
reg             TxPauseRq_sync3;
193
reg             TPauseRq;
194
 
195
 
196
// Connecting Miim module
197
eth_miim miim1
198
(
199
  .Clk(wb_clk_i),                         .Reset(wb_rst_i),                   .Divider(r_ClkDiv),
200
  .NoPre(r_MiiNoPre),                     .CtrlData(r_CtrlData),              .Rgad(r_RGAD),
201
  .Fiad(r_FIAD),                          .WCtrlData(r_WCtrlData),            .RStat(r_RStat),
202
  .ScanStat(r_ScanStat),                  .Mdi(md_pad_i),                     .Mdo(md_pad_o),
203
  .MdoEn(md_padoe_o),                     .Mdc(mdc_pad_o),                    .Busy(Busy_stat),
204
  .Prsd(Prsd),                            .LinkFail(LinkFail),                .Nvalid(NValid_stat),
205
  .WCtrlDataStart(WCtrlDataStart),        .RStatStart(RStatStart),            .UpdateMIIRX_DATAReg(UpdateMIIRX_DATAReg)
206
);
207
 
208
 
209
 
210
 
211
wire  [3:0] RegCs;          // Connected to registers
212
wire [31:0] RegDataOut;     // Multiplexed to wb_dat_o
213
wire        r_RecSmall;     // Receive small frames
214
wire        r_LoopBck;      // Loopback
215
wire        r_TxEn;         // Tx Enable
216
wire        r_RxEn;         // Rx Enable
217
 
218
wire        MRxDV_Lb;       // Muxed MII receive data valid
219
wire        MRxErr_Lb;      // Muxed MII Receive Error
220
wire  [3:0] MRxD_Lb;        // Muxed MII Receive Data
221
wire        Transmitting;   // Indication that TxEthMAC is transmitting
222
wire        r_HugEn;        // Huge packet enable
223
wire        r_DlyCrcEn;     // Delayed CRC enabled
224
wire [15:0] r_MaxFL;        // Maximum frame length
225
 
226
wire [15:0] r_MinFL;        // Minimum frame length
227
wire        ShortFrame;
228
wire        DribbleNibble;  // Extra nibble received
229
wire        ReceivedPacketTooBig; // Received packet is too big
230
wire [47:0] r_MAC;          // MAC address
231
wire        LoadRxStatus;   // Rx status was loaded
232
wire [31:0] r_HASH0;        // HASH table, lower 4 bytes
233
wire [31:0] r_HASH1;        // HASH table, upper 4 bytes
234
wire  [7:0] r_TxBDNum;      // Receive buffer descriptor number
235
wire  [6:0] r_IPGT;         // 
236
wire  [6:0] r_IPGR1;        // 
237
wire  [6:0] r_IPGR2;        // 
238
wire  [5:0] r_CollValid;    // 
239
wire [15:0] r_TxPauseTV;    // Transmit PAUSE value
240
wire        r_TxPauseRq;    // Transmit PAUSE request
241
 
242
wire  [3:0] r_MaxRet;       //
243
wire        r_NoBckof;      // 
244
wire        r_ExDfrEn;      // 
245
wire        r_TxFlow;       // Tx flow control enable
246
wire        r_IFG;          // Minimum interframe gap for incoming packets
247
 
248
wire        TxB_IRQ;        // Interrupt Tx Buffer
249
wire        TxE_IRQ;        // Interrupt Tx Error
250
wire        RxB_IRQ;        // Interrupt Rx Buffer
251
wire        RxE_IRQ;        // Interrupt Rx Error
252
wire        Busy_IRQ;       // Interrupt Busy (lack of buffers)
253
 
254
//wire        DWord;
255
wire        ByteSelected;
256
wire        BDAck;
257
wire [31:0] BD_WB_DAT_O;    // wb_dat_o that comes from the Wishbone module (for buffer descriptors read/write)
258
wire  [3:0] BDCs;           // Buffer descriptor CS
259
wire        CsMiss;         // When access to the address between 0x800 and 0xfff occurs, acknowledge is set
260
                            // but data is not valid.
261
wire        r_Pad;
262
wire        r_CrcEn;
263
wire        r_FullD;
264
wire        r_Pro;
265
wire        r_Bro;
266
wire        r_NoPre;
267
wire        r_RxFlow;
268
wire        r_PassAll;
269
wire        TxCtrlEndFrm;
270
wire        StartTxDone;
271
wire        SetPauseTimer;
272
wire        TxUsedDataIn;
273
wire        TxDoneIn;
274
wire        TxAbortIn;
275
wire        PerPacketPad;
276
wire        PadOut;
277
wire        PerPacketCrcEn;
278
wire        CrcEnOut;
279
wire        TxStartFrmOut;
280
wire        TxEndFrmOut;
281
wire        ReceivedPauseFrm;
282
wire        ControlFrmAddressOK;
283
wire        RxStatusWriteLatched_sync2;
284
wire        LateCollision;
285
wire        DeferIndication;
286
wire        LateCollLatched;
287
wire        DeferLatched;
288
wire        RstDeferLatched;
289
wire        CarrierSenseLost;
290
 
291
wire        temp_wb_ack_o;
292
wire [31:0] temp_wb_dat_o;
293
wire        temp_wb_err_o;
294
 
295
`ifdef ETH_REGISTERED_OUTPUTS
296
  reg         temp_wb_ack_o_reg;
297
  reg [31:0]  temp_wb_dat_o_reg;
298
  reg         temp_wb_err_o_reg;
299
`endif
300
 
301
//assign DWord = &wb_sel_i;
302
assign ByteSelected = |wb_sel_i;
303
assign RegCs[3] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[3];   // 0x0   - 0x3FF
304
assign RegCs[2] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[2];   // 0x0   - 0x3FF
305
assign RegCs[1] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[1];   // 0x0   - 0x3FF
306
assign RegCs[0] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[0];   // 0x0   - 0x3FF
307
assign BDCs[3]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[3];   // 0x400 - 0x7FF
308
assign BDCs[2]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[2];   // 0x400 - 0x7FF
309
assign BDCs[1]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[1];   // 0x400 - 0x7FF
310
assign BDCs[0]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[0];   // 0x400 - 0x7FF
311
assign CsMiss = wb_stb_i & wb_cyc_i & ByteSelected & wb_adr_i[11];                   // 0x800 - 0xfFF
312
assign temp_wb_dat_o = ((|RegCs) & ~wb_we_i)? RegDataOut : BD_WB_DAT_O;
313
assign temp_wb_err_o = wb_stb_i & wb_cyc_i & (~ByteSelected | CsMiss);
314
 
315
`ifdef ETH_REGISTERED_OUTPUTS
316
  assign wb_ack_o = temp_wb_ack_o_reg;
317
  assign wb_dat_o[31:0] = temp_wb_dat_o_reg;
318
  assign wb_err_o = temp_wb_err_o_reg;
319
`else
320
  assign wb_ack_o = temp_wb_ack_o;
321
  assign wb_dat_o[31:0] = temp_wb_dat_o;
322
  assign wb_err_o = temp_wb_err_o;
323
`endif
324
 
325
`ifdef ETH_AVALON_BUS
326
  // As Avalon has no corresponding "error" signal, I (erroneously) will
327
  // send an ack to Avalon, even when accessing undefined memory. This
328
  // is a grey area in Avalon vs. Wishbone specs: My understanding
329
  // is that Avalon expects all memory addressable by the addr bus feeding
330
  // a slave to be, at the very minimum, readable.
331
  assign temp_wb_ack_o = (|RegCs) | BDAck | CsMiss;
332
`else // WISHBONE
333
  assign temp_wb_ack_o = (|RegCs) | BDAck;
334
`endif
335
 
336
`ifdef ETH_REGISTERED_OUTPUTS
337
  always @ (posedge wb_clk_i or posedge wb_rst_i)
338
  begin
339
    if(wb_rst_i)
340
      begin
341
        temp_wb_ack_o_reg <= 1'b0;
342
        temp_wb_dat_o_reg <= 32'h0;
343
        temp_wb_err_o_reg <= 1'b0;
344
      end
345
    else
346
      begin
347
        temp_wb_ack_o_reg <= temp_wb_ack_o & ~temp_wb_ack_o_reg;
348
        temp_wb_dat_o_reg <= temp_wb_dat_o;
349
        temp_wb_err_o_reg <= temp_wb_err_o & ~temp_wb_err_o_reg;
350
      end
351
  end
352
`endif
353
 
354
 
355
// Connecting Ethernet registers
356
eth_registers ethreg1
357
(
358
  .DataIn(wb_dat_i),                      .Address(wb_adr_i[9:2]),                    .Rw(wb_we_i),
359
  .Cs(RegCs),                             .Clk(wb_clk_i),                             .Reset(wb_rst_i),
360
  .DataOut(RegDataOut),                   .r_RecSmall(r_RecSmall),
361
  .r_Pad(r_Pad),                          .r_HugEn(r_HugEn),                          .r_CrcEn(r_CrcEn),
362
  .r_DlyCrcEn(r_DlyCrcEn),                .r_FullD(r_FullD),
363
  .r_ExDfrEn(r_ExDfrEn),                  .r_NoBckof(r_NoBckof),                      .r_LoopBck(r_LoopBck),
364
  .r_IFG(r_IFG),                          .r_Pro(r_Pro),                              .r_Iam(),
365
  .r_Bro(r_Bro),                          .r_NoPre(r_NoPre),                          .r_TxEn(r_TxEn),
366
  .r_RxEn(r_RxEn),                        .Busy_IRQ(Busy_IRQ),                        .RxE_IRQ(RxE_IRQ),
367
  .RxB_IRQ(RxB_IRQ),                      .TxE_IRQ(TxE_IRQ),                          .TxB_IRQ(TxB_IRQ),
368
  .r_IPGT(r_IPGT),
369
  .r_IPGR1(r_IPGR1),                      .r_IPGR2(r_IPGR2),                          .r_MinFL(r_MinFL),
370
  .r_MaxFL(r_MaxFL),                      .r_MaxRet(r_MaxRet),                        .r_CollValid(r_CollValid),
371
  .r_TxFlow(r_TxFlow),                    .r_RxFlow(r_RxFlow),                        .r_PassAll(r_PassAll),
372
  .r_MiiNoPre(r_MiiNoPre),                .r_ClkDiv(r_ClkDiv),
373
  .r_WCtrlData(r_WCtrlData),              .r_RStat(r_RStat),                          .r_ScanStat(r_ScanStat),
374
  .r_RGAD(r_RGAD),                        .r_FIAD(r_FIAD),                            .r_CtrlData(r_CtrlData),
375
  .NValid_stat(NValid_stat),              .Busy_stat(Busy_stat),
376
  .LinkFail(LinkFail),                    .r_MAC(r_MAC),                              .WCtrlDataStart(WCtrlDataStart),
377
  .RStatStart(RStatStart),                .UpdateMIIRX_DATAReg(UpdateMIIRX_DATAReg),  .Prsd(Prsd),
378
  .r_TxBDNum(r_TxBDNum),                  .int_o(int_o),
379
  .r_HASH0(r_HASH0),                      .r_HASH1(r_HASH1),                          .r_TxPauseRq(r_TxPauseRq),
380
  .r_TxPauseTV(r_TxPauseTV),              .RstTxPauseRq(RstTxPauseRq),                .TxCtrlEndFrm(TxCtrlEndFrm),
381
  .StartTxDone(StartTxDone),              .TxClk(mtx_clk_pad_i),                      .RxClk(mrx_clk_pad_i),
382
 .dbg_dat(wb_dbg_dat0),
383
  .SetPauseTimer(SetPauseTimer)
384
 
385
);
386
 
387
 
388
 
389
wire  [7:0] RxData;
390
wire        RxValid;
391
wire        RxStartFrm;
392
wire        RxEndFrm;
393
wire        RxAbort;
394
 
395
wire        WillTransmit;            // Will transmit (to RxEthMAC)
396
wire        ResetCollision;          // Reset Collision (for synchronizing collision)
397
wire  [7:0] TxDataOut;               // Transmit Packet Data (to TxEthMAC)
398
wire        WillSendControlFrame;
399
wire        ReceiveEnd;
400
wire        ReceivedPacketGood;
401
wire        ReceivedLengthOK;
402
wire        InvalidSymbol;
403
wire        LatchedCrcError;
404
wire        RxLateCollision;
405
wire  [3:0] RetryCntLatched;
406
wire  [3:0] RetryCnt;
407
wire        StartTxAbort;
408
wire        MaxCollisionOccured;
409
wire        RetryLimit;
410
wire        StatePreamble;
411
wire  [1:0] StateData;
412
 
413
// Connecting MACControl
414
eth_maccontrol maccontrol1
415
(
416
  .MTxClk(mtx_clk_pad_i),                       .TPauseRq(TPauseRq),
417
  .TxPauseTV(r_TxPauseTV),                      .TxDataIn(TxData),
418
  .TxStartFrmIn(TxStartFrm),                    .TxEndFrmIn(TxEndFrm),
419
  .TxUsedDataIn(TxUsedDataIn),                  .TxDoneIn(TxDoneIn),
420
  .TxAbortIn(TxAbortIn),                        .MRxClk(mrx_clk_pad_i),
421
  .RxData(RxData),                              .RxValid(RxValid),
422
  .RxStartFrm(RxStartFrm),                      .RxEndFrm(RxEndFrm),
423
  .ReceiveEnd(ReceiveEnd),                      .ReceivedPacketGood(ReceivedPacketGood),
424
  .TxFlow(r_TxFlow),
425
  .RxFlow(r_RxFlow),                            .DlyCrcEn(r_DlyCrcEn),
426
  .MAC(r_MAC),                                  .PadIn(r_Pad | PerPacketPad),
427
  .PadOut(PadOut),                              .CrcEnIn(r_CrcEn | PerPacketCrcEn),
428
  .CrcEnOut(CrcEnOut),                          .TxReset(wb_rst_i),
429
  .RxReset(wb_rst_i),                           .ReceivedLengthOK(ReceivedLengthOK),
430
  .TxDataOut(TxDataOut),                        .TxStartFrmOut(TxStartFrmOut),
431
  .TxEndFrmOut(TxEndFrmOut),                    .TxUsedDataOut(TxUsedData),
432
  .TxDoneOut(TxDone),                           .TxAbortOut(TxAbort),
433
  .WillSendControlFrame(WillSendControlFrame),  .TxCtrlEndFrm(TxCtrlEndFrm),
434
  .ReceivedPauseFrm(ReceivedPauseFrm),          .ControlFrmAddressOK(ControlFrmAddressOK),
435
  .SetPauseTimer(SetPauseTimer),
436
  .RxStatusWriteLatched_sync2(RxStatusWriteLatched_sync2),                .r_PassAll(r_PassAll)
437
);
438
 
439
 
440
 
441
wire TxCarrierSense;          // Synchronized CarrierSense (to Tx clock)
442
wire Collision;               // Synchronized Collision
443
 
444
reg CarrierSense_Tx1;
445
reg CarrierSense_Tx2;
446
reg Collision_Tx1;
447
reg Collision_Tx2;
448
 
449
reg RxEnSync;                 // Synchronized Receive Enable
450
reg WillTransmit_q;
451
reg WillTransmit_q2;
452
 
453
 
454
 
455
// Muxed MII receive data valid
456
assign MRxDV_Lb = r_LoopBck? mtxen_pad_o : mrxdv_pad_i & RxEnSync;
457
 
458
// Muxed MII Receive Error
459
assign MRxErr_Lb = r_LoopBck? mtxerr_pad_o : mrxerr_pad_i & RxEnSync;
460
 
461
// Muxed MII Receive Data
462
assign MRxD_Lb[3:0] = r_LoopBck? mtxd_pad_o[3:0] : mrxd_pad_i[3:0];
463
 
464
 
465
 
466
// Connecting TxEthMAC
467
eth_txethmac txethmac1
468
(
469
  .MTxClk(mtx_clk_pad_i),             .Reset(wb_rst_i),                   .CarrierSense(TxCarrierSense),
470
  .Collision(Collision),              .TxData(TxDataOut),                 .TxStartFrm(TxStartFrmOut),
471
  .TxUnderRun(TxUnderRun),            .TxEndFrm(TxEndFrmOut),             .Pad(PadOut),
472
  .MinFL(r_MinFL),                    .CrcEn(CrcEnOut),                   .FullD(r_FullD),
473
  .HugEn(r_HugEn),                    .DlyCrcEn(r_DlyCrcEn),              .IPGT(r_IPGT),
474
  .IPGR1(r_IPGR1),                    .IPGR2(r_IPGR2),                    .CollValid(r_CollValid),
475
  .MaxRet(r_MaxRet),                  .NoBckof(r_NoBckof),                .ExDfrEn(r_ExDfrEn),
476
  .MaxFL(r_MaxFL),                    .MTxEn(mtxen_pad_o),                .MTxD(mtxd_pad_o),
477
  .MTxErr(mtxerr_pad_o),              .TxUsedData(TxUsedDataIn),          .TxDone(TxDoneIn),
478
  .TxRetry(TxRetry),                  .TxAbort(TxAbortIn),                .WillTransmit(WillTransmit),
479
  .ResetCollision(ResetCollision),    .RetryCnt(RetryCnt),                .StartTxDone(StartTxDone),
480
  .StartTxAbort(StartTxAbort),        .MaxCollisionOccured(MaxCollisionOccured), .LateCollision(LateCollision),
481
  .DeferIndication(DeferIndication),  .StatePreamble(StatePreamble),      .StateData(StateData)
482
);
483
 
484
 
485
 
486
 
487
wire  [15:0]  RxByteCnt;
488
wire          RxByteCntEq0;
489
wire          RxByteCntGreat2;
490
wire          RxByteCntMaxFrame;
491
wire          RxCrcError;
492
wire          RxStateIdle;
493
wire          RxStatePreamble;
494
wire          RxStateSFD;
495
wire   [1:0]  RxStateData;
496
wire          AddressMiss;
497
 
498
 
499
 
500
// Connecting RxEthMAC
501
eth_rxethmac rxethmac1
502
(
503
  .MRxClk(mrx_clk_pad_i),               .MRxDV(MRxDV_Lb),                     .MRxD(MRxD_Lb),
504
  .Transmitting(Transmitting),          .HugEn(r_HugEn),                      .DlyCrcEn(r_DlyCrcEn),
505
  .MaxFL(r_MaxFL),                      .r_IFG(r_IFG),                        .Reset(wb_rst_i),
506
  .RxData(RxData),                      .RxValid(RxValid),                    .RxStartFrm(RxStartFrm),
507
  .RxEndFrm(RxEndFrm),                  .ByteCnt(RxByteCnt),
508
  .ByteCntEq0(RxByteCntEq0),            .ByteCntGreat2(RxByteCntGreat2),      .ByteCntMaxFrame(RxByteCntMaxFrame),
509
  .CrcError(RxCrcError),                .StateIdle(RxStateIdle),              .StatePreamble(RxStatePreamble),
510
  .StateSFD(RxStateSFD),                .StateData(RxStateData),
511
  .MAC(r_MAC),                          .r_Pro(r_Pro),                        .r_Bro(r_Bro),
512
  .r_HASH0(r_HASH0),                    .r_HASH1(r_HASH1),                    .RxAbort(RxAbort),
513
  .AddressMiss(AddressMiss),            .PassAll(r_PassAll),                  .ControlFrmAddressOK(ControlFrmAddressOK)
514
);
515
 
516
 
517
// MII Carrier Sense Synchronization
518
always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
519
begin
520
  if(wb_rst_i)
521
    begin
522
      CarrierSense_Tx1 <=  1'b0;
523
      CarrierSense_Tx2 <=  1'b0;
524
    end
525
  else
526
    begin
527
      CarrierSense_Tx1 <=  mcrs_pad_i;
528
      CarrierSense_Tx2 <=  CarrierSense_Tx1;
529
    end
530
end
531
 
532
assign TxCarrierSense = ~r_FullD & CarrierSense_Tx2;
533
 
534
 
535
// MII Collision Synchronization
536
always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
537
begin
538
  if(wb_rst_i)
539
    begin
540
      Collision_Tx1 <=  1'b0;
541
      Collision_Tx2 <=  1'b0;
542
    end
543
  else
544
    begin
545
      Collision_Tx1 <=  mcoll_pad_i;
546
      if(ResetCollision)
547
        Collision_Tx2 <=  1'b0;
548
      else
549
      if(Collision_Tx1)
550
        Collision_Tx2 <=  1'b1;
551
    end
552
end
553
 
554
 
555
// Synchronized Collision
556
assign Collision = ~r_FullD & Collision_Tx2;
557
 
558
 
559
 
560
// Delayed WillTransmit
561
always @ (posedge mrx_clk_pad_i)
562
begin
563
  WillTransmit_q <=  WillTransmit;
564
  WillTransmit_q2 <=  WillTransmit_q;
565
end
566
 
567
 
568
assign Transmitting = ~r_FullD & WillTransmit_q2;
569
 
570
 
571
 
572
// Synchronized Receive Enable
573
always @ (posedge mrx_clk_pad_i or posedge wb_rst_i)
574
begin
575
  if(wb_rst_i)
576
    RxEnSync <=  1'b0;
577
  else
578
  if(~mrxdv_pad_i)
579
    RxEnSync <=  r_RxEn;
580
end
581
 
582
 
583
 
584
// Synchronizing WillSendControlFrame to WB_CLK;
585
always @ (posedge wb_clk_i or posedge wb_rst_i)
586
begin
587
  if(wb_rst_i)
588
    WillSendControlFrame_sync1 <= 1'b0;
589
  else
590
    WillSendControlFrame_sync1 <= WillSendControlFrame;
591
end
592
 
593
always @ (posedge wb_clk_i or posedge wb_rst_i)
594
begin
595
  if(wb_rst_i)
596
    WillSendControlFrame_sync2 <= 1'b0;
597
  else
598
    WillSendControlFrame_sync2 <= WillSendControlFrame_sync1;
599
end
600
 
601
always @ (posedge wb_clk_i or posedge wb_rst_i)
602
begin
603
  if(wb_rst_i)
604
    WillSendControlFrame_sync3 <= 1'b0;
605
  else
606
    WillSendControlFrame_sync3 <= WillSendControlFrame_sync2;
607
end
608
 
609
always @ (posedge wb_clk_i or posedge wb_rst_i)
610
begin
611
  if(wb_rst_i)
612
    RstTxPauseRq <= 1'b0;
613
  else
614
    RstTxPauseRq <= WillSendControlFrame_sync2 & ~WillSendControlFrame_sync3;
615
end
616
 
617
 
618
 
619
 
620
// TX Pause request Synchronization
621
always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
622
begin
623
  if(wb_rst_i)
624
    begin
625
      TxPauseRq_sync1 <=  1'b0;
626
      TxPauseRq_sync2 <=  1'b0;
627
      TxPauseRq_sync3 <=  1'b0;
628
    end
629
  else
630
    begin
631
      TxPauseRq_sync1 <=  (r_TxPauseRq & r_TxFlow);
632
      TxPauseRq_sync2 <=  TxPauseRq_sync1;
633
      TxPauseRq_sync3 <=  TxPauseRq_sync2;
634
    end
635
end
636
 
637
 
638
always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
639
begin
640
  if(wb_rst_i)
641
    TPauseRq <=  1'b0;
642
  else
643
    TPauseRq <=  TxPauseRq_sync2 & (~TxPauseRq_sync3);
644
end
645
 
646
 
647
wire LatchedMRxErr;
648
reg RxAbort_latch;
649
reg RxAbort_sync1;
650
reg RxAbort_wb;
651
reg RxAbortRst_sync1;
652
reg RxAbortRst;
653
 
654
// Synchronizing RxAbort to the WISHBONE clock
655
always @ (posedge mrx_clk_pad_i or posedge wb_rst_i)
656
begin
657
  if(wb_rst_i)
658
    RxAbort_latch <=  1'b0;
659
  else if(RxAbort | (ShortFrame & ~r_RecSmall) | LatchedMRxErr & ~InvalidSymbol | (ReceivedPauseFrm & (~r_PassAll)))
660
    RxAbort_latch <=  1'b1;
661
  else if(RxAbortRst)
662
    RxAbort_latch <=  1'b0;
663
end
664
 
665
always @ (posedge wb_clk_i or posedge wb_rst_i)
666
begin
667
  if(wb_rst_i)
668
    begin
669
      RxAbort_sync1 <=  1'b0;
670
      RxAbort_wb    <=  1'b0;
671
      RxAbort_wb    <=  1'b0;
672
    end
673
  else
674
    begin
675
      RxAbort_sync1 <=  RxAbort_latch;
676
      RxAbort_wb    <=  RxAbort_sync1;
677
    end
678
end
679
 
680
always @ (posedge mrx_clk_pad_i or posedge wb_rst_i)
681
begin
682
  if(wb_rst_i)
683
    begin
684
      RxAbortRst_sync1 <=  1'b0;
685
      RxAbortRst       <=  1'b0;
686
    end
687
  else
688
    begin
689
      RxAbortRst_sync1 <=  RxAbort_wb;
690
      RxAbortRst       <=  RxAbortRst_sync1;
691
    end
692
end
693
 
694
 
695
 
696
// Connecting Wishbone module
697
eth_wishbone wishbone
698
(
699
  .WB_CLK_I(wb_clk_i),                .WB_DAT_I(wb_dat_i),
700
  .WB_DAT_O(BD_WB_DAT_O),
701
 
702
  // WISHBONE slave
703
  .WB_ADR_I(wb_adr_i[9:2]),           .WB_WE_I(wb_we_i),
704
  .BDCs(BDCs),                        .WB_ACK_O(BDAck),
705
 
706
  .Reset(wb_rst_i),
707
 
708
  // WISHBONE master
709
  .m_wb_adr_o(m_wb_adr_tmp),          .m_wb_sel_o(m_wb_sel_o),                  .m_wb_we_o(m_wb_we_o),
710
  .m_wb_dat_i(m_wb_dat_i),            .m_wb_dat_o(m_wb_dat_o),                  .m_wb_cyc_o(m_wb_cyc_o),
711
  .m_wb_stb_o(m_wb_stb_o),            .m_wb_ack_i(m_wb_ack_i),                  .m_wb_err_i(m_wb_err_i),
712
 
713
`ifdef ETH_WISHBONE_B3
714
  .m_wb_cti_o(m_wb_cti_o),            .m_wb_bte_o(m_wb_bte_o),
715
`endif
716
 
717
 
718
    //TX
719
  .MTxClk(mtx_clk_pad_i),             .TxStartFrm(TxStartFrm),                  .TxEndFrm(TxEndFrm),
720
  .TxUsedData(TxUsedData),            .TxData(TxData),
721
  .TxRetry(TxRetry),                  .TxAbort(TxAbort),                        .TxUnderRun(TxUnderRun),
722
  .TxDone(TxDone),
723
  .PerPacketCrcEn(PerPacketCrcEn),    .PerPacketPad(PerPacketPad),
724
 
725
  // Register
726
  .r_TxEn(r_TxEn),                    .r_RxEn(r_RxEn),                          .r_TxBDNum(r_TxBDNum),
727
  .r_RxFlow(r_RxFlow),                      .r_PassAll(r_PassAll),
728
 
729
  //RX
730
  .MRxClk(mrx_clk_pad_i),             .RxData(RxData),                          .RxValid(RxValid),
731
  .RxStartFrm(RxStartFrm),            .RxEndFrm(RxEndFrm),
732
  .Busy_IRQ(Busy_IRQ),                .RxE_IRQ(RxE_IRQ),                        .RxB_IRQ(RxB_IRQ),
733
  .TxE_IRQ(TxE_IRQ),                  .TxB_IRQ(TxB_IRQ),
734
 
735
  .RxAbort(RxAbort_wb),               .RxStatusWriteLatched_sync2(RxStatusWriteLatched_sync2),
736
 
737
  .InvalidSymbol(InvalidSymbol),      .LatchedCrcError(LatchedCrcError),        .RxLength(RxByteCnt),
738
  .RxLateCollision(RxLateCollision),  .ShortFrame(ShortFrame),                  .DribbleNibble(DribbleNibble),
739
  .ReceivedPacketTooBig(ReceivedPacketTooBig), .LoadRxStatus(LoadRxStatus),     .RetryCntLatched(RetryCntLatched),
740
  .RetryLimit(RetryLimit),            .LateCollLatched(LateCollLatched),        .DeferLatched(DeferLatched),
741
  .RstDeferLatched(RstDeferLatched),
742
  .CarrierSenseLost(CarrierSenseLost),.ReceivedPacketGood(ReceivedPacketGood),  .AddressMiss(AddressMiss),
743
  .ReceivedPauseFrm(ReceivedPauseFrm)
744
 
745
`ifdef ETH_BIST
746
  ,
747
  .mbist_si_i       (mbist_si_i),
748
  .mbist_so_o       (mbist_so_o),
749
  .mbist_ctrl_i       (mbist_ctrl_i)
750
`endif
751
 `ifdef WISHBONE_DEBUG
752
  ,
753
  .dbg_dat0(wb_dbg_dat0)
754
`endif
755
 
756
);
757
 
758
assign m_wb_adr_o = {m_wb_adr_tmp, 2'h0};
759
 
760
// Connecting MacStatus module
761
eth_macstatus macstatus1
762
(
763
  .MRxClk(mrx_clk_pad_i),             .Reset(wb_rst_i),
764
  .ReceiveEnd(ReceiveEnd),            .ReceivedPacketGood(ReceivedPacketGood),     .ReceivedLengthOK(ReceivedLengthOK),
765
  .RxCrcError(RxCrcError),            .MRxErr(MRxErr_Lb),                          .MRxDV(MRxDV_Lb),
766
  .RxStateSFD(RxStateSFD),            .RxStateData(RxStateData),                   .RxStatePreamble(RxStatePreamble),
767
  .RxStateIdle(RxStateIdle),          .Transmitting(Transmitting),                 .RxByteCnt(RxByteCnt),
768
  .RxByteCntEq0(RxByteCntEq0),        .RxByteCntGreat2(RxByteCntGreat2),           .RxByteCntMaxFrame(RxByteCntMaxFrame),
769
  .InvalidSymbol(InvalidSymbol),
770
  .MRxD(MRxD_Lb),                     .LatchedCrcError(LatchedCrcError),           .Collision(mcoll_pad_i),
771
  .CollValid(r_CollValid),            .RxLateCollision(RxLateCollision),           .r_RecSmall(r_RecSmall),
772
  .r_MinFL(r_MinFL),                  .r_MaxFL(r_MaxFL),                           .ShortFrame(ShortFrame),
773
  .DribbleNibble(DribbleNibble),      .ReceivedPacketTooBig(ReceivedPacketTooBig), .r_HugEn(r_HugEn),
774
  .LoadRxStatus(LoadRxStatus),        .RetryCnt(RetryCnt),                         .StartTxDone(StartTxDone),
775
  .StartTxAbort(StartTxAbort),        .RetryCntLatched(RetryCntLatched),           .MTxClk(mtx_clk_pad_i),
776
  .MaxCollisionOccured(MaxCollisionOccured), .RetryLimit(RetryLimit),              .LateCollision(LateCollision),
777
  .LateCollLatched(LateCollLatched),  .DeferIndication(DeferIndication),           .DeferLatched(DeferLatched),
778
  .RstDeferLatched(RstDeferLatched),
779
  .TxStartFrm(TxStartFrmOut),         .StatePreamble(StatePreamble),               .StateData(StateData),
780
  .CarrierSense(CarrierSense_Tx2),    .CarrierSenseLost(CarrierSenseLost),         .TxUsedData(TxUsedDataIn),
781
  .LatchedMRxErr(LatchedMRxErr),      .Loopback(r_LoopBck),                        .r_FullD(r_FullD)
782
);
783
 
784
 
785
endmodule

powered by: WebSVN 2.1.0

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