tb/asmicon: bankmachine test bench
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 31 Mar 2012 16:11:29 +0000 (18:11 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 31 Mar 2012 16:11:29 +0000 (18:11 +0200)
tb/asmicon/bankmachine.py [new file with mode: 0644]
tb/asmicon/common.py
tb/asmicon/selector.py

diff --git a/tb/asmicon/bankmachine.py b/tb/asmicon/bankmachine.py
new file mode 100644 (file)
index 0000000..37ef311
--- /dev/null
@@ -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()
index 01d761b50e4b43699e98269263235a42be9ff8d9..70e64e34e4b92b6376b985cdf69b804c05e6497f 100644 (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):
index c5f88dd13eb149749fb986e920c2e106f6e5dc38..fbeee455d5e21c2b3f6da2b2f5ff3787e8779358 100644 (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):