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-04-12 09:21:58 -04:00
|
|
|
def converter_description(dw):
|
2015-04-13 03:53:43 -04:00
|
|
|
payload_layout = [("data", dw)]
|
|
|
|
return EndpointDescription(payload_layout, packetized=True)
|
2015-04-12 09:21:58 -04:00
|
|
|
|
2015-04-13 04:20:02 -04:00
|
|
|
|
2015-01-28 03:14:01 -05:00
|
|
|
class LiteEthPHYMIITX(Module):
|
2015-04-13 03:53:43 -04:00
|
|
|
def __init__(self, pads, pads_register=True):
|
|
|
|
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)
|
2015-04-13 07:02:04 -04:00
|
|
|
converter = Converter(converter_description(8),
|
|
|
|
converter_description(4))
|
2015-04-13 03:53:43 -04:00
|
|
|
self.submodules += converter
|
|
|
|
self.comb += [
|
|
|
|
converter.sink.stb.eq(sink.stb),
|
|
|
|
converter.sink.data.eq(sink.data),
|
|
|
|
sink.ack.eq(converter.sink.ack),
|
|
|
|
converter.source.ack.eq(1)
|
|
|
|
]
|
|
|
|
pads_eq = [
|
|
|
|
pads.tx_en.eq(converter.source.stb),
|
|
|
|
pads.tx_data.eq(converter.source.data)
|
|
|
|
]
|
|
|
|
if pads_register:
|
|
|
|
self.sync += pads_eq
|
|
|
|
else:
|
|
|
|
self.comb += pads_eq
|
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 LiteEthPHYMIIRX(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
|
|
|
sop = FlipFlop(reset=1)
|
|
|
|
self.submodules += sop
|
2015-01-27 17:59:06 -05:00
|
|
|
|
2015-04-13 07:02:04 -04:00
|
|
|
converter = Converter(converter_description(4),
|
|
|
|
converter_description(8))
|
2015-04-13 03:53:43 -04:00
|
|
|
converter = InsertReset(converter)
|
|
|
|
self.submodules += converter
|
2015-04-12 09:50:20 -04:00
|
|
|
|
2015-04-13 03:53:43 -04:00
|
|
|
self.sync += [
|
|
|
|
converter.reset.eq(~pads.dv),
|
|
|
|
converter.sink.stb.eq(1),
|
|
|
|
converter.sink.data.eq(pads.rx_data)
|
|
|
|
]
|
|
|
|
self.comb += [
|
|
|
|
sop.reset.eq(~pads.dv),
|
|
|
|
sop.ce.eq(pads.dv),
|
|
|
|
converter.sink.sop.eq(sop.q),
|
|
|
|
converter.sink.eop.eq(~pads.dv)
|
|
|
|
]
|
|
|
|
self.comb += Record.connect(converter.source, source)
|
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 LiteEthPHYMIICRG(Module, AutoCSR):
|
2015-04-13 03:53:43 -04:00
|
|
|
def __init__(self, clock_pads, pads, with_hw_init_reset):
|
|
|
|
self._reset = CSRStorage()
|
2015-04-13 05:23:27 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
2015-04-13 03:53:43 -04:00
|
|
|
if hasattr(clock_pads, "phy"):
|
|
|
|
self.sync.base50 += clock_pads.phy.eq(~clock_pads.phy)
|
2015-01-27 17:59:06 -05:00
|
|
|
|
2015-04-13 03:53:43 -04:00
|
|
|
self.clock_domains.cd_eth_rx = ClockDomain()
|
|
|
|
self.clock_domains.cd_eth_tx = ClockDomain()
|
|
|
|
self.comb += self.cd_eth_rx.clk.eq(clock_pads.rx)
|
|
|
|
self.comb += self.cd_eth_tx.clk.eq(clock_pads.tx)
|
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 03:14:01 -05:00
|
|
|
class LiteEthPHYMII(Module, AutoCSR):
|
2015-04-13 03:53:43 -04:00
|
|
|
def __init__(self, clock_pads, pads, with_hw_init_reset=True):
|
|
|
|
self.dw = 8
|
|
|
|
self.submodules.crg = LiteEthPHYMIICRG(clock_pads, pads, with_hw_init_reset)
|
|
|
|
self.submodules.tx = RenameClockDomains(LiteEthPHYMIITX(pads), "eth_tx")
|
|
|
|
self.submodules.rx = RenameClockDomains(LiteEthPHYMIIRX(pads), "eth_rx")
|
|
|
|
self.sink, self.source = self.tx.sink, self.rx.source
|