Skip to content

Commit

Permalink
wishbone: base TargetModel class
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Bourdeauducq committed Jun 10, 2012
1 parent ec501e7 commit b7a84b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
5 changes: 1 addition & 4 deletions examples/dataflow_dma.py
Expand Up @@ -9,16 +9,13 @@
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)

Expand Down
5 changes: 1 addition & 4 deletions examples/wb_initiator.py
Expand Up @@ -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)

Expand Down
16 changes: 11 additions & 5 deletions migen/bus/wishbone.py
Expand Up @@ -188,6 +188,16 @@ def do_simulation(self, s):
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()
Expand All @@ -196,11 +206,7 @@ def __init__(self, model):
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:
Expand Down

0 comments on commit b7a84b3

Please sign in to comment.