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

Subversion Repositories openrisc

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

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 439 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 439 julius
  (
49
   // WISHBONE common
50
   wb_clk_i, wb_rst_i, wb_dat_i, wb_dat_o,
51 408 julius
 
52 439 julius
   // 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 408 julius
 
55 439 julius
   // 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 408 julius
 
60
`ifdef ETH_WISHBONE_B3
61 439 julius
   m_wb_cti_o, m_wb_bte_o,
62 408 julius
`endif
63
 
64 439 julius
   //TX
65
   mtx_clk_pad_i, mtxd_pad_o, mtxen_pad_o, mtxerr_pad_o,
66 408 julius
 
67 439 julius
   //RX
68
   mrx_clk_pad_i, mrxd_pad_i, mrxdv_pad_i, mrxerr_pad_i, mcoll_pad_i,
69
   mcrs_pad_i,
70 408 julius
 
71 439 julius
   // MIIM
72
   mdc_pad_o, md_pad_i, md_pad_o, md_padoe_o,
73 408 julius
 
74 439 julius
   int_o
75 408 julius
 
76 439 julius
   // Bist
77 408 julius
`ifdef ETH_BIST
78 439 julius
   ,
79
   // debug chain signals
80
   mbist_si_i,       // bist scan serial in
81
   mbist_so_o,       // bist scan serial out
82
   mbist_ctrl_i        // bist chain shift control
83 408 julius
`endif
84
 
85 439 julius
   );
86 408 julius
 
87
 
88
 
89 439 julius
   // WISHBONE common
90
   input           wb_clk_i;     // WISHBONE clock
91
   input           wb_rst_i;     // WISHBONE reset
92
   input [31:0]    wb_dat_i;     // WISHBONE data input
93
   output [31:0]   wb_dat_o;     // WISHBONE data output
94
   output          wb_err_o;     // WISHBONE error output
95 408 julius
 
96 439 julius
   // WISHBONE slave
97
   input [11:2]    wb_adr_i;     // WISHBONE address input
98
   input [3:0]      wb_sel_i;     // WISHBONE byte select input
99
   input           wb_we_i;      // WISHBONE write enable input
100
   input           wb_cyc_i;     // WISHBONE cycle input
101
   input           wb_stb_i;     // WISHBONE strobe input
102
   output          wb_ack_o;     // WISHBONE acknowledge output
103 408 julius
 
104 439 julius
   // WISHBONE master
105
   output [31:0]   m_wb_adr_o;
106
   output [3:0]    m_wb_sel_o;
107
   output          m_wb_we_o;
108
   input [31:0]    m_wb_dat_i;
109
   output [31:0]   m_wb_dat_o;
110
   output          m_wb_cyc_o;
111
   output          m_wb_stb_o;
112
   input           m_wb_ack_i;
113
   input           m_wb_err_i;
114 408 julius
 
115 439 julius
   wire [29:0]      m_wb_adr_tmp;
116 408 julius
 
117
`ifdef ETH_WISHBONE_B3
118 439 julius
   output [2:0]    m_wb_cti_o;   // Cycle Type Identifier
119
   output [1:0]    m_wb_bte_o;   // Burst Type Extension
120 408 julius
`endif
121
 
122 439 julius
   // Tx
123
   input           mtx_clk_pad_i; // Transmit clock (from PHY)
124
   output [3:0]    mtxd_pad_o;    // Transmit nibble (to PHY)
125
   output          mtxen_pad_o;   // Transmit enable (to PHY)
126
   output          mtxerr_pad_o;  // Transmit error (to PHY)
127 408 julius
 
128 439 julius
   // Rx
129
   input           mrx_clk_pad_i; // Receive clock (from PHY)
130
   input [3:0]      mrxd_pad_i;    // Receive nibble (from PHY)
131
   input           mrxdv_pad_i;   // Receive data valid (from PHY)
132
   input           mrxerr_pad_i;  // Receive data error (from PHY)
133 408 julius
 
134 439 julius
   // Common Tx and Rx
135
   input           mcoll_pad_i;   // Collision (from PHY)
136
   input           mcrs_pad_i;    // Carrier sense (from PHY)
137 408 julius
 
138 439 julius
   // MII Management interface
139
   input           md_pad_i;      // MII data input (from I/O cell)
140
   output          mdc_pad_o;     // MII Management data clock (to PHY)
141
   output          md_pad_o;      // MII data output (to I/O cell)
142
   output          md_padoe_o;    // MII data output enable (to I/O cell)
143 408 julius
 
144 439 julius
   output          int_o;         // Interrupt output
145 408 julius
 
146 439 julius
   // Bist
147 408 julius
`ifdef ETH_BIST
148 439 julius
   input           mbist_si_i;       // bist scan serial in
149
   output          mbist_so_o;       // bist scan serial out
150
   input [`ETH_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;       // bist chain shift control
151 408 julius
`endif
152
 
153
`ifdef WISHBONE_DEBUG
154 439 julius
   wire [31:0]                          wb_dbg_dat0;
