2015-03-16 18:04:37 -04:00
|
|
|
from migen.genlib.io import DDROutput
|
|
|
|
|
2015-09-22 12:35:02 -04:00
|
|
|
from misoc.com.liteethmini.common import *
|
2015-01-27 17:59:06 -05:00
|
|
|
|
2015-04-13 04:20:02 -04:00
|
|
|
|
2015-01-28 03:14:01 -05:00
|
|
|
class LiteEthPHYGMIITX(Module):
|
2015-04-26 08:52:05 -04:00
|
|
|
def __init__(self, pads, pads_register=True):
|
2015-04-13 03:53:43 -04:00
|
|
|
self.sink = sink = Sink(eth_phy_description(8))
|
2015-04-13 05:23:27 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
2015-04-13 03:53:43 -04:00
|
|
|
if hasattr(pads, "tx_er"):
|
|
|
|
self.sync += pads.tx_er.eq(0)
|
|
|
|
pads_eq = [
|
|
|
|
pads.tx_en.eq(sink.stb),
|
|
|
|
pads.tx_data.eq(sink.data)
|
|
|
|
]
|
|
|
|
if pads_register:
|
|
|
|
self.sync += pads_eq
|
|
|
|
else:
|
|
|
|
self.comb += pads_eq
|
|
|
|
self.comb += sink.ack.eq(1)
|
2015-01-27 17:59:06 -05:00
|
|
|
|
2015-04-13 04:20:02 -04:00
|
|
|
|
2015-01-28 03:14:01 -05:00
|
|
|
class LiteEthPHYGMIIRX(Module):
|
2015-04-13 03:53:43 -04:00
|
|
|
def __init__(self, pads):
|
|
|
|
self.source = source = Source(eth_phy_description(8))
|
2015-04-13 05:23:27 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
2015-04-13 03:53:43 -04:00
|
|
|
dv_d = Signal()
|
|
|
|
self.sync += dv_d.eq(pads.dv)
|
2015-01-27 17:59:06 -05:00
|
|
|
|
2015-04-13 03:53:43 -04:00
|
|
|
sop = Signal()
|
|
|
|
eop = Signal()
|
|
|
|
self.comb += [
|
|
|
|
sop.eq(pads.dv & ~dv_d),
|
|
|
|
eop.eq(~pads.dv & dv_d)
|
|
|
|
]
|
|
|
|
self.sync += [
|
|
|
|
source.stb.eq(pads.dv),
|
|
|
|
source.sop.eq(sop),
|
|
|
|
source.data.eq(pads.rx_data)
|
|
|
|
]
|
|
|
|
self.comb += source.eop.eq(eop)
|
2015-01-27 17:59:06 -05:00
|
|
|
|
2015-04-13 04:20:02 -04:00
|
|
|
|
2015-01-28 03:14:01 -05:00
|
|
|
class LiteEthPHYGMIICRG(Module, AutoCSR):
|
2015-04-13 03:53:43 -04:00
|
|
|
def __init__(self, clock_pads, pads, with_hw_init_reset, mii_mode=0):
|
|
|
|
self._reset = CSRStorage()
|
2015-04-13 05:23:27 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
2015-04-13 03:53:43 -04:00
|
|
|
self.clock_domains.cd_eth_rx = ClockDomain()
|
|
|
|
self.clock_domains.cd_eth_tx = ClockDomain()
|
2015-04-12 16:09:46 -04:00
|
|
|
|
|
|
|
# RX : Let the synthesis tool insert the appropriate clock buffer
|
2015-04-13 03:53:43 -04:00
|
|
|
self.comb += self.cd_eth_rx.clk.eq(clock_pads.rx)
|
2015-04-12 16:09:46 -04:00
|
|
|
|
2015-04-13 03:53:43 -04:00
|
|
|
# TX : GMII: Drive clock_pads.gtx, clock_pads.tx unused
|
|
|
|
# MII: Use PHY clock_pads.tx as eth_tx_clk, do not drive clock_pads.gtx
|
|
|
|
self.specials += DDROutput(1, mii_mode, clock_pads.gtx, ClockSignal("eth_tx"))
|
|
|
|
# XXX Xilinx specific, replace BUFGMUX with a generic clock buffer?
|
|
|
|
self.specials += Instance("BUFGMUX",
|
2015-04-13 07:02:04 -04:00
|
|
|
i_I0=self.cd_eth_rx.clk,
|
|
|
|
i_I1=clock_pads.tx,
|
|
|
|
i_S=mii_mode,
|
|
|
|
o_O=self.cd_eth_tx.clk)
|
2015-01-27 17:59:06 -05:00
|
|
|
|
2015-04-13 03:53:43 -04:00
|
|
|
if with_hw_init_reset:
|
|
|
|
reset = Signal()
|
|
|
|
counter_done = Signal()
|
|
|
|
self.submodules.counter = counter = Counter(max=512)
|
|
|
|
self.comb += [
|
|
|
|
counter_done.eq(counter.value == 256),
|
|
|
|
counter.ce.eq(~counter_done),
|
|
|
|
reset.eq(~counter_done | self._reset.storage)
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
reset = self._reset.storage
|
|
|
|
self.comb += pads.rst_n.eq(~reset)
|
|
|
|
self.specials += [
|
|
|
|
AsyncResetSynchronizer(self.cd_eth_tx, reset),
|
|
|
|
AsyncResetSynchronizer(self.cd_eth_rx, reset),
|
|
|
|
]
|
2015-01-27 17:59:06 -05:00
|
|
|
|
2015-04-13 04:20:02 -04:00
|
|
|
|
2015-01-28 05:45:19 -05:00
|
|
|
class LiteEthPHYGMII(Module, AutoCSR):
|
2015-04-13 03:53:43 -04:00
|
|
|
def __init__(self, clock_pads, pads, with_hw_init_reset=True):
|
|
|
|
self.dw = 8
|
2015-04-13 07:02:04 -04:00
|
|
|
self.submodules.crg = LiteEthPHYGMIICRG(clock_pads,
|
|
|
|
pads,
|
|
|
|
with_hw_init_reset)
|
|
|
|
self.submodules.tx = RenameClockDomains(LiteEthPHYGMIITX(pads),
|
|
|
|
"eth_tx")
|
|
|
|
self.submodules.rx = RenameClockDomains(LiteEthPHYGMIIRX(pads),
|
|
|
|
"eth_rx")
|
2015-04-13 03:53:43 -04:00
|
|
|
self.sink, self.source = self.tx.sink, self.rx.source
|