Skip to content

Commit

Permalink
sim: use (mandatory) ncycles when starting a simulation with no activ…
Browse files Browse the repository at this point in the history
…e functions
sbourdeauducq committed Apr 13, 2014
1 parent fef08e8 commit a36a208
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion doc/simulation.rst
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ Running the simulation

Running the simulation is achieved by calling the ``run`` method of the ``Simulator`` object.

It takes an optional parameter that defines the maximum number of clock cycles that this call simulates. The default value of ``None`` sets no cycle limit.
It takes an optional parameter ``ncycles`` that defines the maximum number of clock cycles that this call simulates. The default value of ``None`` sets no cycle limit.

The cycle counter
=================
@@ -111,6 +111,8 @@ Simulation functions and generators can raise the ``StopSimulation`` exception.

Some simulation modules only respond to external stimuli - e.g. the ``bus.wishbone.Tap`` that snoops on bus transactions and prints them on the console - and have simulation functions that never end. To deal with those, the new API introduces "passive" simulation functions that are not taken into account when deciding to continue to run the simulation. A simulation function is declared passive by setting a "passive" attribute on it that evaluates to True. Raising ``StopSimulation`` in such a function still makes the simulator stop running it for the rest of the simulation.

When starting the simulation of a design that contains no simulation functions or only passive simulation functions, the simulation will continue until the specified number of cycles is reached. The ``ncycles`` parameter is mandatory in this case.

.. _simrunner:

The external simulator runner
16 changes: 15 additions & 1 deletion migen/sim/generic.py
Original file line number Diff line number Diff line change
@@ -106,7 +106,21 @@ def __init__(self, fragment, top_level=None, sim_runner=None, sockaddr="simsocke

def run(self, ncycles=None):
counter = 0
while self.active_sim_functions and (ncycles is None or counter < ncycles):

if self.active_sim_functions:
if ncycles is None:
def continue_simulation():
return bool(self.active_sim_functions)
else:
def continue_simulation():
return self.active_sim_functions and counter < ncycles
else:
if ncycles is None:
raise ValueError("No active simulation function present - must specify ncycles to end simulation")
def continue_simulation():
return counter < ncycles

while continue_simulation():
self.cycle_counter += 1
counter += 1
self.ipc.send(MessageGo())

0 comments on commit a36a208

Please sign in to comment.