etherbone_tb: add autocheck

This commit is contained in:
Florent Kermarrec 2015-02-12 02:00:26 +01:00
parent d5887416f1
commit 9eb2e313e7
2 changed files with 67 additions and 54 deletions

View File

@ -15,12 +15,12 @@ mac_address = 0x12345678abcd
class TB(Module): class TB(Module):
def __init__(self): def __init__(self):
self.submodules.phy_model = phy.PHY(8, debug=True) self.submodules.phy_model = phy.PHY(8, debug=False)
self.submodules.mac_model = mac.MAC(self.phy_model, debug=True, loopback=False) 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) self.submodules.arp_model = arp.ARP(self.mac_model, mac_address, ip_address, debug=False)
self.submodules.ip_model = ip.IP(self.mac_model, mac_address, ip_address, debug=True, loopback=False) self.submodules.ip_model = ip.IP(self.mac_model, mac_address, ip_address, debug=False, loopback=False)
self.submodules.udp_model = udp.UDP(self.ip_model, ip_address, debug=True, loopback=False) self.submodules.udp_model = udp.UDP(self.ip_model, ip_address, debug=False, loopback=False)
self.submodules.etherbone_model = etherbone.Etherbone(self.udp_model, debug=True) self.submodules.etherbone_model = etherbone.Etherbone(self.udp_model, debug=False)
self.submodules.core = LiteEthUDPIPCore(self.phy_model, mac_address, ip_address, 100000) self.submodules.core = LiteEthUDPIPCore(self.phy_model, mac_address, ip_address, 100000)
self.submodules.etherbone = LiteEthEtherbone(self.core.udp, 20000) self.submodules.etherbone = LiteEthEtherbone(self.core.udp, 20000)
@ -50,7 +50,7 @@ class TB(Module):
for i in range(100): for i in range(100):
yield yield
test_probe = False test_probe = True
test_writes = True test_writes = True
test_reads = True test_reads = True
@ -59,15 +59,16 @@ class TB(Module):
packet = etherbone.EtherbonePacket() packet = etherbone.EtherbonePacket()
packet.pf = 1 packet.pf = 1
self.etherbone_model.send(packet) self.etherbone_model.send(packet)
yield from self.etherbone_model.receive()
print("probe: " + str(bool(self.etherbone_model.rx_packet.pr)))
for i in range(1024): for i in range(8):
yield
# test writes # test writes
if test_writes: if test_writes:
writes = etherbone.EtherboneWrites(base_addr=0x1000) writes = etherbone.EtherboneWrites(base_addr=0x1000)
for i in range(16): writes_data = [j for j in range(16)]
writes.add(etherbone.EtherboneWrite(i)) for write_data in writes_data:
writes.add(etherbone.EtherboneWrite(write_data))
record = etherbone.EtherboneRecord() record = etherbone.EtherboneRecord()
record.writes = writes record.writes = writes
record.reads = None record.reads = None
@ -84,15 +85,15 @@ class TB(Module):
packet = etherbone.EtherbonePacket() packet = etherbone.EtherbonePacket()
packet.records = [record] packet.records = [record]
self.etherbone_model.send(packet) self.etherbone_model.send(packet)
for i in range(256):
for i in range(1024):
yield yield
# test reads # test reads
if test_reads: if test_reads:
reads = etherbone.EtherboneReads(base_ret_addr=0x1000) reads = etherbone.EtherboneReads(base_ret_addr=0x1000)
for i in range(16): reads_address = [j for j in range(16)]
reads.add(etherbone.EtherboneRead(i)) for read_address in reads_address:
reads.add(etherbone.EtherboneRead(read_address))
record = etherbone.EtherboneRecord() record = etherbone.EtherboneRecord()
record.writes = None record.writes = None
record.reads = reads record.reads = reads
@ -109,9 +110,14 @@ class TB(Module):
packet = etherbone.EtherbonePacket() packet = etherbone.EtherbonePacket()
packet.records = [record] packet.records = [record]
self.etherbone_model.send(packet) self.etherbone_model.send(packet)
yield from self.etherbone_model.receive()
loopback_writes_data = []
for write in self.etherbone_model.rx_packet.records.pop().writes.writes:
loopback_writes_data.append(write.data)
for i in range(1024): # check results
yield s, l, e = check(writes_data, loopback_writes_data)
print("shift "+ str(s) + " / length " + str(l) + " / errors " + str(e))
if __name__ == "__main__": if __name__ == "__main__":
run_simulation(TB(), ncycles=4096, vcd_name="my.vcd", keep_files=True) run_simulation(TB(), ncycles=4096, vcd_name="my.vcd", keep_files=True)

View File

@ -281,12 +281,19 @@ class Etherbone(Module):
udp_packet.checksum = 0 udp_packet.checksum = 0
self.udp.send(udp_packet) self.udp.send(udp_packet)
def receive(self):
self.rx_packet = EtherbonePacket()
while not self.rx_packet.done:
yield
def callback(self, packet): def callback(self, packet):
packet = EtherbonePacket(packet) packet = EtherbonePacket(packet)
packet.decode() packet.decode()
if self.debug: if self.debug:
print_etherbone("<<<<<<<<") print_etherbone("<<<<<<<<")
print_etherbone(packet) print_etherbone(packet)
self.rx_packet = packet
self.rx_packet.done = True
self.process(packet) self.process(packet)
def process(self, packet): def process(self, packet):