2016-05-23 07:30:38 -04:00
|
|
|
from litex.gen import *
|
|
|
|
|
2016-06-08 11:33:21 -04:00
|
|
|
|
2016-12-16 10:58:01 -05:00
|
|
|
def toggle_re(reg):
|
|
|
|
resig = reg.re
|
|
|
|
# Check that reset isn't set
|
|
|
|
reval = yield resig
|
|
|
|
assert not reval, reval
|
|
|
|
yield resig.eq(1)
|
|
|
|
yield
|
|
|
|
yield resig.eq(0)
|
|
|
|
|
|
|
|
|
|
|
|
def reset_bist_module(module):
|
|
|
|
# Toggle the reset
|
|
|
|
yield from toggle_re(module.reset)
|
2016-12-17 05:49:22 -05:00
|
|
|
# Takes 8 more clock cycles for the reset to have an effect
|
|
|
|
for i in range(8):
|
|
|
|
yield
|
2016-12-16 10:58:01 -05:00
|
|
|
|
|
|
|
# Check some initial conditions are correct after reset.
|
|
|
|
done = yield module.done.status
|
|
|
|
assert not done, done
|
|
|
|
|
|
|
|
|
2016-06-08 11:33:21 -04:00
|
|
|
def seed_to_data(seed, random=True, nbits=32):
|
|
|
|
if nbits == 32:
|
|
|
|
if random:
|
|
|
|
return (seed * 0x31415979 + 1) & 0xffffffff
|
|
|
|
else:
|
|
|
|
return seed
|
|
|
|
else:
|
|
|
|
assert nbits%32 == 0
|
|
|
|
data = 0
|
|
|
|
for i in range(nbits//32):
|
|
|
|
data = data << 32
|
|
|
|
data |= seed_to_data(seed*nbits//32 + i, random, 32)
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2016-05-23 07:30:38 -04:00
|
|
|
class DRAMMemory:
|
|
|
|
def __init__(self, width, depth, init=[]):
|
|
|
|
self.width = width
|
|
|
|
self.depth = depth
|
|
|
|
self.mem = []
|
|
|
|
for d in init:
|
|
|
|
self.mem.append(d)
|
|
|
|
for _ in range(depth-len(init)):
|
|
|
|
self.mem.append(0)
|
|
|
|
|
|
|
|
@passive
|
|
|
|
def read_generator(self, dram_port):
|
|
|
|
address = 0
|
|
|
|
pending = 0
|
2016-05-24 15:40:46 -04:00
|
|
|
yield dram_port.cmd.ready.eq(0)
|
2016-05-23 07:30:38 -04:00
|
|
|
while True:
|
|
|
|
yield dram_port.rdata.valid.eq(0)
|
|
|
|
if pending:
|
|
|
|
yield dram_port.rdata.valid.eq(1)
|
|
|
|
yield dram_port.rdata.data.eq(self.mem[address%self.depth])
|
|
|
|
yield
|
|
|
|
yield dram_port.rdata.valid.eq(0)
|
|
|
|
yield dram_port.rdata.data.eq(0)
|
|
|
|
pending = 0
|
|
|
|
elif (yield dram_port.cmd.valid):
|
|
|
|
pending = not (yield dram_port.cmd.we)
|
|
|
|
address = (yield dram_port.cmd.adr)
|
2016-05-24 15:40:46 -04:00
|
|
|
if pending:
|
|
|
|
yield dram_port.cmd.ready.eq(1)
|
|
|
|
yield
|
|
|
|
yield dram_port.cmd.ready.eq(0)
|
2016-05-23 07:30:38 -04:00
|
|
|
yield
|
|
|
|
|
|
|
|
@passive
|
|
|
|
def write_generator(self, dram_port):
|
|
|
|
address = 0
|
|
|
|
pending = 0
|
2016-05-24 15:40:46 -04:00
|
|
|
yield dram_port.cmd.ready.eq(0)
|
2016-05-23 07:30:38 -04:00
|
|
|
while True:
|
|
|
|
yield dram_port.wdata.ready.eq(0)
|
|
|
|
if pending:
|
|
|
|
yield dram_port.wdata.ready.eq(1)
|
|
|
|
yield
|
|
|
|
self.mem[address%self.depth] = (yield dram_port.wdata.data) # TODO manage we
|
|
|
|
yield dram_port.wdata.ready.eq(0)
|
|
|
|
yield
|
|
|
|
pending = 0
|
2016-05-24 14:48:26 -04:00
|
|
|
yield
|
2016-05-23 07:30:38 -04:00
|
|
|
elif (yield dram_port.cmd.valid):
|
2016-05-24 14:48:26 -04:00
|
|
|
pending = (yield dram_port.cmd.we)
|
2016-05-23 07:30:38 -04:00
|
|
|
address = (yield dram_port.cmd.adr)
|
2016-05-24 15:40:46 -04:00
|
|
|
if pending:
|
|
|
|
yield dram_port.cmd.ready.eq(1)
|
|
|
|
yield
|
|
|
|
yield dram_port.cmd.ready.eq(0)
|
2016-05-23 07:30:38 -04:00
|
|
|
yield
|