155 408 julius
`endif
156
 
157
 
158 439 julius
   wire [7:0]                           r_ClkDiv;
159
   wire                                r_MiiNoPre;
160
   wire [15:0]                          r_CtrlData;
161
   wire [4:0]                           r_FIAD;
162
   wire [4:0]                           r_RGAD;
163
   wire                                r_WCtrlData;
164
   wire                                r_RStat;
165
   wire                                r_ScanStat;
166
   wire                                NValid_stat;
167
   wire                                Busy_stat;
168
   wire                                LinkFail;
169
   wire [15:0]                          Prsd; // Read Status Data (data read 
170
                                             // from the PHY)
171
   wire                                WCtrlDataStart;
172
   wire                                RStatStart;
173
   wire                                UpdateMIIRX_DATAReg;
174 408 julius
 
175 439 julius
   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 408 julius
 
184
 
185 439 julius
   reg                                 WillSendControlFrame_sync1;
186
   reg                                 WillSendControlFrame_sync2;
187
   reg                                 WillSendControlFrame_sync3;
188
   reg                                 RstTxPauseRq;
189 408 julius
 
190 439 julius
   reg                                 TxPauseRq_sync1;
191
   reg                                 TxPauseRq_sync2;
192
   reg                                 TxPauseRq_sync3;
193
   reg                                 TPauseRq;
194 408 julius
 
195
 
196 439 julius
   // Connecting Miim module
197
   eth_miim miim1
198
     (
199
      .Clk(wb_clk_i),
200
      .Reset(wb_rst_i),
201
      .Divider(r_ClkDiv),
202
      .NoPre(r_MiiNoPre),
203
      .CtrlData(r_CtrlData),
204
      .Rgad(r_RGAD),
205
      .Fiad(r_FIAD),
206
      .WCtrlData(r_WCtrlData),
207
      .RStat(r_RStat),
208
      .ScanStat(r_ScanStat),
209
      .Mdi(md_pad_i),
210
      .Mdo(md_pad_o),
211
      .MdoEn(md_padoe_o),
212
      .Mdc(mdc_pad_o),
213
      .Busy(Busy_stat),
214
      .Prsd(Prsd),
215
      .LinkFail(LinkFail),
216
      .Nvalid(NValid_stat),
217
      .WCtrlDataStart(WCtrlDataStart),
218
      .RStatStart(RStatStart),
219
      .UpdateMIIRX_DATAReg(UpdateMIIRX_DATAReg)
220
      );
221 408 julius
 
222
 
223
 
224
 
225 439 julius
   wire [3:0]                           RegCs;          // Connected to registers
226
   wire [31:0]                          RegDataOut;     // Multiplexed to wb_dat_o
227
   wire                                r_RecSmall;     // Receive small frames
228
   wire                                r_LoopBck;      // Loopback
229
   wire                                r_TxEn;         // Tx Enable
230
   wire                                r_RxEn;         // Rx Enable
231 408 julius
 
232 439 julius
   wire                                MRxDV_Lb;       // Muxed MII receive data valid
233
   wire                                MRxErr_Lb;      // Muxed MII Receive Error
234
   wire [3:0]                           MRxD_Lb;        // Muxed MII Receive Data
235
   wire                                Transmitting;   // Indication that TxEthMAC is transmitting
236
   wire                                r_HugEn;        // Huge packet enable
237
   wire                                r_DlyCrcEn;     // Delayed CRC enabled
238
   wire [15:0]                          r_MaxFL;        // Maximum frame length
239 408 julius
 
240 439 julius
   wire [15:0]                          r_MinFL;        // Minimum frame length
241
   wire                                ShortFrame;
242
   wire                                DribbleNibble;  // Extra nibble received
243
   wire                                ReceivedPacketTooBig; // Received packet is too big
244
   wire [47:0]                          r_MAC;          // MAC address
245
   wire                                LoadRxStatus;   // Rx status was loaded
246
   wire [31:0]                          r_HASH0;        // HASH table, lower 4 bytes
247
   wire [31:0]                          r_HASH1;        // HASH table, upper 4 bytes
248
   wire [7:0]                           r_TxBDNum;      // Receive buffer descriptor number
249
   wire [6:0]                           r_IPGT;         // 
250
   wire [6:0]                           r_IPGR1;        // 
251
   wire [6:0]                           r_IPGR2;        // 
252
   wire [5:0]                           r_CollValid;    // 
253
   wire [15:0]                          r_TxPauseTV;    // Transmit PAUSE value
254
   wire                                r_TxPauseRq;    // Transmit PAUSE request
255 408 julius
 
256 439 julius
   wire [3:0]                           r_MaxRet;       //
257
   wire                                r_NoBckof;      // 
258
   wire                                r_ExDfrEn;      // 
259
   wire                                r_TxFlow;       // Tx flow control enable
260
   wire                                r_IFG;          // Minimum interframe gap for incoming packets
261 408 julius
 
262 439 julius
   wire                                TxB_IRQ;        // Interrupt Tx Buffer
263
   wire                                TxE_IRQ;        // Interrupt Tx Error
264
   wire                                RxB_IRQ;        // Interrupt Rx Buffer
265
   wire                                RxE_IRQ;        // Interrupt Rx Error
266
   wire                                Busy_IRQ;       // Interrupt Busy (lack of buffers)
267 408 julius
 
268 439 julius
   //wire        DWord;
269
   wire                                ByteSelected;
270
   wire                                BDAck;
271
   wire [31:0]                          BD_WB_DAT_O;    // wb_dat_o that comes from the Wishbone module (for buffer descriptors read/write)
272
   wire [3:0]                           BDCs;           // Buffer descriptor CS
273
   wire                                CsMiss;         // When access to the address between 0x800 and 0xfff occurs, acknowledge is set
274
   // but data is not valid.
275
   wire                                r_Pad;
276
   wire                                r_CrcEn;
277
   wire                                r_FullD;
278
   wire                                r_Pro;
279
   wire                                r_Bro;
280
   wire                                r_NoPre;
281
   wire                                r_RxFlow;
282
   wire                                r_PassAll;
283
   wire                                TxCtrlEndFrm;
284
   wire                                StartTxDone;
285
   wire                                SetPauseTimer;
286
   wire                                TxUsedDataIn;
287
   wire                                TxDoneIn;
288
   wire                                TxAbortIn;
289
   wire                                PerPacketPad;
290
   wire                                PadOut;
291
   wire                                PerPacketCrcEn;
292
   wire                                CrcEnOut;
293
   wire                                TxStartFrmOut;
294
   wire                                TxEndFrmOut;
295
   wire                                ReceivedPauseFrm;
296
   wire                                ControlFrmAddressOK;
297
   wire                                RxStatusWriteLatched_sync2;
298
   wire                                LateCollision;
299
   wire                                DeferIndication;
300
   wire                                LateCollLatched;
301
   wire                                DeferLatched;
302
   wire                                RstDeferLatched;
303
   wire                                CarrierSenseLost;
304 408 julius
 
305 439 julius
   wire                                temp_wb_ack_o;
306
   wire [31:0]                          temp_wb_dat_o;
307
   wire                                temp_wb_err_o;
308 408 julius
 
309
`ifdef ETH_REGISTERED_OUTPUTS
310 439 julius
   reg                                 temp_wb_ack_o_reg;
