2013-05-22 11:11:09 -04:00
|
|
|
from migen.fhdl.std import *
|
2012-11-23 10:22:50 -05:00
|
|
|
from migen.bus.transactions import *
|
|
|
|
|
|
|
|
def _byte_mask(orig, dat_w, sel):
|
|
|
|
r = 0
|
|
|
|
shift = 0
|
|
|
|
while sel:
|
|
|
|
if sel & 1:
|
|
|
|
r |= (dat_w & 0xff) << shift
|
|
|
|
else:
|
|
|
|
r |= (orig & 0xff) << shift
|
|
|
|
orig >>= 8
|
|
|
|
dat_w >>= 8
|
|
|
|
sel >>= 1
|
|
|
|
shift += 8
|
|
|
|
return r
|
|
|
|
|
2013-03-15 14:41:30 -04:00
|
|
|
class Initiator(Module):
|
2012-11-23 10:22:50 -05:00
|
|
|
def __init__(self, generator, mem):
|
|
|
|
self.generator = generator
|
|
|
|
self.mem = mem
|
|
|
|
|
2014-01-26 16:19:43 -05:00
|
|
|
def do_simulation(self, selfp):
|
|
|
|
try:
|
|
|
|
transaction = next(self.generator)
|
|
|
|
except StopIteration:
|
|
|
|
transaction = None
|
|
|
|
raise StopSimulation
|
|
|
|
if isinstance(transaction, TRead):
|
|
|
|
transaction.data = selfp.mem[transaction.address]
|
|
|
|
elif isinstance(transaction, TWrite):
|
|
|
|
d = selfp.mem[transaction.address]
|
|
|
|
d_mask = _byte_mask(d, transaction.data, transaction.sel)
|
|
|
|
selfp.mem[transaction.address] = d_mask
|