com.newisys.dv
Class DVSimulation

java.lang.Object
  extended by com.newisys.dv.DVSimulation

public final class DVSimulation
extends Object

Provides access to events and structures in the current simulation.

This class is the user code's central access point to the simulation. Methods provide:


Constructor Summary
DVSimulation(com.newisys.verilog.VerilogSimulation verilogSim, SimulationManager simManager, OVAEngine ovaEngine)
          Create a new DVSimulation with the given VerilogSimulation and SimulationManager.
 
Method Summary
 void callVerilogTask(String name, Object... args)
          Execute the given HDL task.
<T> Mailbox<T>
createMailbox()
          Creates a new mailbox.
 Semaphore createSemaphore(int permits)
          Creates a new semaphore with the specified number of permits.
 SimulationThread currentThread()
          Returns the current SimulationThread.
 void delay(long ticks)
          Block the current thread for the specified number of simulation ticks.
 void finish()
          Ends the current simulation.
 SimulationThread[] fork(Runnable... rs)
          Starts a set of new simulation threads with generated names.
 SimulationThread fork(Runnable r)
          Starts a new simulation thread with a generated name.
 SimulationThread fork(String name, Runnable r)
          Starts a new simulation thread with the given name.
 List<String> getArguments()
          Returns the arguments passed to this simulation.
 ClockSignal getClockSignal(String name, int depth)
          Returns a ClockSignal object for the specified signal.
 InOutSignal getConcatInOutSignal(InOutSignal... signals)
          Returns an InOutSignal that is the concatenation of multiple signals.
 InputSignal getConcatInputSignal(InputSignal... signals)
          Returns an InputSignal that is the concatenation of multiple signals.
 OutputSignal getConcatOutputSignal(OutputSignal... signals)
          Returns an OutputSignal that is the concatenation of multiple signals.
 ClockSignal getDefaultClockSignal()
          Returns the default ClockSignal object for the simulation.
 InOutSignal getInOutSignal(String name, ClockSignal clock, com.newisys.verilog.EdgeSet inputEdges, int inputSkew, com.newisys.verilog.EdgeSet outputEdges, int outputSkew, int depth)
          Returns an InOutSignal object for the specified signal.
 InputSignal getInputSignal(String name, ClockSignal clock, com.newisys.verilog.EdgeSet inputEdges, int inputSkew, int depth)
          Returns an InputSignal object for the specified signal.
 com.newisys.verilog.VerilogObject getObjectByName(String name)
          Looks up an HDL object by name.
 OutputSignal getOutputSignal(String name, ClockSignal clock, com.newisys.verilog.EdgeSet outputEdges, int outputSkew)
          Returns an OutputSignal object for the specified signal.
 OVAEngine getOVAEngine()
          Get the OVAEngine for this DVSimulation.
 InOutSignal getPartialInOutSignal(InOutSignal baseSignal, int highBit, int lowBit)
          Returns an InOutSignal based on a bit range of another signal.
 InputSignal getPartialInputSignal(InputSignal baseSignal, int highBit, int lowBit)
          Returns an InputSignal based on a bit range of another signal.
 OutputSignal getPartialOutputSignal(OutputSignal baseSignal, int highBit, int lowBit)
          Returns an OutputSignal based on a bit range of another signal.
 PRNG getRandom()
          Returns the random number generator associated with the current thread.
 PRNGFactory getRandomFactory()
          Returns the random number generator factory associated with the current thread.
 long getSimTime()
          Returns the current simulation time.
 boolean hasOVASupport()
          Returns whether or not OVA is supported in this DVSimulation.
 void join(SimulationThread thread)
          Waits for the specified thread to complete.
 void joinAll(SimulationThread... threads)
          Waits for all specified threads to complete.
 void joinAny(SimulationThread... threads)
          Waits for any of the specified threads to complete.
 void joinChildren()
          Waits for all child threads of this thread to complete.
 void notifyOf(Event e)
          Notify the simulation that the specified event has occured.
 void registerJavaTask(Method method, Object object)
          Registers the given method as callable from the HDL.
 void registerJavaTasks(Class cls)
          Registers all static methods in the given class (and any superclasses) whose names start with "task_" as callable from the HDL.
 void registerJavaTasks(Object object)
          Registers all methods in the class of the given object (and any superclasses) whose names start with "task_" as callable from the HDL.
 void setRandom(PRNG random)
          Sets the random number generator associated with the current thread.
 void setRandomFactory(PRNGFactory randomFactory)
          Sets the random number generator factory associated with the current thread.
 void stop()
          Stops the current simulation.
 void terminate()
          Terminates this thread and all of its child threads.
 void terminateAll()
          Terminates all threads in the current simulation.
 void waitFor(Event e)
          Waits for the specified event to occur.
 void waitForAll(Collection<? extends Event> events)
          Waits for all of the specified events to occur.
 void waitForAll(Event... events)
          Waits for all of the specified events to occur.
 void waitForAny(Collection<? extends Event> events)
          Waits for any of the specified events to occur.
 void waitForAny(Event... events)
          Waits for any of the specified events to occur.
 void waitForSimTime(long simTime)
          Block the current thread until the specified simulation time.
 void yield()
          Yields execution to another thread.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DVSimulation