311
   reg [31:0]                           temp_wb_dat_o_reg;
312
   reg                                 temp_wb_err_o_reg;
313 408 julius
`endif
314
 
315 439 julius
   //assign DWord = &wb_sel_i;
316
   assign ByteSelected = |wb_sel_i;
317
   assign RegCs[3] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[3];   // 0x0   - 0x3FF
318
   assign RegCs[2] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[2];   // 0x0   - 0x3FF
319
   assign RegCs[1] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[1];   // 0x0   - 0x3FF
320
   assign RegCs[0] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[0];   // 0x0   - 0x3FF
321
   assign BDCs[3]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[3];   // 0x400 - 0x7FF
322
   assign BDCs[2]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[2];   // 0x400 - 0x7FF
323
   assign BDCs[1]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[1];   // 0x400 - 0x7FF
324
   assign BDCs[0]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[0];   // 0x400 - 0x7FF
325
   assign CsMiss = wb_stb_i & wb_cyc_i & ByteSelected & wb_adr_i[11];                   // 0x800 - 0xfFF
326
   assign temp_wb_dat_o = ((|RegCs) & ~wb_we_i)? RegDataOut : BD_WB_DAT_O;
327
   assign temp_wb_err_o = wb_stb_i & wb_cyc_i & (~ByteSelected | CsMiss);
328 408 julius
 
329
`ifdef ETH_REGISTERED_OUTPUTS
330 439 julius
   assign wb_ack_o = temp_wb_ack_o_reg;
331
   assign wb_dat_o[31:0] = temp_wb_dat_o_reg;
332
   assign wb_err_o = temp_wb_err_o_reg;
333 408 julius
`else
334 439 julius
   assign wb_ack_o = temp_wb_ack_o;
335
   assign wb_dat_o[31:0] = temp_wb_dat_o;
336
   assign wb_err_o = temp_wb_err_o;
337 408 julius
`endif
338
 
339
`ifdef ETH_AVALON_BUS
340 439 julius
   // As Avalon has no corresponding "error" signal, I (erroneously) will
341
   // send an ack to Avalon, even when accessing undefined memory. This
342
   // is a grey area in Avalon vs. Wishbone specs: My understanding
343
   // is that Avalon expects all memory addressable by the addr bus feeding
344
   // a slave to be, at the very minimum, readable.
345
   assign temp_wb_ack_o = (|RegCs) | BDAck | CsMiss;
346 408 julius
`else // WISHBONE
347 439 julius
   assign temp_wb_ack_o = (|RegCs) | BDAck;
348 408 julius
`endif
349
 
350
`ifdef ETH_REGISTERED_OUTPUTS
351 439 julius
   always @ (posedge wb_clk_i or posedge wb_rst_i)
352
     begin
353
        if(wb_rst_i)
354
          begin
355
             temp_wb_ack_o_reg <= 1'b0;
356
             temp_wb_dat_o_reg <= 32'h0;
357
             temp_wb_err_o_reg <= 1'b0;
358
          end
359
        else
360
          begin
361
             temp_wb_ack_o_reg <= temp_wb_ack_o & ~temp_wb_ack_o_reg;
362
             temp_wb_dat_o_reg <= temp_wb_dat_o;
363
             temp_wb_err_o_reg <= temp_wb_err_o & ~temp_wb_err_o_reg;
364
          end
365
     end
