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

48 lines
1.5 KiB
Python
Raw Normal View History

2015-02-09 05:19:26 -05:00
from liteeth.common import *
from liteeth.generic import *
2015-02-10 09:22:06 -05:00
2015-02-11 19:30:17 -05:00
from liteeth.generic.crossbar import LiteEthCrossbar
2015-02-09 05:19:26 -05:00
class LiteEthUDPMasterPort:
def __init__(self, dw):
self.dw = dw
2015-02-09 05:19:26 -05:00
self.source = Source(eth_udp_user_description(dw))
self.sink = Sink(eth_udp_user_description(dw))
class LiteEthUDPSlavePort:
def __init__(self, dw):
self.dw =dw
2015-02-09 05:19:26 -05:00
self.sink = Sink(eth_udp_user_description(dw))
self.source = Source(eth_udp_user_description(dw))
class LiteEthUDPUserPort(LiteEthUDPSlavePort):
def __init__(self, dw):
LiteEthUDPSlavePort.__init__(self, dw)
2015-02-10 09:22:06 -05:00
class LiteEthUDPCrossbar(LiteEthCrossbar):
def __init__(self):
LiteEthCrossbar.__init__(self, LiteEthUDPMasterPort, "dst_port")
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