public DVSimulation(com.newisys.verilog.VerilogSimulation verilogSim,
                    SimulationManager simManager,
                    OVAEngine ovaEngine)
Create a new DVSimulation with the given VerilogSimulation and SimulationManager.

Parameters:
verilogSim - the VerilogSimulation to be used by this DVSimulation
simManager - the SimulationManager to be used by this DVSimulation
ovaEngine - the OVAEngine to be used by this DVSimulation
Method Detail

registerJavaTasks

public void registerJavaTasks(Class cls)
Registers all static methods in the given class (and any superclasses) whose names start with "task_" as callable from the HDL.

Parameters:
cls - the class to register static methods from

registerJavaTasks

public void registerJavaTasks(Object object)
Registers all methods in the class of the given object (and any superclasses) whose names start with "task_" as callable from the HDL.

Parameters:
object - the object to register methods from

registerJavaTask

public void registerJavaTask(Method method,
                             Object object)
Registers the given method as callable from the HDL. If the object argument is not null, the method is called on the given object; otherwise, the method must be static.

Parameters:
method - the method to register
object - the object to invoke the method on

callVerilogTask

public void callVerilogTask(String name,
                            Object... args)
Execute the given HDL task.

Parameters:
name - the name of the HDL task
args - an array of arguments to pass to the verilog task

createMailbox

public <T> Mailbox<T> createMailbox()
Creates a new mailbox.

Type Parameters:
T - the type of objects contained by the mailbox
Returns:
the new Mailbox object

createSemaphore

public Semaphore createSemaphore(int permits)
Creates a new semaphore with the specified number of permits.

Parameters:
permits - the initial number of permits in the semaphore
Returns:
the new Sempahore object

currentThread

public SimulationThread currentThread()
Returns the current SimulationThread.

Returns:
the current SimulationThread

fork

public SimulationThread fork(String name,
                             Runnable r)
Starts a new simulation thread with the given name.

Parameters:
name - the name of this thread, for debugging purposes
r - the code to run for this thread
Returns:
the SimulationThread object associated with the new thread

fork

public SimulationThread fork(Runnable r)
Starts a new simulation thread with a generated name.

Parameters:
r - the code to run for this thread
Returns:
the SimulationThread object associated with the new thread

fork

public SimulationThread[] fork(Runnable... rs)
Starts a set of new simulation threads with generated names.

Parameters:
rs - the code to run for each thread
Returns:
the SimulationThread objects associated with the new threads

join

public void join(SimulationThread thread)
Waits for the specified thread to complete.

Parameters:
thread - the thread to wait for

joinAll

public void joinAll(SimulationThread... threads)
Waits for all specified threads to complete.

Parameters:
threads - an array of SimulationThreads to wait for

joinAny

public void joinAny(SimulationThread... threads)
Waits for any of the specified threads to complete. Once any of the specified threads completes, this method will return.

Parameters:
threads - an array of SimulationThreads to wait for

joinChildren

public void joinChildren()
Waits for all child threads of this thread to complete.


yield

public void yield()
Yields execution to another thread.


terminate

public void terminate()
Terminates this thread and all of its child threads.


terminateAll

public void terminateAll()
Terminates all threads in the current simulation.


stop

public void stop()
Stops the current simulation. This is equivalent to the Verilog $stop task.


finish

public void finish()
Ends the current simulation. This is equivalent to the Verilog $finish task.


notifyOf

public void notifyOf(Event e)
Notify the simulation that the specified event has occured. This may cause other threads to become unblocked.

Parameters:
e - the event that has occurred

waitFor

public void waitFor(Event e)
Waits for the specified event to occur. If the event has already occured, this method will return immediately.

Parameters:
e - the event to wait for

waitForAll

public void waitForAll(Event... events)
Waits for all of the specified events to occur. If all events have already occured, this method will return immediately.

Parameters:
events - an array of events to wait for

waitForAll

public void waitForAll(Collection<? extends Event> events)
Waits for all of the specified events to occur. If all events have already occured, this method will return immediately.

Parameters:
events - a collection of events to wait for

waitForAny

public void waitForAny(Event... events)
Waits for any of the specified events to occur. If any events have already occured, this method will return immediately. Otherwise, this method will return as soon as one of the specified events occurs.

Parameters:
events - an array of events to wait for

waitForAny

public final void waitForAny(Collection<? extends Event> events)
Waits for any of the specified events to occur. If any events have already occured, this method will return immediately. Otherwise, this method will return as soon as one of the specified events occurs.

Parameters:
events - a collection of events to wait for

getRandom

public PRNG getRandom()
Returns the random number generator associated with the current thread.

Returns:
the current thread's random number generator

setRandom

public void setRandom(PRNG random)
Sets the random number generator associated with the current thread.

Parameters:
random - the random number generator to associate with the current thread

getRandomFactory

public PRNGFactory getRandomFactory()
Returns the random number generator factory associated with the current thread.

Returns:
the current thread's random number generator factory

setRandomFactory

public void setRandomFactory(PRNGFactory randomFactory)
Sets the random number generator factory associated with the current thread.

Parameters:
randomFactory - the random number generator factory to associate with the current thread

getArguments

public List<String> getArguments()
Returns the arguments passed to this simulation.

Returns:
a list of arguments passed to this simulation

getSimTime

public long getSimTime()
Returns the current simulation time. TODO: write a note about the timescale of the returned value

Returns:
the current simulation time in ticks

getObjectByName

public com.newisys.verilog.VerilogObject getObjectByName(String name)
Looks up an HDL object by name.

Parameters:
name - the name of the HDL object
Returns:
the HDL object with the specified name

getClockSignal

public ClockSignal getClockSignal(String name,
                                  int depth)
Returns a ClockSignal object for the specified signal.

Parameters:
name - the name of the signal
depth - the desired back-reference depth
Returns:
a ClockSignal object for the specified signal

getDefaultClockSignal

public ClockSignal getDefaultClockSignal()
Returns the default ClockSignal object for the simulation. This is a clock that can be used if no other clocks are available.

Returns:
the default clock signal

getInputSignal

public InputSignal getInputSignal(String name,
                                  ClockSignal clock,
                                  com.newisys.verilog.EdgeSet inputEdges,
                                  int inputSkew,
                                  int depth)
Returns an InputSignal object for the specified signal.

Parameters:
name - the name of the signal
clock - the ClockSignal used to sample this signal
inputEdges - the clock edges to sample this signal on
inputSkew - the input skew in ticks (should be negative)
depth - the desired back-reference depth
Returns:
an InputSignal object for the specified signal

getPartialInputSignal

public InputSignal getPartialInputSignal(InputSignal baseSignal,
                                         int highBit,
                                         int lowBit)
Returns an InputSignal based on a bit range of another signal. The new InputSignal will have a width of highBit - lowBit + 1.

Parameters:
baseSignal - the InputSignal containing the bits from which the new InputSignal will be created
highBit - the bit of baseSignal that will become the MSB of the new InputSignal
lowBit - the bit of baseSignal that will become the LSB of the new InputSignal
Returns:
the partial InputSignal

getConcatInputSignal

public InputSignal getConcatInputSignal(InputSignal... signals)
Returns an InputSignal that is the concatenation of multiple signals. The first signal will be placed in the highest order bits of the new signals, the second index in the next highest order bits, and so on.

Parameters:
signals - an array of InputSignals to concatenate
Returns:
the concatenated InputSignal

getOutputSignal

public OutputSignal getOutputSignal(String name,
                                    ClockSignal clock,
                                    com.newisys.verilog.EdgeSet outputEdges,
                                    int outputSkew)
Returns an OutputSignal object for the specified signal.

Parameters:
name - the name of the signal
clock - the ClockSignal used to drive this signal
outputEdges - the clock edges to drive this signal on
outputSkew - the output skew in ticks (should be positive)
Returns:
an OutputSignal object for the specified signal

getPartialOutputSignal

public OutputSignal getPartialOutputSignal(OutputSignal baseSignal,
                                           int highBit,
                                           int lowBit)
Returns an OutputSignal based on a bit range of another signal. The new OutputSignal will have a width of highBit - lowBit + 1.

Parameters:
baseSignal - the OutputSignal containing the bits from which the new OutputSignal will be created
highBit - the bit of baseSignal that will become the MSB of the new OutputSignal
lowBit - the bit of baseSignal that will become the LSB of the new OutputSignal
Returns:
the partial OutputSignal

getConcatOutputSignal

public OutputSignal getConcatOutputSignal(OutputSignal... signals)
Returns an OutputSignal that is the concatenation of multiple signals. The first signal will be placed in the highest order bits of the new signals, the second index in the next highest order bits, and so on.

Parameters:
signals - an array of OutputSignals to concatenate
Returns:
the concatenated OutputSignal

getInOutSignal

public InOutSignal getInOutSignal(String name,
                                  ClockSignal clock,
                                  com.newisys.verilog.EdgeSet inputEdges,
                                  int inputSkew,
                                  com.newisys.verilog.EdgeSet outputEdges,
                                  int outputSkew,
                                  int depth)
Returns an InOutSignal object for the specified signal.

Parameters:
name - the name of the signal
clock - the ClockSignal used to sample and drive this signal
inputEdges - the clock edges to sample this signal on
inputSkew - the input skew in ticks (should be negative)
outputEdges - the clock edges to drive this signal on
outputSkew - the output skew in ticks (should be positive)
depth - the desired back-reference depth
Returns:
an InOutSignal object for the specified signal

getPartialInOutSignal

public InOutSignal getPartialInOutSignal(InOutSignal baseSignal,
                                         int highBit,
                                         int lowBit)
Returns an InOutSignal based on a bit range of another signal. The new InOutSignal will have a width of highBit - lowBit + 1.

Parameters:
baseSignal - the InOutSignal containing the bits from which the new InOutSignal will be created
highBit - the bit of baseSignal that will become the MSB of the new InOutSignal
lowBit - the bit of baseSignal that will become the LSB of the new InOutSignal
Returns:
the partial InOutSignal

getConcatInOutSignal

public InOutSignal getConcatInOutSignal(InOutSignal... signals)
Returns an InOutSignal that is the concatenation of multiple signals. The first signal will be placed in the highest order bits of the new signals, the second index in the next highest order bits, and so on.

Parameters:
signals - an array of InOutSignals to concatenate
Returns:
the concatenated InOutSignal

waitForSimTime

public void waitForSimTime(long simTime)
Block the current thread until the specified simulation time.

Parameters:
simTime - the simulation time at which to unblock the current thread

delay

public void delay(long ticks)
Block the current thread for the specified number of simulation ticks.

Parameters:
ticks - the number of ticks to wait before unblocking the thread

getOVAEngine

public OVAEngine getOVAEngine()
Get the OVAEngine for this DVSimulation. If OVA is not supported in this DVsimulation, a DVRuntimeException is thrown.

Returns:
The OVAEngine for this DVSimulation.
Throws:
DVRuntimeException - if no OVA support is available.

hasOVASupport

public boolean hasOVASupport()
Returns whether or not OVA is supported in this DVSimulation.

Returns:
true if OVA is supported in this simulation, false otherwise