366 408 julius
`endif
367
 
368
 
369 439 julius
   // Connecting Ethernet registers
370
   eth_registers ethreg1
371
     (
372
      .DataIn(wb_dat_i),
373
      .Address(wb_adr_i[9:2]),
374
      .Rw(wb_we_i),
375
 
376
      .Cs(RegCs),
377
      .Clk(wb_clk_i),
378
      .Reset(wb_rst_i),
379
 
380
      .DataOut(RegDataOut),
381
      .r_RecSmall(r_RecSmall),
382
 
383
      .r_Pad(r_Pad),
384
      .r_HugEn(r_HugEn),
385
      .r_CrcEn(r_CrcEn),
386
 
387
      .r_DlyCrcEn(r_DlyCrcEn),
388
      .r_FullD(r_FullD),
389
 
390
      .r_ExDfrEn(r_ExDfrEn),
391
      .r_NoBckof(r_NoBckof),
392
      .r_LoopBck(r_LoopBck),
393
 
394
      .r_IFG(r_IFG),
395
      .r_Pro(r_Pro),
396
      .r_Iam(),
397
 
398
      .r_Bro(r_Bro),
399
      .r_NoPre(r_NoPre),
400
      .r_TxEn(r_TxEn),
401
 
402
      .r_RxEn(r_RxEn),
403
      .Busy_IRQ(Busy_IRQ),
404
      .RxE_IRQ(RxE_IRQ),
405
 
406
      .RxB_IRQ(RxB_IRQ),
407
      .TxE_IRQ(TxE_IRQ),
408
      .TxB_IRQ(TxB_IRQ),
409
 
410
      .r_IPGT(r_IPGT),
411
 
412
      .r_IPGR1(r_IPGR1),
413
      .r_IPGR2(r_IPGR2),
414
      .r_MinFL(r_MinFL),
415
 
416
      .r_MaxFL(r_MaxFL),
417
      .r_MaxRet(r_MaxRet),
418
      .r_CollValid(r_CollValid),
419
 
420
      .r_TxFlow(r_TxFlow),
421
      .r_RxFlow(r_RxFlow),
422
      .r_PassAll(r_PassAll),
423
 
424
      .r_MiiNoPre(r_MiiNoPre),
425
      .r_ClkDiv(r_ClkDiv),
426
 
427
      .r_WCtrlData(r_WCtrlData),
428
      .r_RStat(r_RStat),
429
      .r_ScanStat(r_ScanStat),
430
 
431
      .r_RGAD(r_RGAD),
432
      .r_FIAD(r_FIAD),
433
      .r_CtrlData(r_CtrlData),
434
 
435
      .NValid_stat(NValid_stat),
436
      .Busy_stat(Busy_stat),
437
 
438
      .LinkFail(LinkFail),
439
      .r_MAC(r_MAC),
440
      .WCtrlDataStart(WCtrlDataStart),
441
 
442
      .RStatStart(RStatStart),
443
      .UpdateMIIRX_DATAReg(UpdateMIIRX_DATAReg),
444
      .Prsd(Prsd),
445
 
446
      .r_TxBDNum(r_TxBDNum),
447
      .int_o(int_o),
448
 
449
      .r_HASH0(r_HASH0),
450
      .r_HASH1(r_HASH1),
451
      .r_TxPauseRq(r_TxPauseRq),
452
 
453
      .r_TxPauseTV(r_TxPauseTV),
454
      .RstTxPauseRq(RstTxPauseRq),
455
      .TxCtrlEndFrm(TxCtrlEndFrm),
456
 
457
      .StartTxDone(StartTxDone),
458
      .TxClk(mtx_clk_pad_i),
459
      .RxClk(mrx_clk_pad_i),
460
 
461
      .dbg_dat(wb_dbg_dat0),
462
 
463
      .SetPauseTimer(SetPauseTimer)
464
 
465
      );
466 408 julius
 
467
 
468
 
469 439 julius
   wire  [7:0] RxData;
470
   wire        RxValid;
471
   wire        RxStartFrm;
472
   wire        RxEndFrm;
473
   wire        RxAbort;
474 408 julius
 
475 439 julius
   wire        WillTransmit;            // Will transmit (to RxEthMAC)
476
   wire        ResetCollision;          // Reset Collision (for synchronizing 
477
                                        // collision)
478
   wire [7:0]  TxDataOut;               // Transmit Packet Data (to TxEthMAC)
479
   wire        WillSendControlFrame;
480
   wire        ReceiveEnd;
481
   wire        ReceivedPacketGood;
482
   wire        ReceivedLengthOK;
483
   wire        InvalidSymbol;
484
   wire        LatchedCrcError;
485
   wire        RxLateCollision;
486
   wire [3:0]  RetryCntLatched;
487
   wire [3:0]  RetryCnt;
488
   wire        StartTxAbort;
489
   wire        MaxCollisionOccured;
490
   wire        RetryLimit;
491
   wire        StatePreamble;
492
   wire [1:0]  StateData;
493 408 julius
 
494 439 julius
   // Connecting MACControl
495
   eth_maccontrol maccontrol1
496
     (
497
      .MTxClk(mtx_clk_pad_i),
498
      .TPauseRq(TPauseRq),
499
 
500
      .TxPauseTV(r_TxPauseTV),
501
      .TxDataIn(TxData),
502
 
503
      .TxStartFrmIn(TxStartFrm),
504
      .TxEndFrmIn(TxEndFrm),
505
 
506
      .TxUsedDataIn(TxUsedDataIn),
507
      .TxDoneIn(TxDoneIn),
508
 
509
      .TxAbortIn(TxAbortIn),
510
      .MRxClk(mrx_clk_pad_i),
511
 
512
      .RxData(RxData),
513
      .RxValid(RxValid),
514
 
515
      .RxStartFrm(RxStartFrm),
516
      .RxEndFrm(RxEndFrm),
517
 
518
      .ReceiveEnd(ReceiveEnd),
519
      .ReceivedPacketGood(ReceivedPacketGood),
520
 
521
      .TxFlow(r_TxFlow),
522
 
523
      .RxFlow(r_RxFlow),
524
      .DlyCrcEn(r_DlyCrcEn),
525
 
526
      .MAC(r_MAC),
527
      .PadIn(r_Pad | PerPacketPad),
528
 
529
      .PadOut(PadOut),
530
      .CrcEnIn(r_CrcEn | PerPacketCrcEn),
531
 
532
      .CrcEnOut(CrcEnOut),
533
      .TxReset(wb_rst_i),
534
 
535
      .RxReset(wb_rst_i),
536
      .ReceivedLengthOK(ReceivedLengthOK),
537
 
538
      .TxDataOut(TxDataOut),
539
      .TxStartFrmOut(TxStartFrmOut),
540
 
541
      .TxEndFrmOut(TxEndFrmOut),
542
      .TxUsedDataOut(TxUsedData),
543
 
544
      .TxDoneOut(TxDone),
545
      .TxAbortOut(TxAbort),
546
 
547
      .WillSendControlFrame(WillSendControlFrame),
548
      .TxCtrlEndFrm(TxCtrlEndFrm),
549
 
550
      .ReceivedPauseFrm(ReceivedPauseFrm),
551
      .ControlFrmAddressOK(ControlFrmAddressOK),
552
 
553
      .SetPauseTimer(SetPauseTimer),
554
 
555
      .RxStatusWriteLatched_sync2(RxStatusWriteLatched_sync2),
556
      .r_PassAll(r_PassAll)
557
      );
558 408 julius
 
559
 
560
 
561 439 julius
   wire        TxCarrierSense;          // Synchronized CarrierSense (to Tx 
562
                                        // clock)
563
   wire        Collision;               // Synchronized Collision
564 408 julius
 
565 439 julius
   reg         CarrierSense_Tx1;
566
   reg         CarrierSense_Tx2;
567
   reg         Collision_Tx1;
568
   reg         Collision_Tx2;
569 408 julius
 
570 439 julius
   reg         RxEnSync;                 // Synchronized Receive Enable
571
   reg         WillTransmit_q;
572
   reg         WillTransmit_q2;
573 408 julius
 
574
 
575
 
576 439 julius
   // Muxed MII receive data valid
577
   assign MRxDV_Lb = r_LoopBck? mtxen_pad_o : mrxdv_pad_i & RxEnSync;
578 408 julius
 
579 439 julius
   // Muxed MII Receive Error
580
   assign MRxErr_Lb = r_LoopBck? mtxerr_pad_o : mrxerr_pad_i & RxEnSync;
581 408 julius
 
582 439 julius
   // Muxed MII Receive Data
583
   assign MRxD_Lb[3:0] = r_LoopBck? mtxd_pad_o[3:0] : mrxd_pad_i[3:0];
584 408 julius
 
585
 
586
 
587 439 julius
   // Connecting TxEthMAC
588
   eth_txethmac txethmac1
589
     (
590
 
591
      .MTxClk(mtx_clk_pad_i),
592
      .Reset(wb_rst_i),
593
      .CarrierSense(TxCarrierSense),
594
 
595
      .Collision(Collision),
596
      .TxData(TxDataOut),
597
      .TxStartFrm(TxStartFrmOut),
598
 
599
      .TxUnderRun(TxUnderRun),
600
      .TxEndFrm(TxEndFrmOut),
601
      .Pad(PadOut),
602
 
603
      .MinFL(r_MinFL),
604
      .CrcEn(CrcEnOut),
605
      .FullD(r_FullD),
606
 
607
      .HugEn(r_HugEn),
608
      .DlyCrcEn(r_DlyCrcEn),
609
      .IPGT(r_IPGT),
610
 
611
      .IPGR1(r_IPGR1),
612
      .IPGR2(r_IPGR2),
613
      .CollValid(r_CollValid),
614
 
615
      .MaxRet(r_MaxRet),
616
      .NoBckof(r_NoBckof),
617
      .ExDfrEn(r_ExDfrEn),
618
 
619
      .MaxFL(r_MaxFL),
620
      .MTxEn(mtxen_pad_o),
621
      .MTxD(mtxd_pad_o),
622
 
623
      .MTxErr(mtxerr_pad_o),
624
      .TxUsedData(TxUsedDataIn),
625
      .TxDone(TxDoneIn),
626
 
627
      .TxRetry(TxRetry),
628
      .TxAbort(TxAbortIn),
629
      .WillTransmit(WillTransmit),
630
 
631
      .ResetCollision(ResetCollision),
632
      .RetryCnt(RetryCnt),
633
      .StartTxDone(StartTxDone),
634
 
635
      .StartTxAbort(StartTxAbort),
636
      .MaxCollisionOccured(MaxCollisionOccured),
637
      .LateCollision(LateCollision),
638
 
639
      .DeferIndication(DeferIndication),
640
      .StatePreamble(StatePreamble),
641
      .StateData(StateData)
642
      );
643 408 julius
 
644
 
645
 
646
 
647 439 julius
   wire [15:0] RxByteCnt;
648
   wire        RxByteCntEq0;
649
   wire        RxByteCntGreat2;
650
   wire        RxByteCntMaxFrame;
651
   wire        RxCrcError;
652
   wire        RxStateIdle;
653
   wire        RxStatePreamble;
654
   wire        RxStateSFD;
655
   wire [1:0]  RxStateData;
656
   wire        AddressMiss;
657 408 julius
 
658
 
659
 
660 439 julius
   // Connecting RxEthMAC
661
   eth_rxethmac rxethmac1
662
     (
663
 
664
      .MRxClk(mrx_clk_pad_i),
665
      .MRxDV(MRxDV_Lb),
666
      .MRxD(MRxD_Lb),
667
 
668
      .Transmitting(Transmitting),
669
      .HugEn(r_HugEn),
670
      .DlyCrcEn(r_DlyCrcEn),
671
 
672
      .MaxFL(r_MaxFL),
673
      .r_IFG(r_IFG),
674
      .Reset(wb_rst_i),
675
 
676
      .RxData(RxData),
677
      .RxValid(RxValid),
678
      .RxStartFrm(RxStartFrm),
679
 
680
      .RxEndFrm(RxEndFrm),
681
      .ByteCnt(RxByteCnt),
682
 
683
      .ByteCntEq0(RxByteCntEq0),
684
      .ByteCntGreat2(RxByteCntGreat2),
685
      .ByteCntMaxFrame(RxByteCntMaxFrame),
686
 
687
      .CrcError(RxCrcError),
688
      .StateIdle(RxStateIdle),
689
      .StatePreamble(RxStatePreamble),
690
 
691
      .StateSFD(RxStateSFD),
692
      .StateData(RxStateData),
693
 
694
      .MAC(r_MAC),
695
      .r_Pro(r_Pro),
696
      .r_Bro(r_Bro),
697
 
698
      .r_HASH0(r_HASH0),
699
      .r_HASH1(r_HASH1),
700
      .RxAbort(RxAbort),
701
 
702
      .AddressMiss(AddressMiss),
703
      .PassAll(r_PassAll),
704
      .ControlFrmAddressOK(ControlFrmAddressOK)
705
      );
706 408 julius
 
707
 
708 439 julius
   // MII Carrier Sense Synchronization
709
   always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
710
     begin
711
        if(wb_rst_i)
712
          begin
713
             CarrierSense_Tx1 <=  1'b0;
714
             CarrierSense_Tx2 <=  1'b0;
715
          end
716
        else
717
          begin
718
             CarrierSense_Tx1 <=  mcrs_pad_i;
719
             CarrierSense_Tx2 <=  CarrierSense_Tx1;
720
          end
721
     end
722 408 julius
 
723 439 julius
   assign TxCarrierSense = ~r_FullD & CarrierSense_Tx2;
724 408 julius
 
725
 
726 439 julius
   // MII Collision Synchronization
727
   always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
728
     begin
729
        if(wb_rst_i)
730
          begin
731
             Collision_Tx1 <=  1'b0;
732
             Collision_Tx2 <=  1'b0;
733
          end
734
        else
735
          begin
736
             Collision_Tx1 <=  mcoll_pad_i;
737
             if(ResetCollision)
738
               Collision_Tx2 <=  1'b0;
739
             else
740
               if(Collision_Tx1)
741
                 Collision_Tx2 <=  1'b1;
742
          end
743
     end
744 408 julius
 
745
 
746 439 julius
   // Synchronized Collision
747
   assign Collision = ~r_FullD & Collision_Tx2;
748 408 julius
 
749
 
750
 
751 439 julius
   // Delayed WillTransmit
752
   always @ (posedge mrx_clk_pad_i)
753
     begin
754
        WillTransmit_q <=  WillTransmit;
755
        WillTransmit_q2 <=  WillTransmit_q;
756
     end
757 408 julius
 
758
 
759 439 julius
   assign Transmitting = ~r_FullD & WillTransmit_q2;
760 408 julius
 
761
 
762
 
763 439 julius
   // Synchronized Receive Enable
764
   always @ (posedge mrx_clk_pad_i or posedge wb_rst_i)
765
     begin
766
        if(wb_rst_i)
767
          RxEnSync <=  1'b0;
768
        else
769
          if(~mrxdv_pad_i)
770
            RxEnSync <=  r_RxEn;
771
     end
772 408 julius
 
773
 
774
 
775 439 julius
   // Synchronizing WillSendControlFrame to WB_CLK;
776
   always @ (posedge wb_clk_i or posedge wb_rst_i)
777
     begin
778
        if(wb_rst_i)
779
          WillSendControlFrame_sync1 <= 1'b0;
780
        else
781
          WillSendControlFrame_sync1 <= WillSendControlFrame;
782
     end
783 408 julius
 
784 439 julius
   always @ (posedge wb_clk_i or posedge wb_rst_i)
785
     begin
786
        if(wb_rst_i)
787
          WillSendControlFrame_sync2 <= 1'b0;
788
        else
789
          WillSendControlFrame_sync2 <= WillSendControlFrame_sync1;
790
     end
791 408 julius
 
792 439 julius
   always @ (posedge wb_clk_i or posedge wb_rst_i)
793
     begin
794
        if(wb_rst_i)
795
          WillSendControlFrame_sync3 <= 1'b0;
796
        else
797
          WillSendControlFrame_sync3 <= WillSendControlFrame_sync2;
798
     end
799 408 julius
 
800 439 julius
   always @ (posedge wb_clk_i or posedge wb_rst_i)
801
     begin
802
        if(wb_rst_i)
803
          RstTxPauseRq <= 1'b0;
804
        else
805
          RstTxPauseRq <= WillSendControlFrame_sync2 &
806
                          ~WillSendControlFrame_sync3;
807
     end
808 408 julius
 
809
 
810
 
811
 
812 439 julius
   // TX Pause request Synchronization
813
   always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
814
     begin
815
        if(wb_rst_i)
816
          begin
817
             TxPauseRq_sync1 <=  1'b0;
818
             TxPauseRq_sync2 <=  1'b0;
819
             TxPauseRq_sync3 <=  1'b0;
820
          end
821
        else
822
          begin
823
             TxPauseRq_sync1 <=  (r_TxPauseRq & r_TxFlow);
824
             TxPauseRq_sync2 <=  TxPauseRq_sync1;
825
             TxPauseRq_sync3 <=  TxPauseRq_sync2;
826
          end
827
     end
828 408 julius
 
829
 
830 439 julius
   always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
831
     begin
832
        if(wb_rst_i)
833
          TPauseRq <=  1'b0;
834
        else
835
          TPauseRq <=  TxPauseRq_sync2 & (~TxPauseRq_sync3);
836
     end
837 408 julius
 
838
 
839 439 julius
   wire LatchedMRxErr;
840
   reg  RxAbort_latch;
841
   reg  RxAbort_sync1;
842
   reg  RxAbort_wb;
843
   reg  RxAbortRst_sync1;
844
   reg  RxAbortRst;
845 408 julius
 
846 439 julius
   // Synchronizing RxAbort to the WISHBONE clock
847
   always @ (posedge mrx_clk_pad_i or posedge wb_rst_i)
848
     begin
849
        if(wb_rst_i)
850
          RxAbort_latch <=  1'b0;
851
        else if(RxAbort | (ShortFrame & ~r_RecSmall) | LatchedMRxErr &
852
                ~InvalidSymbol | (ReceivedPauseFrm & (~r_PassAll)))
853
          RxAbort_latch <=  1'b1;
854
        else if(RxAbortRst)
855
          RxAbort_latch <=  1'b0;
856
     end
857 408 julius
 
858 439 julius
   always @ (posedge wb_clk_i or posedge wb_rst_i)
859
     begin
860
        if(wb_rst_i)
861
          begin
862
             RxAbort_sync1 <=  1'b0;
863
             RxAbort_wb    <=  1'b0;
864
             RxAbort_wb    <=  1'b0;
865
          end
866
        else
867
          begin
868
             RxAbort_sync1 <=  RxAbort_latch;
869
             RxAbort_wb    <=  RxAbort_sync1;
870
          end
871
     end
872 408 julius
 
873 439 julius
   always @ (posedge mrx_clk_pad_i or posedge wb_rst_i)
874
     begin
875
        if(wb_rst_i)
876
          begin
877
             RxAbortRst_sync1 <=  1'b0;
878
             RxAbortRst       <=  1'b0;
879
          end
880
        else
881
          begin
882
             RxAbortRst_sync1 <=  RxAbort_wb;
883
             RxAbortRst       <=  RxAbortRst_sync1;
884
          end
885
     end
886 408 julius
 
887
 
888
 
889 439 julius
   // Connecting Wishbone module
890
   eth_wishbone wishbone
891
     (
892
 
893
      .WB_CLK_I(wb_clk_i),
894
      .WB_DAT_I(wb_dat_i),
895
 
896
      .WB_DAT_O(BD_WB_DAT_O),
897 408 julius
 
898 439 julius
      // WISHBONE slave
899
 
900
      .WB_ADR_I(wb_adr_i[9:2]),
901
      .WB_WE_I(wb_we_i),
902
 
903
      .BDCs(BDCs),
904
      .WB_ACK_O(BDAck),
905 408 julius
 
906 439 julius
 
907
      .Reset(wb_rst_i),
908 408 julius
 
909 439 julius
      // WISHBONE master
910
 
911
      .m_wb_adr_o(m_wb_adr_tmp),
912
      .m_wb_sel_o(m_wb_sel_o),
913
      .m_wb_we_o(m_wb_we_o),
914
 
915
      .m_wb_dat_i(m_wb_dat_i),
916
      .m_wb_dat_o(m_wb_dat_o),
917
      .m_wb_cyc_o(m_wb_cyc_o),
918
 
919
      .m_wb_stb_o(m_wb_stb_o),
920
      .m_wb_ack_i(m_wb_ack_i),
921
      .m_wb_err_i(m_wb_err_i),
922
 
923 408 julius
`ifdef ETH_WISHBONE_B3
924 439 julius
 
925
      .m_wb_cti_o(m_wb_cti_o),
926
      .m_wb_bte_o(m_wb_bte_o),
927 408 julius
`endif
928 439 julius
 
929 408 julius
 
930 439 julius
      //TX
931
 
932
      .MTxClk(mtx_clk_pad_i),
933
      .TxStartFrm(TxStartFrm),
934
      .TxEndFrm(TxEndFrm),
935
 
936
      .TxUsedData(TxUsedData),
937
      .TxData(TxData),
938
 
939
      .TxRetry(TxRetry),
940
      .TxAbort(TxAbort),
941
      .TxUnderRun(TxUnderRun),
942
 
943
      .TxDone(TxDone),
944
 
945
      .PerPacketCrcEn(PerPacketCrcEn),
946
      .PerPacketPad(PerPacketPad),
947 408 julius
 
948 439 julius
      // Register
949
 
950
      .r_TxEn(r_TxEn),
951
      .r_RxEn(r_RxEn),
952
      .r_TxBDNum(r_TxBDNum),
953
 
954
      .r_RxFlow(r_RxFlow),
955
      .r_PassAll(r_PassAll),
956 408 julius
 
957 439 julius
      //RX
958
 
959
      .MRxClk(mrx_clk_pad_i),
960
      .RxData(RxData),
961
      .RxValid(RxValid),
962
 
963
      .RxStartFrm(RxStartFrm),
964
      .RxEndFrm(RxEndFrm),
965
 
966
      .Busy_IRQ(Busy_IRQ),
967
      .RxE_IRQ(RxE_IRQ),
968
      .RxB_IRQ(RxB_IRQ),
969
 
970
      .TxE_IRQ(TxE_IRQ),
971
      .TxB_IRQ(TxB_IRQ),
972 408 julius
 
973 439 julius
 
974
      .RxAbort(RxAbort_wb),
975
      .RxStatusWriteLatched_sync2(RxStatusWriteLatched_sync2),
976 408 julius
 
977 439 julius
 
978
      .InvalidSymbol(InvalidSymbol),
979
      .LatchedCrcError(LatchedCrcError),
980
      .RxLength(RxByteCnt),
981
 
982
      .RxLateCollision(RxLateCollision),
983
      .ShortFrame(ShortFrame),
984
      .DribbleNibble(DribbleNibble),
985
 
986
      .ReceivedPacketTooBig(ReceivedPacketTooBig),
987
      .LoadRxStatus(LoadRxStatus),
988
      .RetryCntLatched(RetryCntLatched),
989
 
990
      .RetryLimit(RetryLimit),
991
      .LateCollLatched(LateCollLatched),
992
      .DeferLatched(DeferLatched),
993
 
994
      .RstDeferLatched(RstDeferLatched),
995
 
996
      .CarrierSenseLost(CarrierSenseLost),
997
      .ReceivedPacketGood(ReceivedPacketGood),
998
      .AddressMiss(AddressMiss),
999
 
1000
      .ReceivedPauseFrm(ReceivedPauseFrm)
1001
 
1002 408 julius
`ifdef ETH_BIST
1003 439 julius
      ,
