etherbone_tb: add autocheck
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 12 Feb 2015 01:00:26 +0000 (02:00 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 12 Feb 2015 01:00:26 +0000 (02:00 +0100)
liteeth/test/etherbone_tb.py
liteeth/test/model/etherbone.py

index ce2a9f1cbe309b5eb0062c45e4847fa537e856f7..0322acd019888bfd4ab2a2ae3c6cd5dd1c50e23f 100644 (file)
@@ -15,12 +15,12 @@ mac_address = 0x12345678abcd
 
 class TB(Module):
        def __init__(self):
-               self.submodules.phy_model = phy.PHY(8, debug=True)
-               self.submodules.mac_model = mac.MAC(self.phy_model, debug=True, loopback=False)
+               self.submodules.phy_model = phy.PHY(8, debug=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.ip_model = ip.IP(self.mac_model, mac_address, ip_address, debug=True, loopback=False)
-               self.submodules.udp_model = udp.UDP(self.ip_model, ip_address, debug=True, loopback=False)
-               self.submodules.etherbone_model = etherbone.Etherbone(self.udp_model, debug=True)
+               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=False, loopback=False)
+               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.etherbone = LiteEthEtherbone(self.core.udp, 20000)
@@ -50,7 +50,7 @@ class TB(Module):
                for i in range(100):
                        yield
 
-               test_probe = False
+               test_probe = True
                test_writes = True
                test_reads = True
 
@@ -59,59 +59,65 @@ class TB(Module):
                        packet = etherbone.EtherbonePacket()
                        packet.pf = 1
                        self.etherbone_model.send(packet)
-
-                       for i in range(1024):
-                               yield
-
-               # test writes
-               if test_writes:
-                       writes = etherbone.EtherboneWrites(base_addr=0x1000)
-                       for i in range(16):
-                               writes.add(etherbone.EtherboneWrite(i))
-                       record = etherbone.EtherboneRecord()
-                       record.writes = writes
-                       record.reads = None
-                       record.bca = 0
-                       record.rca = 0
-                       record.rff = 0
-                       record.cyc = 0
-                       record.wca = 0
-                       record.wff = 0
-                       record.byte_enable = 0xf
-                       record.wcount = 16
-                       record.rcount = 0
-
-                       packet = etherbone.EtherbonePacket()
-                       packet.records = [record]
-                       self.etherbone_model.send(packet)
-
-                       for i in range(1024):
-                               yield
-
-               # test reads
-               if test_reads:
-                       reads = etherbone.EtherboneReads(base_ret_addr=0x1000)
-                       for i in range(16):
-                               reads.add(etherbone.EtherboneRead(i))
-                       record = etherbone.EtherboneRecord()
-                       record.writes = None
-                       record.reads = reads
-                       record.bca = 0
-                       record.rca = 0
-                       record.rff = 0
-                       record.cyc = 0
-                       record.wca = 0
-                       record.wff = 0
-                       record.byte_enable = 0xf
-                       record.wcount = 0
-                       record.rcount = 16
-
-                       packet = etherbone.EtherbonePacket()
-                       packet.records = [record]
-                       self.etherbone_model.send(packet)
-
-                       for i in range(1024):
-                               yield
+                       yield from self.etherbone_model.receive()
+                       print("probe: " + str(bool(self.etherbone_model.rx_packet.pr)))
+
+               for i in range(8):
+                       # test writes
+                       if test_writes:
+                               writes = etherbone.EtherboneWrites(base_addr=0x1000)
+                               writes_data = [j for j in range(16)]
+                               for write_data in writes_data:
+                                       writes.add(etherbone.EtherboneWrite(write_data))
+                               record = etherbone.EtherboneRecord()
+                               record.writes = writes
+                               record.reads = None
+                               record.bca = 0
+                               record.rca = 0
+                               record.rff = 0
+                               record.cyc = 0
+                               record.wca = 0
+                               record.wff = 0
+                               record.byte_enable = 0xf
+                               record.wcount = 16
+                               record.rcount = 0
+
+                               packet = etherbone.EtherbonePacket()
+                               packet.records = [record]
+                               self.etherbone_model.send(packet)
+                               for i in range(256):
+                                       yield
+
+                       # test reads
+                       if test_reads:
+                               reads = etherbone.EtherboneReads(base_ret_addr=0x1000)
+                               reads_address = [j for j in range(16)]
+                               for read_address in reads_address:
+                                       reads.add(etherbone.EtherboneRead(read_address))
+                               record = etherbone.EtherboneRecord()
+                               record.writes = None
+                               record.reads = reads
+                               record.bca = 0
+                               record.rca = 0
+                               record.rff = 0
+                               record.cyc = 0
+                               record.wca = 0
+                               record.wff = 0
+                               record.byte_enable = 0xf
+                               record.wcount = 0
+                               record.rcount = 16
+
+                               packet = etherbone.EtherbonePacket()
+                               packet.records = [record]
+                               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)
+
+                               # check results
+                               s, l, e = check(writes_data, loopback_writes_data)
+                               print("shift "+ str(s) + " / length " + str(l) + " / errors " + str(e))
 
 if __name__ == "__main__":
        run_simulation(TB(), ncycles=4096, vcd_name="my.vcd", keep_files=True)
\ No newline at end of file
index 5b1c0b8eaeb9d0dc2e09642bd766ed7f6b57368c..366aa5bf8a0710ac5d47dd485fe099c5a0ae1e0e 100644 (file)
@@ -281,12 +281,19 @@ class Etherbone(Module):
                udp_packet.checksum = 0
                self.udp.send(udp_packet)
 
+       def receive(self):
+               self.rx_packet = EtherbonePacket()
+               while not self.rx_packet.done:
+                       yield
+
        def callback(self, packet):
                packet = EtherbonePacket(packet)
                packet.decode()
                if self.debug:
                        print_etherbone("<<<<<<<<")
                        print_etherbone(packet)
+               self.rx_packet = packet
+               self.rx_packet.done = True
                self.process(packet)
 
        def process(self, packet):