test: add PHY model skeleton
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 28 Jan 2015 09:25:33 +0000 (10:25 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 28 Jan 2015 09:25:33 +0000 (10:25 +0100)
liteeth/test/Makefile
liteeth/test/common.py
liteeth/test/model/phy.py [new file with mode: 0644]

index 774146199016c4fff188b07b0d20c81760ed93e2..31b69ebe4e518573e428ba5ea1d1a0913dfc3ba3 100644 (file)
@@ -3,11 +3,8 @@ PYTHON = python3
 
 CMD = PYTHONPATH=$(MSCDIR) $(PYTHON)
 
-mac_crc_tb:
-       $(CMD) mac_crc_tb.py
+mac_core_tb:
+       $(CMD) mac_core_tb.py
 
-mac_preamble_tb:
-       $(CMD) mac_preamble_preamble_tb.py
-
-ethmac_tb:
-       $(CMD) ethmac_tb.py
+mac_wishbone_tb:
+       $(CMD) mac_wishbone_tb.py
index 13123700a1ceb271fcdd506842113012d63b7d6d..32e2aaeaa2660085a77944af696579962e591d0f 100644 (file)
@@ -6,6 +6,13 @@ from migen.genlib.record import *
 
 from misoclib.ethmac.common import *
 
+def print_with_prefix(s, prefix=""):
+       if not isinstance(s, str):
+               s = s.__repr__()
+       s = s.split("\n")
+       for l in s:
+               print(prefix + l)
+
 def seed_to_data(seed, random=True):
        if random:
                return (seed * 0x31415979 + 1) & 0xffffffff
diff --git a/liteeth/test/model/phy.py b/liteeth/test/model/phy.py
new file mode 100644 (file)
index 0000000..2708ed4
--- /dev/null
@@ -0,0 +1,31 @@
+from liteeth.common import *
+from liteeth.mac.common import *
+from liteeth.test.common import *
+
+# PHY model
+class PHYSource(PacketStreamer):
+       def __init__(self, dw):
+               PacketStreamer.__init__(self, eth_phy_description(dw))
+
+class PHYSink(PacketLogger):
+       def __init__(self, dw):
+               PacketLogger.__init__(self, eth_phy_description(dw))
+
+class PHY(Module):
+       def __init__(self, dw, debug):
+               self.dw = dw
+               self.debug = debug
+
+               self.phy_source = PHYSource(dw)
+               self.phy_sink = PHYSink(dw)
+
+               self.source = self.phy_source.source
+               self.sink = self.phy_sink.sink
+
+       def send(self, datas, blocking=True):
+               packet = Packet(datas)
+               yield from self.phy_source.send(packet, blocking)
+
+       def receive(self):
+               yield from self.phy_sink.receive()
+               self.packet = self.phy_sink.packet