1004
 
1005
      .mbist_si_i       (mbist_si_i),
1006
 
1007
      .mbist_so_o       (mbist_so_o),
1008
 
1009
      .mbist_ctrl_i       (mbist_ctrl_i)
1010 408 julius
`endif
1011 439 julius
`ifdef WISHBONE_DEBUG
1012
      ,
1013
 
1014
      .dbg_dat0(wb_dbg_dat0)
1015 408 julius
`endif
1016
 
1017 439 julius
      );
1018 408 julius
 
1019 439 julius
   assign m_wb_adr_o = {m_wb_adr_tmp, 2'h0};
1020 408 julius
 
1021 439 julius
   // Connecting MacStatus module
1022
   eth_macstatus macstatus1
1023
     (
1024
 
1025
      .MRxClk(mrx_clk_pad_i),
1026
      .Reset(wb_rst_i),
1027
 
1028
      .ReceiveEnd(ReceiveEnd),
1029
      .ReceivedPacketGood(ReceivedPacketGood),
1030
      .ReceivedLengthOK(ReceivedLengthOK),
1031
 
1032
      .RxCrcError(RxCrcError),
1033
      .MRxErr(MRxErr_Lb),
1034
      .MRxDV(MRxDV_Lb),
1035
 
1036
      .RxStateSFD(RxStateSFD),
1037
      .RxStateData(RxStateData),
1038
      .RxStatePreamble(RxStatePreamble),
1039
 
1040
      .RxStateIdle(RxStateIdle),
1041
      .Transmitting(Transmitting),
1042
      .RxByteCnt(RxByteCnt),
1043
 
1044
      .RxByteCntEq0(RxByteCntEq0),
1045
      .RxByteCntGreat2(RxByteCntGreat2),
1046
      .RxByteCntMaxFrame(RxByteCntMaxFrame),
1047
 
1048
      .InvalidSymbol(InvalidSymbol),
1049
 
1050
      .MRxD(MRxD_Lb),
1051
      .LatchedCrcError(LatchedCrcError),
1052
      .Collision(mcoll_pad_i),
1053
 
1054
      .CollValid(r_CollValid),
1055
      .RxLateCollision(RxLateCollision),
1056
      .r_RecSmall(r_RecSmall),
1057
 
1058
      .r_MinFL(r_MinFL),
1059
      .r_MaxFL(r_MaxFL),
1060
      .ShortFrame(ShortFrame),
1061
 
1062
      .DribbleNibble(DribbleNibble),
1063
      .ReceivedPacketTooBig(ReceivedPacketTooBig),
1064
      .r_HugEn(r_HugEn),
1065
 
1066
      .LoadRxStatus(LoadRxStatus),
1067
      .RetryCnt(RetryCnt),
1068
      .StartTxDone(StartTxDone),
1069
 
1070
      .StartTxAbort(StartTxAbort),
1071
      .RetryCntLatched(RetryCntLatched),
1072
      .MTxClk(mtx_clk_pad_i),
1073
 
1074
      .MaxCollisionOccured(MaxCollisionOccured),
1075
      .RetryLimit(RetryLimit),
1076
      .LateCollision(LateCollision),
1077
 
1078
      .LateCollLatched(LateCollLatched),
1079
      .DeferIndication(DeferIndication),
1080
      .DeferLatched(DeferLatched),
1081
 
1082
      .RstDeferLatched(RstDeferLatched),
1083
 
1084
      .TxStartFrm(TxStartFrmOut),
1085
      .StatePreamble(StatePreamble),
1086
      .StateData(StateData),
1087
 
1088
      .CarrierSense(CarrierSense_Tx2),
1089
      .CarrierSenseLost(CarrierSenseLost),
1090
      .TxUsedData(TxUsedDataIn),
1091
 
1092
      .LatchedMRxErr(LatchedMRxErr),
1093
      .Loopback(r_LoopBck),
1094
      .r_FullD(r_FullD)
1095
      );
1096 408 julius
 
1097
 
1098
endmodule

powered by: WebSVN 2.1.0

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