2015-09-12 07:34:07 -04:00
|
|
|
from migen import *
|
2012-03-06 13:29:39 -05:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2013-07-24 12:47:25 -04:00
|
|
|
class Mem(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self):
|
|
|
|
# Initialize the beginning of the memory with integers
|
|
|
|
# from 0 to 19.
|
|
|
|
self.specials.mem = Memory(16, 2**12, init=list(range(20)))
|
2014-10-17 05:08:37 -04:00
|
|
|
|
2015-09-20 02:52:26 -04:00
|
|
|
|
|
|
|
def memory_test(dut):
|
|
|
|
# write (only first 5 values)
|
|
|
|
for i in range(5):
|
2015-09-20 03:04:15 -04:00
|
|
|
yield dut.mem[i].eq(42 + i)
|
2015-09-20 02:52:26 -04:00
|
|
|
# remember: values are written after the tick, and read before the tick.
|
|
|
|
# wait one tick for the memory to update.
|
|
|
|
yield
|
|
|
|
# read what we have written, plus some initialization data
|
|
|
|
for i in range(10):
|
|
|
|
value = yield dut.mem[i]
|
2015-04-13 14:07:07 -04:00
|
|
|
print(value)
|
2015-09-20 02:52:26 -04:00
|
|
|
|
2012-03-06 13:29:39 -05:00
|
|
|
|
2014-01-26 16:19:43 -05:00
|
|
|
if __name__ == "__main__":
|
2015-09-20 02:52:26 -04:00
|
|
|
dut = Mem()
|
|
|
|
Simulator(dut, memory_test(dut)).run()
|