2015-02-28 03:02:28 -05:00
|
|
|
from misoclib.com.liteeth.common import *
|
2015-04-28 12:51:40 -04:00
|
|
|
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:
|
2015-04-13 03:53:43 -04:00
|
|
|
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:
|
2015-04-13 03:53:43 -04:00
|
|
|
def __init__(self, dw):
|
2015-04-13 04:56:18 -04:00
|
|
|
self.dw = dw
|
2015-04-13 03:53:43 -04:00
|
|
|
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):
|
2015-04-13 03:53:43 -04:00
|
|
|
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):
|
2015-04-13 03:53:43 -04:00
|
|
|
def __init__(self):
|
|
|
|
LiteEthCrossbar.__init__(self, LiteEthUDPMasterPort, "dst_port")
|
2015-02-10 09:22:06 -05:00
|
|
|
|
2015-04-13 03:53:43 -04: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:
|
2015-04-13 07:02:04 -04:00
|
|
|
converter = Converter(eth_udp_user_description(user_port.dw),
|
|
|
|
eth_udp_user_description(8))
|
2015-04-13 03:53:43 -04:00
|
|
|
self.submodules += converter
|
|
|
|
self.comb += [
|
|
|
|
Record.connect(user_port.sink, converter.sink),
|
|
|
|
Record.connect(converter.source, internal_port.sink)
|
|
|
|
]
|
2015-04-13 07:02:04 -04:00
|
|
|
converter = Converter(eth_udp_user_description(8),
|
|
|
|
eth_udp_user_description(user_port.dw))
|
2015-04-13 03:53:43 -04:00
|
|
|
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
|