sim: make initialization cycle optional (selectable by function attribute)
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Tue, 6 Mar 2012 18:43:59 +0000 (19:43 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Tue, 6 Mar 2012 18:43:59 +0000 (19:43 +0100)
examples/basic_sim.py
examples/memory_sim.py
migen/fhdl/structure.py

index a4f17c465cd292018bc83c68a33e69190d3ba4cb..035440ca322dcf22ff0c7311d5c0dede2c7e9ebf 100644 (file)
@@ -13,6 +13,7 @@ class Counter:
                else:
                        s.wr(self.ce, 1)
                print("Cycle: " + str(s.cycle_counter) + " Count: " + str(s.rd(self.count)))
+       do_simulation.initialize = True
        
        def get_fragment(self):
                sync = [If(self.ce, self.count.eq(self.count + 1))]
index 7c58b2bbb65180b1bfd095d83e4856225c86b39a..dae3925726c7a0c3872e935d9a9802e9a137c994 100644 (file)
@@ -10,11 +10,10 @@ class Mem:
                self.mem = Memory(16, 2**12, p, init=list(range(20)))
        
        def do_simulation(self, s):
-               if s.cycle_counter >= 0:
-                       value = s.rd(self.mem, s.cycle_counter)
-                       print(value)
-                       if value == 10:
-                               s.interrupt = True
+               value = s.rd(self.mem, s.cycle_counter)
+               print(value)
+               if value == 10:
+                       s.interrupt = True
        
        def get_fragment(self):
                return Fragment(memories=[self.mem], sim=[self.do_simulation])
index e5730ff508349ac02e98a00c7c84141c64fede3f..69f53f65d845b924709b4f6dd0f469a550c7b198 100644 (file)
@@ -278,4 +278,5 @@ class Fragment:
 
        def call_sim(self, simulator):
                for s in self.sim:
-                       s(simulator)
+                       if simulator.cycle_counter >= 0 or (hasattr(s, "initialize") and s.initialize):
+                               s(simulator)