| 1 |
15 |
mohor |
//////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//// ////
|
| 3 |
|
|
//// eth_top.v ////
|
| 4 |
|
|
//// ////
|
| 5 |
|
|
//// This file is part of the Ethernet IP core project ////
|
| 6 |
|
|
//// http://www.opencores.org/cores/ethmac/ ////
|
| 7 |
|
|
//// ////
|
| 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 |
17 |
mohor |
// Revision 1.1 2001/08/06 14:44:29 mohor
|
| 45 |
|
|
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
|
| 46 |
|
|
// Include files fixed to contain no path.
|
| 47 |
|
|
// File names and module names changed ta have a eth_ prologue in the name.
|
| 48 |
|
|
// File eth_timescale.v is used to define timescale
|
| 49 |
|
|
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
|
| 50 |
|
|
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
|
| 51 |
|
|
// and Mdo_OE. The bidirectional signal must be created on the top level. This
|
| 52 |
|
|
// is done due to the ASIC tools.
|
| 53 |
|
|
//
|
| 54 |
15 |
mohor |
// Revision 1.2 2001/08/02 09:25:31 mohor
|
| 55 |
|
|
// Unconnected signals are now connected.
|
| 56 |
|
|
//
|
| 57 |
|
|
// Revision 1.1 2001/07/30 21:23:42 mohor
|
| 58 |
|
|
// Directory structure changed. Files checked and joind together.
|
| 59 |
|
|
//
|
| 60 |
|
|
//
|
| 61 |
|
|
//
|
| 62 |
|
|
//
|
| 63 |
|
|
//
|
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
|
| 67 |
|
|
`include "eth_defines.v"
|
| 68 |
|
|
`include "eth_timescale.v"
|
| 69 |
|
|
|
| 70 |
|
|
|
| 71 |
|
|
module eth_top
|
| 72 |
|
|
(
|
| 73 |
|
|
// WISHBONE common
|
| 74 |
17 |
mohor |
wb_clk_i, wb_rst_i, wb_dat_i, wb_dat_o,
|
| 75 |
15 |
mohor |
|
| 76 |
|
|
// WISHBONE slave
|
| 77 |
17 |
mohor |
wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i, wb_stb_i, wb_ack_o, wb_err_o,
|
| 78 |
|
|
wb_req_o, wb_ack_i, wb_nd_o, wb_rd_o,
|
| 79 |
15 |
mohor |
|
| 80 |
|
|
//TX
|
| 81 |
17 |
mohor |
mtxclk_pad_i, mtxd_pad_o, mtxen_pad_o, mtxerr_pad_o,
|
| 82 |
15 |
mohor |
|
| 83 |
|
|
//RX
|
| 84 |
17 |
mohor |
mrxclk_pad_i, mrxd_pad_i, mrxdv_pad_i, mrxerr_pad_i, mcoll_pad_i, mcrs_pad_i,
|
| 85 |
15 |
mohor |
|
| 86 |
|
|
// MIIM
|
| 87 |
17 |
mohor |
mdc_pad_o, md_pad_i, md_pad_o, md_pad_oe
|
| 88 |
|
|
|
| 89 |
|
|
|
| 90 |
15 |
mohor |
);
|
| 91 |
|
|
|
| 92 |
|
|
|
| 93 |
|
|
parameter Tp = 1;
|
| 94 |
|
|
|
| 95 |
|
|
|
| 96 |
|
|
// WISHBONE common
|
| 97 |
17 |
mohor |
input wb_clk_i; // WISHBONE clock
|
| 98 |
|
|
input wb_rst_i; // WISHBONE reset
|
| 99 |
|
|
input [31:0] wb_dat_i; // WISHBONE data input
|
| 100 |
|
|
output [31:0] wb_dat_o; // WISHBONE data output
|
| 101 |
|
|
output wb_err_o; // WISHBONE error output
|
| 102 |
15 |
mohor |
|
| 103 |
|
|
// WISHBONE slave
|
| 104 |
17 |
mohor |
input [31:0] wb_adr_i; // WISHBONE address input
|
| 105 |
|
|
input [3:0] wb_sel_i; // WISHBONE byte select input
|
| 106 |
|
|
input wb_we_i; // WISHBONE write enable input
|
| 107 |
|
|
input wb_cyc_i; // WISHBONE cycle input
|
| 108 |
|
|
input wb_stb_i; // WISHBONE strobe input
|
| 109 |
|
|
output wb_ack_o; // WISHBONE acknowledge output
|
| 110 |
15 |
mohor |
|
| 111 |
|
|
// DMA
|
| 112 |
17 |
mohor |
input [1:0] wb_ack_i; // DMA acknowledge input
|
| 113 |
|
|
output [1:0] wb_req_o; // DMA request output
|
| 114 |
|
|
output [1:0] wb_nd_o; // DMA force new descriptor output
|
| 115 |
|
|
output wb_rd_o; // DMA restart descriptor output
|
| 116 |
15 |
mohor |
|
| 117 |
|
|
// Tx
|
| 118 |
17 |
mohor |
input mtxclk_pad_i; // Transmit clock (from PHY)
|
| 119 |
|
|
output [3:0] mtxd_pad_o; // Transmit nibble (to PHY)
|
| 120 |
|
|
output mtxen_pad_o; // Transmit enable (to PHY)
|
| 121 |
|
|
output mtxerr_pad_o; // Transmit error (to PHY)
|
| 122 |
15 |
mohor |
|
| 123 |
|
|
// Rx
|
| 124 |
17 |
mohor |
input mrxclk_pad_i; // Receive clock (from PHY)
|
| 125 |
|
|
input [3:0] mrxd_pad_i; // Receive nibble (from PHY)
|
| 126 |
|
|
input mrxdv_pad_i; // Receive data valid (from PHY)
|
| 127 |
|
|
input mrxerr_pad_i; // Receive data error (from PHY)
|
| 128 |
15 |
mohor |
|
| 129 |
|
|
// Common Tx and Rx
|
| 130 |
17 |
mohor |
input mcoll_pad_i; // Collision (from PHY)
|
| 131 |
|
|
input mcrs_pad_i; // Carrier sense (from PHY)
|
| 132 |
15 |
mohor |
|
| 133 |
|
|
// MII Management interface
|
| 134 |
17 |
mohor |
input md_pad_i; // MII data input (from I/O cell)
|
| 135 |
|
|
output mdc_pad_o; // MII Management data clock (to PHY)
|
| 136 |
|
|
output md_pad_o; // MII data output (to I/O cell)
|
| 137 |
|
|
output md_pad_oe; // MII data output enable (to I/O cell)
|
| 138 |
15 |
mohor |
|
| 139 |
|
|
|
| 140 |
|
|
wire [7:0] r_ClkDiv;
|
| 141 |
|
|
wire r_MiiNoPre;
|
| 142 |
|
|
wire [15:0] r_CtrlData;
|
| 143 |
|
|
wire [4:0] r_FIAD;
|
| 144 |
|
|
wire [4:0] r_RGAD;
|
| 145 |
|
|
wire r_WCtrlData;
|
| 146 |
|
|
wire r_RStat;
|
| 147 |
|
|
wire r_ScanStat;
|
| 148 |
|
|
wire NValid_stat;
|
| 149 |
|
|
wire Busy_stat;
|
| 150 |
|
|
wire LinkFail;
|
| 151 |
|
|
wire r_MiiMRst;
|
| 152 |
|
|
wire [15:0] Prsd; // Read Status Data (data read from the PHY)
|
| 153 |
|
|
wire WCtrlDataStart;
|
| 154 |
|
|
wire RStatStart;
|
| 155 |
|
|
wire UpdateMIIRX_DATAReg;
|
| 156 |
|
|
|
| 157 |
|
|
wire TxStartFrm;
|
| 158 |
|
|
wire TxEndFrm;
|
| 159 |
|
|
wire TxUsedData;
|
| 160 |
|
|
wire [7:0] TxData;
|
| 161 |
|
|
wire TxRetry;
|
| 162 |
|
|
wire TxAbort;
|
| 163 |
|
|
wire TxUnderRun;
|
| 164 |
|
|
wire TxDone;
|
| 165 |
|
|
|
| 166 |
|
|
|
| 167 |
|
|
|
| 168 |
|
|
|
| 169 |
|
|
// Connecting Miim module
|
| 170 |
|
|
eth_miim miim1
|
| 171 |
|
|
(
|
| 172 |
17 |
mohor |
.Clk(wb_clk_i), .Reset(r_MiiMRst), .Divider(r_ClkDiv),
|
| 173 |
15 |
mohor |
.NoPre(r_MiiNoPre), .CtrlData(r_CtrlData), .Rgad(r_RGAD),
|
| 174 |
|
|
.Fiad(r_FIAD), .WCtrlData(r_WCtrlData), .RStat(r_RStat),
|
| 175 |
17 |
mohor |
.ScanStat(r_ScanStat), .Mdi(md_pad_i), .Mdo(md_pad_o),
|
| 176 |
|
|
.MdoEn(md_pad_oe), .Mdc(mdc_pad_o), .Busy(Busy_stat),
|
| 177 |
15 |
mohor |
.Prsd(Prsd), .LinkFail(LinkFail), .Nvalid(NValid_stat),
|
| 178 |
|
|
.WCtrlDataStart(WCtrlDataStart), .RStatStart(RStatStart), .UpdateMIIRX_DATAReg(UpdateMIIRX_DATAReg)
|
| 179 |
|
|
);
|
| 180 |
|
|
|
| 181 |
|
|
|
| 182 |
|
|
|
| 183 |
|
|
|
| 184 |
|
|
wire RegCs; // Connected to registers
|
| 185 |
17 |
mohor |
wire [31:0] RegDataOut; // Multiplexed to wb_dat_o
|
| 186 |
15 |
mohor |
wire r_DmaEn; // DMA enable
|
| 187 |
|
|
wire r_Rst; // Reset
|
| 188 |
|
|
wire r_LoopBck; // Loopback
|
| 189 |
|
|
wire r_TxEn; // Tx Enable
|
| 190 |
|
|
wire r_RxEn; // Rx Enable
|
| 191 |
|
|
|
| 192 |
|
|
wire MRxDV_Lb; // Muxed MII receive data valid
|
| 193 |
|
|
wire MRxErr_Lb; // Muxed MII Receive Error
|
| 194 |
|
|
wire [3:0] MRxD_Lb; // Muxed MII Receive Data
|
| 195 |
|
|
wire Transmitting; // Indication that TxEthMAC is transmitting
|
| 196 |
|
|
wire r_HugEn; // Huge packet enable
|
| 197 |
|
|
wire r_DlyCrcEn; // Delayed CRC enabled
|
| 198 |
|
|
wire [15:0] r_MaxFL; // Maximum frame length
|
| 199 |
|
|
|
| 200 |
|
|
wire [15:0] r_MinFL; // Minimum frame length
|
| 201 |
|
|
wire [47:0] r_MAC; // MAC address
|
| 202 |
|
|
|
| 203 |
|
|
wire [7:0] r_RxBDAddress; // Receive buffer descriptor base address
|
| 204 |
|
|
wire [6:0] r_IPGT; //
|
| 205 |
|
|
wire [6:0] r_IPGR1; //
|
| 206 |
|
|
wire [6:0] r_IPGR2; //
|
| 207 |
|
|
wire [5:0] r_CollValid; //
|
| 208 |
|
|
wire r_TPauseRq; // Transmit PAUSE request pulse
|
| 209 |
|
|
|
| 210 |
|
|
wire [3:0] r_MaxRet; //
|
| 211 |
|
|
wire r_NoBckof; //
|
| 212 |
|
|
wire r_ExDfrEn; //
|
| 213 |
|
|
wire RX_BD_ADR_Wr; // Write enable that writes RX_BD_ADR to the registers.
|
| 214 |
|
|
wire TPauseRq; // Sinhronized Tx PAUSE request
|
| 215 |
|
|
wire [15:0] TxPauseTV; // Tx PAUSE timer value
|
| 216 |
|
|
wire r_TxFlow; // Tx flow control enable
|
| 217 |
|
|
wire r_IFG; // Minimum interframe gap for incoming packets
|
| 218 |
|
|
|
| 219 |
|
|
wire EthAddMatch;
|
| 220 |
|
|
wire WB_STB_I_eth;
|
| 221 |
|
|
wire WB_CYC_I_eth;
|
| 222 |
|
|
|
| 223 |
|
|
wire DWord;
|
| 224 |
|
|
wire RegAck;
|
| 225 |
|
|
wire BDAck;
|
| 226 |
17 |
mohor |
wire [31:0] DMA_WB_DAT_O; // wb_dat_o that comes from the WishboneDMA module
|
| 227 |
15 |
mohor |
|
| 228 |
|
|
|
| 229 |
|
|
|
| 230 |
17 |
mohor |
assign EthAddMatch = wb_adr_i[31:16] == `ETHERNET_SPACE;
|
| 231 |
|
|
assign WB_STB_I_eth = wb_stb_i & EthAddMatch;
|
| 232 |
|
|
assign WB_CYC_I_eth = wb_stb_i & EthAddMatch;
|
| 233 |
15 |
mohor |
|
| 234 |
17 |
mohor |
assign wb_err_o = wb_stb_i & wb_cyc_i & EthAddMatch & ~DWord;
|
| 235 |
|
|
assign DWord = &wb_sel_i;
|
| 236 |
|
|
assign RegCs = wb_stb_i & wb_cyc_i & DWord & EthAddMatch & (wb_adr_i[15:12] == `REG_SPACE);
|
| 237 |
15 |
mohor |
assign RegAck = RegCs;
|
| 238 |
17 |
mohor |
assign wb_ack_o = RegAck | BDAck;
|
| 239 |
15 |
mohor |
|
| 240 |
|
|
|
| 241 |
|
|
// Selecting the WISHBONE output data
|
| 242 |
17 |
mohor |
assign wb_dat_o[31:0] = (RegCs & ~wb_we_i)? RegDataOut : DMA_WB_DAT_O;
|
| 243 |
15 |
mohor |
|
| 244 |
|
|
|
| 245 |
|
|
// Connecting Ethernet registers
|
| 246 |
|
|
eth_registers ethreg1
|
| 247 |
|
|
(
|
| 248 |
17 |
mohor |
.DataIn(wb_dat_i), .Address(wb_adr_i[7:2]), .Rw(wb_we_i),
|
| 249 |
|
|
.Cs(RegCs), .Clk(wb_clk_i), .Reset(wb_rst_i),
|
| 250 |
15 |
mohor |
.DataOut(RegDataOut), .r_DmaEn(r_DmaEn), .r_RecSmall(),
|
| 251 |
|
|
.r_Pad(r_Pad), .r_HugEn(r_HugEn), .r_CrcEn(r_CrcEn),
|
| 252 |
|
|
.r_DlyCrcEn(r_DlyCrcEn), .r_Rst(r_Rst), .r_FullD(r_FullD),
|
| 253 |
|
|
.r_ExDfrEn(r_ExDfrEn), .r_NoBckof(r_NoBckof), .r_LoopBck(r_LoopBck),
|
| 254 |
|
|
.r_IFG(r_IFG), .r_Pro(), .r_Iam(),
|
| 255 |
|
|
.r_Bro(), .r_NoPre(r_NoPre), .r_TxEn(r_TxEn),
|
| 256 |
|
|
.r_RxEn(r_RxEn), .Busy_IRQ(), .RxF_IRQ(),
|
| 257 |
|
|
.RxB_IRQ(), .TxE_IRQ(), .TxB_IRQ(),
|
| 258 |
|
|
.Busy_MASK(), .RxF_MASK(), .RxB_MASK(),
|
| 259 |
|
|
.TxE_MASK(), .TxB_MASK(), .r_IPGT(r_IPGT),
|
| 260 |
|
|
.r_IPGR1(r_IPGR1), .r_IPGR2(r_IPGR2), .r_MinFL(r_MinFL),
|
| 261 |
|
|
.r_MaxFL(r_MaxFL), .r_MaxRet(r_MaxRet), .r_CollValid(r_CollValid),
|
| 262 |
|
|
.r_TxFlow(r_TxFlow), .r_RxFlow(r_RxFlow), .r_PassAll(r_PassAll),
|
| 263 |
|
|
.r_MiiMRst(r_MiiMRst), .r_MiiNoPre(r_MiiNoPre), .r_ClkDiv(r_ClkDiv),
|
| 264 |
|
|
.r_WCtrlData(r_WCtrlData), .r_RStat(r_RStat), .r_ScanStat(r_ScanStat),
|
| 265 |
|
|
.r_RGAD(r_RGAD), .r_FIAD(r_FIAD), .r_CtrlData(r_CtrlData),
|
| 266 |
|
|
.NValid_stat(NValid_stat), .Busy_stat(Busy_stat),
|
| 267 |
|
|
.LinkFail(LinkFail), .r_MAC(r_MAC), .WCtrlDataStart(WCtrlDataStart),
|
| 268 |
|
|
.RStatStart(RStatStart), .UpdateMIIRX_DATAReg(UpdateMIIRX_DATAReg), .Prsd(Prsd),
|
| 269 |
|
|
.r_RxBDAddress(r_RxBDAddress), .RX_BD_ADR_Wr(RX_BD_ADR_Wr)
|
| 270 |
|
|
);
|
| 271 |
|
|
|
| 272 |
|
|
|
| 273 |
|
|
|
| 274 |
|
|
wire [7:0] RxData;
|
| 275 |
|
|
wire RxValid;
|
| 276 |
|
|
wire RxStartFrm;
|
| 277 |
|
|
wire RxEndFrm;
|
| 278 |
|
|
|
| 279 |
|
|
wire WillTransmit; // Will transmit (to RxEthMAC)
|
| 280 |
|
|
wire ResetCollision; // Reset Collision (for synchronizing collision)
|
| 281 |
|
|
wire [7:0] TxDataOut; // Transmit Packet Data (to TxEthMAC)
|
| 282 |
|
|
wire WillSendControlFrame;
|
| 283 |
|
|
wire TxCtrlEndFrm;
|
| 284 |
|
|
wire ReceivedPauseFrm;
|
| 285 |
|
|
wire ReceiveEnd;
|
| 286 |
|
|
wire ReceivedPacketGood;
|
| 287 |
|
|
wire ReceivedLengthOK;
|
| 288 |
|
|
|
| 289 |
|
|
// Connecting MACControl
|
| 290 |
|
|
eth_maccontrol maccontrol1
|
| 291 |
|
|
(
|
| 292 |
17 |
mohor |
.MTxClk(mtxclk_pad_i), .TPauseRq(TPauseRq),
|
| 293 |
15 |
mohor |
.TxPauseTV(TxPauseTV), .TxDataIn(TxData),
|
| 294 |
|
|
.TxStartFrmIn(TxStartFrm), .TxEndFrmIn(TxEndFrm),
|
| 295 |
|
|
.TxUsedDataIn(TxUsedDataIn), .TxDoneIn(TxDoneIn),
|
| 296 |
17 |
mohor |
.TxAbortIn(TxAbortIn), .MRxClk(mrxclk_pad_i),
|
| 297 |
15 |
mohor |
.RxData(RxData), .RxValid(RxValid),
|
| 298 |
|
|
.RxStartFrm(RxStartFrm), .RxEndFrm(RxEndFrm),
|
| 299 |
|
|
.ReceiveEnd(ReceiveEnd), .ReceivedPacketGood(ReceivedPacketGood),
|
| 300 |
|
|
.PassAll(r_PassAll), .TxFlow(r_TxFlow),
|
| 301 |
|
|
.RxFlow(r_RxFlow), .DlyCrcEn(r_DlyCrcEn),
|
| 302 |
|
|
.MAC(r_MAC), .PadIn(r_Pad | PerPacketPad),
|
| 303 |
|
|
.PadOut(PadOut), .CrcEnIn(r_CrcEn | PerPacketCrcEn),
|
| 304 |
|
|
.CrcEnOut(CrcEnOut), .TxReset(r_Rst),
|
| 305 |
|
|
.RxReset(r_Rst), .ReceivedLengthOK(ReceivedLengthOK),
|
| 306 |
|
|
.TxDataOut(TxDataOut), .TxStartFrmOut(TxStartFrmOut),
|
| 307 |
|
|
.TxEndFrmOut(TxEndFrmOut), .TxUsedDataOut(TxUsedData),
|
| 308 |
|
|
.TxDoneOut(TxDone), .TxAbortOut(TxAbort),
|
| 309 |
|
|
.WillSendControlFrame(WillSendControlFrame), .TxCtrlEndFrm(TxCtrlEndFrm),
|
| 310 |
|
|
.ReceivedPauseFrm(ReceivedPauseFrm)
|
| 311 |
|
|
);
|
| 312 |
|
|
|
| 313 |
|
|
|
| 314 |
|
|
|
| 315 |
|
|
wire TxCarrierSense; // Synchronized CarrierSense (to Tx clock)
|
| 316 |
|
|
wire Collision; // Synchronized Collision
|
| 317 |
|
|
|
| 318 |
|
|
reg CarrierSense_Tx1;
|
| 319 |
|
|
reg CarrierSense_Tx2;
|
| 320 |
|
|
reg Collision_Tx1;
|
| 321 |
|
|
reg Collision_Tx2;
|
| 322 |
|
|
|
| 323 |
|
|
reg RxEnSync; // Synchronized Receive Enable
|
| 324 |
|
|
reg CarrierSense_Rx1;
|
| 325 |
|
|
reg RxCarrierSense; // Synchronized CarrierSense (to Rx clock)
|
| 326 |
|
|
reg WillTransmit_q;
|
| 327 |
|
|
reg WillTransmit_q2;
|
| 328 |
|
|
|
| 329 |
|
|
|
| 330 |
|
|
|
| 331 |
|
|
// Muxed MII receive data valid
|
| 332 |
17 |
mohor |
assign MRxDV_Lb = r_LoopBck? mtxen_pad_o : mrxdv_pad_i & RxEnSync;
|
| 333 |
15 |
mohor |
|
| 334 |
|
|
// Muxed MII Receive Error
|
| 335 |
17 |
mohor |
assign MRxErr_Lb = r_LoopBck? mtxerr_pad_o : mrxerr_pad_i & RxEnSync;
|
| 336 |
15 |
mohor |
|
| 337 |
|
|
// Muxed MII Receive Data
|
| 338 |
17 |
mohor |
assign MRxD_Lb[3:0] = r_LoopBck? mtxd_pad_o[3:0] : mrxd_pad_i[3:0];
|
| 339 |
15 |
mohor |
|
| 340 |
|
|
|
| 341 |
|
|
|
| 342 |
|
|
// Connecting TxEthMAC
|
| 343 |
|
|
eth_txethmac txethmac1
|
| 344 |
|
|
(
|
| 345 |
17 |
mohor |
.MTxClk(mtxclk_pad_i), .Reset(r_Rst), .CarrierSense(TxCarrierSense),
|
| 346 |
15 |
mohor |
.Collision(Collision), .TxData(TxDataOut), .TxStartFrm(TxStartFrmOut),
|
| 347 |
|
|
.TxUnderRun(TxUnderRun), .TxEndFrm(TxEndFrmOut), .Pad(PadOut),
|
| 348 |
|
|
.MinFL(r_MinFL), .CrcEn(CrcEnOut), .FullD(r_FullD),
|
| 349 |
|
|
.HugEn(r_HugEn), .DlyCrcEn(r_DlyCrcEn), .IPGT(r_IPGT),
|
| 350 |
|
|
.IPGR1(r_IPGR1), .IPGR2(r_IPGR2), .CollValid(r_CollValid),
|
| 351 |
|
|
.MaxRet(r_MaxRet), .NoBckof(r_NoBckof), .ExDfrEn(r_ExDfrEn),
|
| 352 |
17 |
mohor |
.MaxFL(r_MaxFL), .MTxEn(mtxen_pad_o), .MTxD(mtxd_pad_o),
|
| 353 |
|
|
.MTxErr(mtxerr_pad_o), .TxUsedData(TxUsedDataIn), .TxDone(TxDoneIn),
|
| 354 |
15 |
mohor |
.TxRetry(TxRetry), .TxAbort(TxAbortIn), .WillTransmit(WillTransmit),
|
| 355 |
|
|
.ResetCollision(ResetCollision)
|
| 356 |
|
|
);
|
| 357 |
|
|
|
| 358 |
|
|
|
| 359 |
|
|
|
| 360 |
|
|
|
| 361 |
|
|
wire [15:0] RxByteCnt;
|
| 362 |
|
|
wire RxByteCntEq0;
|
| 363 |
|
|
wire RxByteCntGreat2;
|
| 364 |
|
|
wire RxByteCntMaxFrame;
|
| 365 |
|
|
wire RxCrcError;
|
| 366 |
|
|
wire RxStateIdle;
|
| 367 |
|
|
wire RxStatePreamble;
|
| 368 |
|
|
wire RxStateSFD;
|
| 369 |
|
|
wire [1:0] RxStateData;
|
| 370 |
|
|
|
| 371 |
|
|
|
| 372 |
|
|
|
| 373 |
|
|
|
| 374 |
|
|
// Connecting RxEthMAC
|
| 375 |
|
|
eth_rxethmac rxethmac1
|
| 376 |
|
|
(
|
| 377 |
17 |
mohor |
.MRxClk(mrxclk_pad_i), .MRxDV(MRxDV_Lb), .MRxD(MRxD_Lb),
|
| 378 |
15 |
mohor |
.Transmitting(Transmitting), .HugEn(r_HugEn), .DlyCrcEn(r_DlyCrcEn),
|
| 379 |
|
|
.MaxFL(r_MaxFL), .r_IFG(r_IFG), .Reset(r_Rst),
|
| 380 |
|
|
.RxData(RxData), .RxValid(RxValid), .RxStartFrm(RxStartFrm),
|
| 381 |
|
|
.RxEndFrm(RxEndFrm), .CrcHash(), .CrcHashGood(),
|
| 382 |
|
|
.Broadcast(), .Multicast(), .ByteCnt(RxByteCnt),
|
| 383 |
|
|
.ByteCntEq0(RxByteCntEq0), .ByteCntGreat2(RxByteCntGreat2), .ByteCntMaxFrame(RxByteCntMaxFrame),
|
| 384 |
|
|
.CrcError(RxCrcError), .StateIdle(RxStateIdle), .StatePreamble(RxStatePreamble),
|
| 385 |
|
|
.StateSFD(RxStateSFD), .StateData(RxStateData)
|
| 386 |
|
|
);
|
| 387 |
|
|
|
| 388 |
|
|
|
| 389 |
|
|
// MII Carrier Sense Synchronization
|
| 390 |
17 |
mohor |
always @ (posedge mtxclk_pad_i or posedge r_Rst)
|
| 391 |
15 |
mohor |
begin
|
| 392 |
|
|
if(r_Rst)
|
| 393 |
|
|
begin
|
| 394 |
|
|
CarrierSense_Tx1 <= #Tp 1'b0;
|
| 395 |
|
|
CarrierSense_Tx2 <= #Tp 1'b0;
|
| 396 |
|
|
end
|
| 397 |
|
|
else
|
| 398 |
|
|
begin
|
| 399 |
17 |
mohor |
CarrierSense_Tx1 <= #Tp mcrs_pad_i;
|
| 400 |
15 |
mohor |
CarrierSense_Tx2 <= #Tp CarrierSense_Tx1;
|
| 401 |
|
|
end
|
| 402 |
|
|
end
|
| 403 |
|
|
|
| 404 |
|
|
assign TxCarrierSense = ~r_FullD & CarrierSense_Tx2;
|
| 405 |
|
|
|
| 406 |
|
|
|
| 407 |
|
|
// MII Collision Synchronization
|
| 408 |
17 |
mohor |
always @ (posedge mtxclk_pad_i or posedge r_Rst)
|
| 409 |
15 |
mohor |
begin
|
| 410 |
|
|
if(r_Rst)
|
| 411 |
|
|
begin
|
| 412 |
|
|
Collision_Tx1 <= #Tp 1'b0;
|
| 413 |
|
|
Collision_Tx2 <= #Tp 1'b0;
|
| 414 |
|
|
end
|
| 415 |
|
|
else
|
| 416 |
|
|
begin
|
| 417 |
17 |
mohor |
Collision_Tx1 <= #Tp mcoll_pad_i;
|
| 418 |
15 |
mohor |
if(ResetCollision)
|
| 419 |
|
|
Collision_Tx2 <= #Tp 1'b0;
|
| 420 |
|
|
else
|
| 421 |
|
|
if(Collision_Tx1)
|
| 422 |
|
|
Collision_Tx2 <= #Tp 1'b1;
|
| 423 |
|
|
end
|
| 424 |
|
|
end
|
| 425 |
|
|
|
| 426 |
|
|
|
| 427 |
|
|
// Synchronized Collision
|
| 428 |
|
|
assign Collision = ~r_FullD & Collision_Tx2;
|
| 429 |
|
|
|
| 430 |
|
|
|
| 431 |
|
|
|
| 432 |
|
|
// Carrier sense is synchronized to receive clock.
|
| 433 |
17 |
mohor |
always @ (posedge mrxclk_pad_i or posedge r_Rst)
|
| 434 |
15 |
mohor |
begin
|
| 435 |
|
|
if(r_Rst)
|
| 436 |
|
|
begin
|
| 437 |
|
|
CarrierSense_Rx1 <= #Tp 1'h0;
|
| 438 |
|
|
RxCarrierSense <= #Tp 1'h0;
|
| 439 |
|
|
end
|
| 440 |
|
|
else
|
| 441 |
|
|
begin
|
| 442 |
17 |
mohor |
CarrierSense_Rx1 <= #Tp mcrs_pad_i;
|
| 443 |
15 |
mohor |
RxCarrierSense <= #Tp CarrierSense_Rx1;
|
| 444 |
|
|
end
|
| 445 |
|
|
end
|
| 446 |
|
|
|
| 447 |
|
|
|
| 448 |
|
|
// Delayed WillTransmit
|
| 449 |
17 |
mohor |
always @ (posedge mrxclk_pad_i)
|
| 450 |
15 |
mohor |
begin
|
| 451 |
|
|
WillTransmit_q <= #Tp WillTransmit;
|
| 452 |
|
|
WillTransmit_q2 <= #Tp WillTransmit_q;
|
| 453 |
|
|
end
|
| 454 |
|
|
|
| 455 |
|
|
|
| 456 |
|
|
assign Transmitting = ~r_FullD & WillTransmit_q2;
|
| 457 |
|
|
|
| 458 |
|
|
|
| 459 |
|
|
|
| 460 |
|
|
// Synchronized Receive Enable
|
| 461 |
17 |
mohor |
always @ (posedge mrxclk_pad_i or posedge r_Rst)
|
| 462 |
15 |
mohor |
begin
|
| 463 |
|
|
if(r_Rst)
|
| 464 |
|
|
RxEnSync <= #Tp 1'b0;
|
| 465 |
|
|
else
|
| 466 |
|
|
if(~RxCarrierSense | RxCarrierSense & Transmitting)
|
| 467 |
|
|
RxEnSync <= #Tp r_RxEn;
|
| 468 |
|
|
end
|
| 469 |
|
|
|
| 470 |
|
|
|
| 471 |
|
|
|
| 472 |
|
|
|
| 473 |
|
|
// Connecting WishboneDMA module
|
| 474 |
|
|
eth_wishbonedma wbdma
|
| 475 |
|
|
(
|
| 476 |
17 |
mohor |
.WB_CLK_I(wb_clk_i), .WB_RST_I(wb_rst_i), .WB_DAT_I(wb_dat_i),
|
| 477 |
15 |
mohor |
.WB_DAT_O(DMA_WB_DAT_O),
|
| 478 |
|
|
|
| 479 |
|
|
// WISHBONE slave
|
| 480 |
17 |
mohor |
.WB_ADR_I(wb_adr_i), .WB_SEL_I(wb_sel_i), .WB_WE_I(wb_we_i),
|
| 481 |
15 |
mohor |
.WB_CYC_I(WB_CYC_I_eth), .WB_STB_I(WB_STB_I_eth), .WB_ACK_O(BDAck),
|
| 482 |
17 |
mohor |
.WB_REQ_O(wb_req_o), .WB_ACK_I(wb_ack_i), .WB_ND_O(wb_nd_o),
|
| 483 |
|
|
.WB_RD_O(wb_rd_o),
|
| 484 |
15 |
mohor |
|
| 485 |
|
|
//TX
|
| 486 |
17 |
mohor |
.MTxClk(mtxclk_pad_i), .TxStartFrm(TxStartFrm), .TxEndFrm(TxEndFrm),
|
| 487 |
15 |
mohor |
.TxUsedData(TxUsedData), .TxData(TxData), .StatusIzTxEthMACModula(16'h0),
|
| 488 |
|
|
.TxRetry(TxRetry), .TxAbort(TxAbort), .TxUnderRun(TxUnderRun),
|
| 489 |
|
|
.TxDone(TxDone), .TPauseRq(TPauseRq), .TxPauseTV(TxPauseTV),
|
| 490 |
|
|
.PerPacketCrcEn(PerPacketCrcEn), .PerPacketPad(PerPacketPad), .WillSendControlFrame(WillSendControlFrame),
|
| 491 |
|
|
.TxCtrlEndFrm(TxCtrlEndFrm),
|
| 492 |
|
|
|
| 493 |
|
|
// Register
|
| 494 |
|
|
.r_TxEn(r_TxEn), .r_RxEn(r_RxEn), .r_RxBDAddress(r_RxBDAddress),
|
| 495 |
|
|
.r_DmaEn(r_DmaEn), .RX_BD_ADR_Wr(RX_BD_ADR_Wr),
|
| 496 |
|
|
|
| 497 |
|
|
//RX
|
| 498 |
17 |
mohor |
.MRxClk(mrxclk_pad_i), .RxData(RxData), .RxValid(RxValid),
|
| 499 |
15 |
mohor |
.RxStartFrm(RxStartFrm), .RxEndFrm(RxEndFrm)
|
| 500 |
|
|
);
|
| 501 |
|
|
|
| 502 |
|
|
|
| 503 |
|
|
|
| 504 |
|
|
// Connecting MacStatus module
|
| 505 |
|
|
eth_macstatus macstatus1
|
| 506 |
|
|
(
|
| 507 |
17 |
mohor |
.MRxClk(mrxclk_pad_i), .Reset(r_Rst), .TransmitEnd(),
|
| 508 |
15 |
mohor |
.ReceiveEnd(ReceiveEnd), .ReceivedPacketGood(ReceivedPacketGood), .ReceivedLengthOK(ReceivedLengthOK),
|
| 509 |
|
|
.RxCrcError(RxCrcError), .MRxErr(MRxErr_Lb), .MRxDV(MRxDV_Lb),
|
| 510 |
|
|
.RxStateSFD(RxStateSFD), .RxStateData(RxStateData), .RxStatePreamble(RxStatePreamble),
|
| 511 |
|
|
.RxStateIdle(RxStateIdle), .Transmitting(Transmitting), .RxByteCnt(RxByteCnt),
|
| 512 |
|
|
.RxByteCntEq0(RxByteCntEq0), .RxByteCntGreat2(RxByteCntGreat2), .RxByteCntMaxFrame(RxByteCntMaxFrame),
|
| 513 |
|
|
.ReceivedPauseFrm(ReceivedPauseFrm)
|
| 514 |
|
|
);
|
| 515 |
|
|
|
| 516 |
|
|
|
| 517 |
|
|
endmodule
|