litex/liteeth/test/arp_tb.py

58 lines
1.7 KiB
Python
Raw Normal View History

from migen.fhdl.std import *
from migen.bus import wishbone
from migen.bus.transactions import *
from migen.sim.generic import run_simulation
from liteeth.common import *
from liteeth.mac import LiteEthMAC
2015-02-04 13:57:20 -05:00
from liteeth.core.arp import LiteEthARP
from liteeth.test.common import *
from liteeth.test.model import phy, mac, arp
ip_address = 0x12345678
mac_address = 0x12345678abcd
class TB(Module):
def __init__(self):
2015-02-04 13:57:20 -05:00
self.submodules.phy_model = phy.PHY(8, debug=False)
2015-01-30 13:34:13 -05:00
self.submodules.mac_model = mac.MAC(self.phy_model, debug=False, loopback=False)
self.submodules.arp_model = arp.ARP(self.mac_model, mac_address, ip_address, debug=False)
2015-01-30 10:27:56 -05:00
self.submodules.mac = LiteEthMAC(self.phy_model, dw=8, with_hw_preamble_crc=True)
self.submodules.arp = LiteEthARP(self.mac, mac_address, ip_address, 100000)
# use sys_clk for each clock_domain
self.clock_domains.cd_eth_rx = ClockDomain()
self.clock_domains.cd_eth_tx = ClockDomain()
self.comb += [
self.cd_eth_rx.clk.eq(ClockSignal()),
self.cd_eth_rx.rst.eq(ResetSignal()),
self.cd_eth_tx.clk.eq(ClockSignal()),
self.cd_eth_tx.rst.eq(ResetSignal()),
]
def gen_simulation(self, selfp):
selfp.cd_eth_rx.rst = 1
selfp.cd_eth_tx.rst = 1
yield
selfp.cd_eth_rx.rst = 0
selfp.cd_eth_tx.rst = 0
for i in range(100):
yield
2015-01-30 06:02:01 -05:00
while selfp.arp.table.request.ack != 1:
selfp.arp.table.request.stb = 1
selfp.arp.table.request.ip_address = 0x12345678
yield
selfp.arp.table.request.stb = 0
while selfp.arp.table.response.stb != 1:
selfp.arp.table.response.ack = 1
yield
2015-02-04 10:31:37 -05:00
print("Model's MAC : 0x%12x" %selfp.arp.table.response.mac_address)
2015-01-30 06:02:01 -05:00
if __name__ == "__main__":
2015-01-30 06:02:01 -05:00
run_simulation(TB(), ncycles=2048, vcd_name="my.vcd", keep_files=True)