From 4e8e1dd8b1c321f33ee2a88a0646883709b3d833 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 10 Feb 2015 10:30:39 +0100 Subject: [PATCH] use new Migen feature: payload_layout/param_layout --- liteeth/common.py | 84 ++++++++++++++++++++++---------------- liteeth/core/ip/common.py | 2 + liteeth/core/udp/common.py | 2 + 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/liteeth/common.py b/liteeth/common.py index e3ba7547..ce7e0d63 100644 --- a/liteeth/common.py +++ b/liteeth/common.py @@ -123,27 +123,28 @@ def _layout_from_header(header): return _layout def eth_phy_description(dw): - layout = [ + payload_layout = [ ("data", dw), ("last_be", dw//8), ("error", dw//8) ] - return EndpointDescription(layout, packetized=True) + return EndpointDescription(payload_layout, packetized=True) def eth_mac_description(dw): - layout = _layout_from_header(mac_header) + [ + payload_layout = _layout_from_header(mac_header) + [ ("data", dw), ("last_be", dw//8), ("error", dw//8) ] - return EndpointDescription(layout, packetized=True) + return EndpointDescription(payload_layout, packetized=True) def eth_arp_description(dw): - layout = _layout_from_header(arp_header) + [ + payload_layout = [ ("data", dw), ("error", dw//8) ] - return EndpointDescription(layout, packetized=True) + param_layout = _layout_from_header(arp_header) + return EndpointDescription(payload_layout, param_layout, packetized=True) arp_table_request_layout = [ ("ip_address", 32) @@ -155,21 +156,24 @@ arp_table_response_layout = [ ] def eth_ipv4_description(dw): - layout = _layout_from_header(ipv4_header) + [ + payload_layout = [ ("data", dw), ("error", dw//8) ] - return EndpointDescription(layout, packetized=True) + param_layout = _layout_from_header(ipv4_header) + return EndpointDescription(payload_layout, param_layout, packetized=True) def eth_ipv4_user_description(dw): - layout = [ - ("length", 16), - ("protocol", 8), - ("ip_address", 32), + payload_layout = [ ("data", dw), ("error", dw//8) ] - return EndpointDescription(layout, packetized=True) + param_layout = [ + ("length", 16), + ("protocol", 8), + ("ip_address", 32) + ] + return EndpointDescription(payload_layout, param_layout, packetized=True) def convert_ip(s): ip = 0 @@ -179,63 +183,73 @@ def convert_ip(s): return ip def eth_icmp_description(dw): - layout = _layout_from_header(icmp_header) + [ + payload_layout = [ ("data", dw), ("error", dw//8) ] - return EndpointDescription(layout, packetized=True) + param_layout = _layout_from_header(icmp_header) + return EndpointDescription(payload_layout, param_layout, packetized=True) def eth_icmp_user_description(dw): - layout = _layout_from_header(icmp_header) + [ - ("ip_address", 32), - ("length", 16), + payload_layout = [ ("data", dw), ("error", dw//8) ] - return EndpointDescription(layout, packetized=True) + param_layout = _layout_from_header(icmp_header) + [ + ("ip_address", 32), + ("length", 16) + ] + return EndpointDescription(payload_layout, param_layout, packetized=True) def eth_udp_description(dw): - layout = _layout_from_header(udp_header) + [ + payload_layout = [ ("data", dw), ("error", dw//8) ] - return EndpointDescription(layout, packetized=True) + param_layout = _layout_from_header(udp_header) + return EndpointDescription(payload_layout, param_layout, packetized=True) def eth_udp_user_description(dw): - layout = [ + payload_layout = [ + ("data", dw), + ("error", dw//8) + ] + param_layout = [ ("src_port", 16), ("dst_port", 16), ("ip_address", 32), - ("length", 16), - ("data", dw), - ("error", dw//8) + ("length", 16) ] - return EndpointDescription(layout, packetized=True) + return EndpointDescription(payload_layout, param_layout, packetized=True) def eth_etherbone_description(dw): - layout = _layout_from_header(etherbone_header) + [ + payload_layout = [ ("data", dw), ("error", dw//8) ] - return EndpointDescription(layout, packetized=True) + param_layout = _layout_from_header(etherbone_header) + return EndpointDescription(payload_layout, param_layout, packetized=True) def eth_etherbone_description(dw): - layout = _layout_from_header(etherbone_header) + [ + payload_layout = [ ("data", dw), ("error", dw//8) ] - return EndpointDescription(layout, packetized=True) + param_layout = _layout_from_header(etherbone_header) + return EndpointDescription(payload_layout, param_layout, packetized=True) def eth_etherbone_user_description(dw): - layout = [ + payload_layout = [ + ("data", dw), + ("error", dw//8) + ] + param_layout = [ ("length", 16), ("ip_address", 32), ("wcount", 8), - ("rcount", 8), - ("data", dw), - ("error", dw//8) + ("rcount", 8) ] - return EndpointDescription(layout, packetized=True) + return EndpointDescription(payload_layout, param_layout, packetized=True) # Generic modules diff --git a/liteeth/core/ip/common.py b/liteeth/core/ip/common.py index fef6d2d4..b61c27c9 100644 --- a/liteeth/core/ip/common.py +++ b/liteeth/core/ip/common.py @@ -2,6 +2,7 @@ from liteeth.common import * class LiteEthIPV4MasterPort: def __init__(self, dw): + self.dw = dw self.source = Source(eth_ipv4_user_description(dw)) self.sink = Sink(eth_ipv4_user_description(dw)) @@ -13,6 +14,7 @@ class LiteEthIPV4MasterPort: class LiteEthIPV4SlavePort: def __init__(self, dw): + self.dw = dw self.sink = Sink(eth_ipv4_user_description(dw)) self.source = Source(eth_ipv4_user_description(dw)) diff --git a/liteeth/core/udp/common.py b/liteeth/core/udp/common.py index feb55bf8..eed6f1d2 100644 --- a/liteeth/core/udp/common.py +++ b/liteeth/core/udp/common.py @@ -2,6 +2,7 @@ from liteeth.common import * 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)) @@ -13,6 +14,7 @@ class LiteEthUDPMasterPort: class LiteEthUDPSlavePort: def __init__(self, dw): + self.dw =dw self.sink = Sink(eth_udp_user_description(dw)) self.source = Source(eth_udp_user_description(dw)) -- 2.30.2