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
|
||||
|
||||
def convert_ip(s):
|
||||
ip = 0
|
||||
for e in s.split("."):
|
||||
ip = ip << 8
|
||||
ip += int(e)
|
||||
return ip
|
||||
if isinstance(s, str):
|
||||
ip = 0
|
||||
for e in s.split("."):
|
||||
ip = ip << 8
|
||||
ip += int(e)
|
||||
return ip
|
||||
else:
|
||||
return s
|
||||
|
||||
# Stream Layouts -----------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@ from liteeth.core.icmp import LiteEthICMP
|
|||
|
||||
class LiteEthIPCore(Module, AutoCSR):
|
||||
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.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)
|
||||
|
@ -27,8 +26,7 @@ class LiteEthIPCore(Module, AutoCSR):
|
|||
|
||||
class LiteEthUDPIPCore(LiteEthIPCore):
|
||||
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,
|
||||
with_icmp=with_icmp)
|
||||
self.submodules.udp = LiteEthUDP(self.ip, ip_address, dw=dw)
|
||||
|
|
Loading…
Reference in New Issue