common: Improve convert_ip to automatically detect passed format.
Simplify use in the code.
This commit is contained in:
parent
e39fec240b
commit
27a0b99e54
|
@ -146,11 +146,14 @@ def _remove_from_layout(layout, *args):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def convert_ip(s):
|
def convert_ip(s):
|
||||||
ip = 0
|
if isinstance(s, str):
|
||||||
for e in s.split("."):
|
ip = 0
|
||||||
ip = ip << 8
|
for e in s.split("."):
|
||||||
ip += int(e)
|
ip = ip << 8
|
||||||
return ip
|
ip += int(e)
|
||||||
|
return ip
|
||||||
|
else:
|
||||||
|
return s
|
||||||
|
|
||||||
# Stream Layouts -----------------------------------------------------------------------------------
|
# Stream Layouts -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,7 @@ from liteeth.core.icmp import LiteEthICMP
|
||||||
|
|
||||||
class LiteEthIPCore(Module, AutoCSR):
|
class LiteEthIPCore(Module, AutoCSR):
|
||||||
def __init__(self, phy, mac_address, ip_address, clk_freq, with_icmp=True, dw=8):
|
def __init__(self, phy, mac_address, ip_address, clk_freq, with_icmp=True, dw=8):
|
||||||
if isinstance(ip_address, str):
|
ip_address = convert_ip(ip_address)
|
||||||
ip_address = convert_ip(ip_address)
|
|
||||||
self.submodules.mac = LiteEthMAC(phy, dw, interface="crossbar", with_preamble_crc=True)
|
self.submodules.mac = LiteEthMAC(phy, dw, interface="crossbar", with_preamble_crc=True)
|
||||||
self.submodules.arp = LiteEthARP(self.mac, mac_address, ip_address, clk_freq, dw=dw)
|
self.submodules.arp = LiteEthARP(self.mac, mac_address, ip_address, clk_freq, dw=dw)
|
||||||
self.submodules.ip = LiteEthIP(self.mac, mac_address, ip_address, self.arp.table, dw=dw)
|
self.submodules.ip = LiteEthIP(self.mac, mac_address, ip_address, self.arp.table, dw=dw)
|
||||||
|
@ -27,8 +26,7 @@ class LiteEthIPCore(Module, AutoCSR):
|
||||||
|
|
||||||
class LiteEthUDPIPCore(LiteEthIPCore):
|
class LiteEthUDPIPCore(LiteEthIPCore):
|
||||||
def __init__(self, phy, mac_address, ip_address, clk_freq, with_icmp=True, dw=8):
|
def __init__(self, phy, mac_address, ip_address, clk_freq, with_icmp=True, dw=8):
|
||||||
if isinstance(ip_address, str):
|
ip_address = convert_ip(ip_address)
|
||||||
ip_address = convert_ip(ip_address)
|
|
||||||
LiteEthIPCore.__init__(self, phy, mac_address, ip_address, clk_freq, dw=dw,
|
LiteEthIPCore.__init__(self, phy, mac_address, ip_address, clk_freq, dw=dw,
|
||||||
with_icmp=with_icmp)
|
with_icmp=with_icmp)
|
||||||
self.submodules.udp = LiteEthUDP(self.ip, ip_address, dw=dw)
|
self.submodules.udp = LiteEthUDP(self.ip, ip_address, dw=dw)
|
||||||
|
|
Loading…
Reference in New Issue