litex/misoclib/com/liteeth/core/udp/crossbar.py

52 lines
1.8 KiB
Python
Raw Normal View History

from misoclib.com.liteeth.common import *
from misoclib.com.liteeth.crossbar import LiteEthCrossbar
2015-02-09 05:19:26 -05:00
2015-04-13 04:20:02 -04:00
2015-02-09 05:19:26 -05:00
class LiteEthUDPMasterPort:
def __init__(self, dw):
self.dw = dw
self.source = Source(eth_udp_user_description(dw))
self.sink = Sink(eth_udp_user_description(dw))
2015-02-09 05:19:26 -05:00
2015-04-13 04:20:02 -04:00
2015-02-09 05:19:26 -05:00
class LiteEthUDPSlavePort:
def __init__(self, dw):
2015-04-13 04:56:18 -04:00
self.dw = dw
self.sink = Sink(eth_udp_user_description(dw))
self.source = Source(eth_udp_user_description(dw))
2015-02-09 05:19:26 -05:00
2015-04-13 04:20:02 -04:00
2015-02-09 05:19:26 -05:00
class LiteEthUDPUserPort(LiteEthUDPSlavePort):
def __init__(self, dw):
LiteEthUDPSlavePort.__init__(self, dw)
2015-02-10 09:22:06 -05:00
2015-04-13 04:20:02 -04:00
2015-02-10 09:22:06 -05:00
class LiteEthUDPCrossbar(LiteEthCrossbar):
def __init__(self):
LiteEthCrossbar.__init__(self, LiteEthUDPMasterPort, "dst_port")
2015-02-10 09:22:06 -05:00
def get_port(self, udp_port, dw=8):
if udp_port in self.users.keys():
raise ValueError("Port {0:#x} already assigned".format(udp_port))
user_port = LiteEthUDPUserPort(dw)
internal_port = LiteEthUDPUserPort(8)
if dw != 8:
converter = Converter(eth_udp_user_description(user_port.dw),
eth_udp_user_description(8))
self.submodules += converter
self.comb += [
Record.connect(user_port.sink, converter.sink),
Record.connect(converter.source, internal_port.sink)
]
converter = Converter(eth_udp_user_description(8),
eth_udp_user_description(user_port.dw))
self.submodules += converter
self.comb += [
Record.connect(internal_port.source, converter.sink),
Record.connect(converter.source, user_port.source)
]
self.users[udp_port] = internal_port
else:
self.users[udp_port] = user_port
return user_port