wishbone: base TargetModel class
This commit is contained in:
parent
ec501e7797
commit
b7a84b3750
|
@ -9,16 +9,13 @@ from migen.bus import wishbone
|
||||||
from migen.sim.generic import Simulator
|
from migen.sim.generic import Simulator
|
||||||
from migen.sim.icarus import Runner
|
from migen.sim.icarus import Runner
|
||||||
|
|
||||||
class MyModel:
|
class MyModel(wishbone.TargetModel):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.prng = Random(763627)
|
self.prng = Random(763627)
|
||||||
|
|
||||||
def read(self, address):
|
def read(self, address):
|
||||||
return address + 4
|
return address + 4
|
||||||
|
|
||||||
def write(self, address, data, sel):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def can_ack(self, bus):
|
def can_ack(self, bus):
|
||||||
return self.prng.randrange(0, 2)
|
return self.prng.randrange(0, 2)
|
||||||
|
|
||||||
|
|
|
@ -33,16 +33,13 @@ def my_generator():
|
||||||
yield None
|
yield None
|
||||||
|
|
||||||
# Our bus slave.
|
# Our bus slave.
|
||||||
class MyModel:
|
class MyModel(wishbone.TargetModel):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.prng = Random(763627)
|
self.prng = Random(763627)
|
||||||
|
|
||||||
def read(self, address):
|
def read(self, address):
|
||||||
return address + 4
|
return address + 4
|
||||||
|
|
||||||
def write(self, address, data, sel):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def can_ack(self, bus):
|
def can_ack(self, bus):
|
||||||
return self.prng.randrange(0, 2)
|
return self.prng.randrange(0, 2)
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,16 @@ class Initiator:
|
||||||
def get_fragment(self):
|
def get_fragment(self):
|
||||||
return Fragment(sim=[self.do_simulation])
|
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:
|
class Target:
|
||||||
def __init__(self, model):
|
def __init__(self, model):
|
||||||
self.bus = Interface()
|
self.bus = Interface()
|
||||||
|
@ -196,11 +206,7 @@ class Target:
|
||||||
def do_simulation(self, s):
|
def do_simulation(self, s):
|
||||||
bus = Proxy(s, self.bus)
|
bus = Proxy(s, self.bus)
|
||||||
if not bus.ack:
|
if not bus.ack:
|
||||||
if hasattr(self.model, "can_ack"):
|
if self.model.can_ack(bus) and bus.cyc and bus.stb:
|
||||||
can_ack = self.model.can_ack(bus)
|
|
||||||
else:
|
|
||||||
can_ack = True
|
|
||||||
if can_ack and bus.cyc and bus.stb:
|
|
||||||
if bus.we:
|
if bus.we:
|
||||||
self.model.write(bus.adr, bus.dat_w, bus.sel)
|
self.model.write(bus.adr, bus.dat_w, bus.sel)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue