wishbone: base TargetModel class
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sun, 10 Jun 2012 15:05:10 +0000 (17:05 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sun, 10 Jun 2012 15:05:10 +0000 (17:05 +0200)
examples/dataflow_dma.py
examples/wb_initiator.py
migen/bus/wishbone.py

index a6ccd9a34a765587b63804e21d80b660e340dbf1..9b2491ec29075315fdd550afa81b9ad09d8fe09e 100644 (file)
@@ -9,16 +9,13 @@ from migen.bus import wishbone
 from migen.sim.generic import Simulator
 from migen.sim.icarus import Runner
 
-class MyModel:
+class MyModel(wishbone.TargetModel):
        def __init__(self):
                self.prng = Random(763627)
        
        def read(self, address):
                return address + 4
        
-       def write(self, address, data, sel):
-               pass
-       
        def can_ack(self, bus):
                return self.prng.randrange(0, 2)
 
index 607de6963a10b4ed389fdccccfd9cf3c0ee1daa3..0832d4bb9733d162295a4f9cc1d3c9f7eb0050a3 100644 (file)
@@ -33,16 +33,13 @@ def my_generator():
                        yield None
 
 # Our bus slave.
-class MyModel:
+class MyModel(wishbone.TargetModel):
        def __init__(self):
                self.prng = Random(763627)
        
        def read(self, address):
                return address + 4
        
-       def write(self, address, data, sel):
-               pass
-       
        def can_ack(self, bus):
                return self.prng.randrange(0, 2)
 
index d7a400ae418f922cefccb3254a356c3764f59ff3..ae58127ec27f726cbfc369c0d2bfbd7ecdbb89b9 100644 (file)
@@ -188,6 +188,16 @@ class Initiator:
        def get_fragment(self):
                return Fragment(sim=[self.do_simulation])
 
+class TargetModel:
+       def read(self, address):
+               return 0
+       
+       def write(self, address, data, sel):
+               pass
+       
+       def can_ack(self, bus):
+               return True
+
 class Target:
        def __init__(self, model):
                self.bus = Interface()
@@ -196,11 +206,7 @@ class Target:
        def do_simulation(self, s):
                bus = Proxy(s, self.bus)
                if not bus.ack:
-                       if hasattr(self.model, "can_ack"):
-                               can_ack = self.model.can_ack(bus)
-                       else:
-                               can_ack = True
-                       if can_ack and bus.cyc and bus.stb:
+                       if self.model.can_ack(bus) and bus.cyc and bus.stb:
                                if bus.we:
                                        self.model.write(bus.adr, bus.dat_w, bus.sel)
                                else: