tb/asmicon: bankmachine test bench

This commit is contained in:
Sebastien Bourdeauducq 2012-03-31 18:11:29 +02:00
parent b1e5b9ef36
commit 185bd66ee4
3 changed files with 90 additions and 10 deletions

48
tb/asmicon/bankmachine.py Normal file
View file

@ -0,0 +1,48 @@
from migen.fhdl.structure import *
from migen.bus.asmibus import *
from migen.sim.generic import Simulator, TopLevel
from migen.sim.icarus import Runner
from milkymist.asmicon.bankmachine import *
from common import sdram_geom, sdram_timing, CommandLogger
def my_generator():
for x in range(10):
t = TWrite(x)
yield t
for x in range(10):
t = TWrite(x + 2200)
yield t
class Completer:
def __init__(self, hub, cmd):
self.hub = hub
self.cmd = cmd
def get_fragment(self):
sync = [
self.hub.call.eq(self.cmd.stb & self.cmd.ack & (self.cmd.is_read | self.cmd.is_write)),
self.hub.tag_call.eq(self.cmd.tag)
]
return Fragment(sync=sync)
def main():
hub = Hub(12, 128, 2)
initiator = Initiator(hub.get_port(), my_generator())
hub.finalize()
dut = BankMachine(sdram_geom, sdram_timing, 2, 0, hub.get_slots())
logger = CommandLogger(dut.cmd, True)
completer = Completer(hub, dut.cmd)
def end_simulation(s):
s.interrupt = initiator.done
fragment = hub.get_fragment() + initiator.get_fragment() + \
dut.get_fragment() + logger.get_fragment() + completer.get_fragment() + \
Fragment(sim=[end_simulation])
sim = Simulator(fragment, Runner(), TopLevel("my.vcd"))
sim.run()
main()

View file

@ -1,9 +1,44 @@
from fractions import Fraction
from math import ceil
from migen.fhdl.structure import *
from migen.sim.generic import Proxy
from milkymist import asmicon
MHz = 1000000
clk_freq = (83 + Fraction(1, 3))*MHz
clk_period_ns = 1000000000/clk_freq
def ns(t, margin=True):
if margin:
t += clk_period_ns/2
return ceil(t/clk_period_ns)
sdram_geom = asmicon.GeomSettings(
bank_a=2,
row_a=13,
col_a=10
)
sdram_timing = asmicon.TimingSettings(
tRP=ns(15),
tRCD=ns(15),
tWR=ns(15),
tREFI=ns(7800, False),
tRFC=ns(70),
CL=3,
rd_delay=4,
slot_time=16,
read_time=32,
write_time=16
)
class CommandLogger:
def __init__(self, cmd):
def __init__(self, cmd, rw=False):
self.cmd = cmd
self.rw = rw
def do_simulation(self, s):
elts = ["@" + str(s.cycle_counter)]
@ -38,7 +73,11 @@ class CommandLogger:
print("\t".join(elts))
def get_fragment(self):
return Fragment(sim=[self.do_simulation])
if self.rw:
comb = [self.cmd.ack.eq(1)]
else:
comb = []
return Fragment(comb, sim=[self.do_simulation])
class SlotsLogger:
def __init__(self, slicer, slots):

View file

@ -5,16 +5,9 @@ from migen.bus.asmibus import *
from migen.sim.generic import Simulator, TopLevel
from migen.sim.icarus import Runner
from milkymist import asmicon
from milkymist.asmicon.bankmachine import _AddressSlicer, _Selector, _Buffer
from common import SlotsLogger
sdram_geom = asmicon.GeomSettings(
bank_a=2,
row_a=13,
col_a=10
)
from common import SlotsLogger, sdram_geom
def my_generator(dt, offset):
for t in range(dt):