2011-12-16 15:30:14 -05:00
|
|
|
from migen.fhdl.structure import *
|
2012-02-15 10:30:16 -05:00
|
|
|
from migen.bus.simple import *
|
2012-07-07 16:36:15 -04:00
|
|
|
from migen.bus.transactions import *
|
|
|
|
from migen.sim.generic import PureSimulable
|
2011-12-04 18:16:44 -05:00
|
|
|
|
2012-02-15 10:30:16 -05:00
|
|
|
_desc = Description(
|
|
|
|
(M_TO_S, "adr", 14),
|
|
|
|
(M_TO_S, "we", 1),
|
|
|
|
(M_TO_S, "dat_w", 8),
|
|
|
|
(S_TO_M, "dat_r", 8)
|
|
|
|
)
|
2011-12-08 12:47:32 -05:00
|
|
|
|
2012-02-15 10:30:16 -05:00
|
|
|
class Interface(SimpleInterface):
|
2012-01-27 16:20:57 -05:00
|
|
|
def __init__(self):
|
2012-06-08 12:06:12 -04:00
|
|
|
super().__init__(_desc)
|
2011-12-04 18:16:44 -05:00
|
|
|
|
2012-02-15 10:30:16 -05:00
|
|
|
class Interconnect(SimpleInterconnect):
|
|
|
|
pass
|
2012-07-07 16:36:15 -04:00
|
|
|
|
|
|
|
class Initiator(PureSimulable):
|
|
|
|
def __init__(self, generator):
|
|
|
|
self.generator = generator
|
|
|
|
self.bus = Interface()
|
|
|
|
self.transaction = None
|
|
|
|
self.done = False
|
|
|
|
|
|
|
|
def do_simulation(self, s):
|
|
|
|
if not self.done:
|
|
|
|
if self.transaction is not None:
|
|
|
|
if isinstance(self.transaction, TRead):
|
|
|
|
self.transaction.data = s.rd(self.bus.dat_r)
|
|
|
|
else:
|
|
|
|
s.wr(self.bus.we, 0)
|
|
|
|
try:
|
|
|
|
self.transaction = next(self.generator)
|
|
|
|
except StopIteration:
|
|
|
|
self.transaction = None
|
|
|
|
self.done = True
|
|
|
|
if self.transaction is not None:
|
|
|
|
s.wr(self.bus.adr, self.transaction.address)
|
|
|
|
if isinstance(self.transaction, TWrite):
|
|
|
|
s.wr(self.bus.we, 1)
|
|
|
|
s.wr(self.bus.dat_w, self.transaction.data)
|