hades.simulator
Class VhdlSimKernel

java.lang.Object
  extended byhades.simulator.SimKernel
      extended byhades.simulator.VhdlSimKernel
All Implemented Interfaces:
ContextToolTip, java.lang.Runnable, Simulatable
Direct Known Subclasses:
VhdlBatchSimKernel

public class VhdlSimKernel
extends SimKernel
implements java.lang.Runnable

A simulation engine with VHDL-like semantics. VhdlSimKernel implements a discrete-event 2-list delta-delay simulation engine that supports VHDL-like semantics: during simulation, the simulator collects all events scheduled at the same simulation time, then executes all pending signal assignments, before continuing with the next simulation cycle.

Similar to RealTimeSimKernel, the simulation will not run faster than (approximately) real time, to allow for visualization and animation.


Nested Class Summary
(package private)  class VhdlSimKernel.DeleteAllEventsFromSourceCommand
          internal class to actually delete all events from the specified SimObject 'source' in a thread-safe manner (because executed from the simulation Thread itself).
(package private)  class VhdlSimKernel.NOP
          adapter class to provide a "no operation" Simulatable suitable to put as a replacement into our pending event arrays
 
Field Summary
static int COLLECT_CYCLE
           
(package private)  int delta_resync_iterations
           
(package private)  double eventTime
           
static int EXECUTE_CYCLE
           
(package private)  int global_errors
           
static int IDLE_CYCLE
           
(package private)  double lastSyncTime
           
protected  int macroState
           
protected  int microState
           
protected  int n_max_pending
           
(package private)  int n_resync_iterations
           
protected  int PENDING_ARRAY_SIZE
           
protected  int pendingArrayIndex
           
protected  SimEvent[] pendingEventArray
           
protected  Port[] pendingEventTargetArray
           
(package private)  double realTime
           
protected  int RECYCLE_ARRAY_SIZE
           
protected  SimEvent[] recycleEventArray
           
protected  int recycleIndex
           
static int t_sleep
           
(package private)  long t0
           
(package private)  long t1
           
(package private)  java.lang.String versionString
           
 
Fields inherited from class hades.simulator.SimKernel
commandQueue, console, controlPanel, debug, design, ELABORATE, endTime, eventList, n_interactive, n_interactive_transferred, n_iterations, n_processed, n_scheduled, n_simulators, name, painter, PAUSED, RESET, runner, RUNNING, shouldStop, simTime, simulatorID, SINGLESTEP, state, STOPPED
 
Constructor Summary
VhdlSimKernel()
          constructor for an so far idle simulation engine
 
Method Summary
 void addPendingEvent(SimEvent event, Port target)
          add SimEvents for later execution.
 void addRecycleableEvent(SimEvent event)
          add a SimEvent to the collection of recycle-able SimEvents.
(package private)  void checkInteractiveEvents()
           
(package private)  void checkResync()
          check whether we need to re-synchronize simulation time and real time.
(package private)  void collectEvents()
           
 void deleteAllEventsFromSource(SimObject source)
          try to delete all events that originated from SimObject 'source'.
(package private)  void executeAllPendingEvents()
           
(package private)  void executePendingEvent()
          execute one pending event (the last one).
 void initializeSimulator()
          initialize the simulator: stop any running simulation, then create a new eventlist, initialize start and end times, ...
 void printStatus()
          printStatus(): print a short message about current simulation and real times, as well as the number of scheduled and processed events.
(package private)  void reallocatePendingEventArrays()
           
(package private)  void reallocateRecycleEventArrays()
           
(package private)  void recycleEvents()
           
 void resync()
          resync: update our 'realTime' variable from the JVM system clock.
 void run()
          run the simulation until ready or interrupted.
 void runForever()
          set the simulation end time to Double.MAX_VALUE, then start/continue the simulation from the current time.
 void scheduleInteractiveEvent(SimEvent se)
          schedule an interactive (=asynchronous) simulation event
(package private)  void simulation()
          simulation: for each iteration, we first check and handle interactive events.
 void sleep()
          sleep for t_sleep milliseconds.
 java.lang.String toString()
          standard identification method
 
Methods inherited from class hades.simulator.SimKernel
checkClearWaveforms, continueSimulation, dbg, elaborate, elaborateComponents, evaluate, executeSingleStep, getDebug, getEventList, getNumberOfProcessedEvents, getNumberOfScheduledEvents, getSimTime, getState, getSyncPainter, getToolTip, hasEvents, isPaused, isReset, isRunning, isSingleStep, main, message, pauseSimulation_NEW, pauseSimulation, printNextPendingEvent, processPendingRepaints, run_debug, runFor, scheduleEvent, scheduleWakeup, setConsole, setControlPanel, setDebug, setDesign, setName, setSyncPainter, singleStep, stopSimulation_NEW, stopSimulation, usage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

versionString

java.lang.String versionString

IDLE_CYCLE

public static final int IDLE_CYCLE
See Also:
Constant Field Values

COLLECT_CYCLE

public static final int COLLECT_CYCLE
See Also:
Constant Field Values

EXECUTE_CYCLE

public static final int EXECUTE_CYCLE
See Also:
Constant Field Values

macroState

protected int macroState

microState

protected int microState

realTime

double realTime

lastSyncTime

double lastSyncTime

eventTime

double eventTime

t0

long t0

t1

long t1

n_resync_iterations

int n_resync_iterations

delta_resync_iterations

int delta_resync_iterations

global_errors

int global_errors

PENDING_ARRAY_SIZE

protected int PENDING_ARRAY_SIZE

pendingArrayIndex

protected int pendingArrayIndex

n_max_pending

protected int n_max_pending

pendingEventArray

protected SimEvent[] pendingEventArray

pendingEventTargetArray

protected Port[] pendingEventTargetArray

RECYCLE_ARRAY_SIZE

protected int RECYCLE_ARRAY_SIZE

recycleIndex

protected int recycleIndex

recycleEventArray

protected SimEvent[] recycleEventArray

t_sleep

public static int t_sleep
Constructor Detail

VhdlSimKernel

public VhdlSimKernel()
constructor for an so far idle simulation engine

Method Detail

addPendingEvent

public void addPendingEvent(SimEvent event,
                            Port target)
add SimEvents for later execution. We use arrays as datastructures, the first SimEvent/Ports goes into position 0. The index is incremented after adding a SimEvent/Port pair. The arrays are reallocated as necessary.

Overrides:
addPendingEvent in class SimKernel

reallocatePendingEventArrays

void reallocatePendingEventArrays()

executePendingEvent

void executePendingEvent()
execute one pending event (the last one). We decrement the index into the SimEvent/Port arrays, access the data at the resulting index, and process it.


executeAllPendingEvents

void executeAllPendingEvents()

addRecycleableEvent

public void addRecycleableEvent(SimEvent event)
add a SimEvent to the collection of recycle-able SimEvents. We cannot recycle at once, because VHDL semantics forces us to keep events alive until the current delta-cycle is finished. The collection is realized with a simple array, the first SimEvent to recycle goes into position 0, and the recycleIndex is incremented after adding a SimEvents. The array is reallocated when necessary.


reallocateRecycleEventArrays

void reallocateRecycleEventArrays()

recycleEvents

void recycleEvents()

runForever

public void runForever()
set the simulation end time to Double.MAX_VALUE, then start/continue the simulation from the current time.

Overrides:
runForever in class SimKernel

initializeSimulator

public void initializeSimulator()
Description copied from class: SimKernel
initialize the simulator: stop any running simulation, then create a new eventlist, initialize start and end times, ...

Overrides:
initializeSimulator in class SimKernel

run

public void run()
run the simulation until ready or interrupted. This method processes all remaining SimEvents in 'real time' as follows: All Events with scheduled time smaller than the current time are processed as fast as possible. If no such Events remain, the simulator Thread will sleep() itself for 100msec. each, until the user generates new Events or the time is ripe for the Events scheduled for later times.

Variable 't0' holds the JVM clock at start of the simulation, 't1' is used for the curent JVM clock value.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class SimKernel

simulation

void simulation()
simulation: for each iteration, we first check and handle interactive events. Next, we check simulation and real-time and re-synchronize, if necessary.

Finally, we collect and execute the events.


checkInteractiveEvents

void checkInteractiveEvents()

scheduleInteractiveEvent

public void scheduleInteractiveEvent(SimEvent se)
Description copied from class: SimKernel
schedule an interactive (=asynchronous) simulation event

Overrides:
scheduleInteractiveEvent in class SimKernel

deleteAllEventsFromSource

public void deleteAllEventsFromSource(SimObject source)
try to delete all events that originated from SimObject 'source'. This method is called during interactive simulation when the 'source' object is deleted from the current Design. This is obviously most useful for WakeupEvents, in order to avoid that the (deleted) SimObject repeatedly wakes itself up. Unfortunately, due to the broken implementation of SimKernel.scheduleWakeup, this does not work as expected (because the 'source' member of WakeupEvents is 'null').

Note that the VhdlSimkernel needs to delete events from both the eventlist and its pendingEvent data structures. In order to avoid threading issues, this method schedules a special simulator command that executes from the simulator thread.

Overrides:
deleteAllEventsFromSource in class SimKernel

checkResync

void checkResync()
check whether we need to re-synchronize simulation time and real time. Currently, this is done after every n_resync_iterations cycles, or every 0.5 seconds of real time.


collectEvents

void collectEvents()

resync

public void resync()
resync: update our 'realTime' variable from the JVM system clock.


printStatus

public void printStatus()
printStatus(): print a short message about current simulation and real times, as well as the number of scheduled and processed events.

Overrides:
printStatus in class SimKernel

sleep

public void sleep()
sleep for t_sleep milliseconds. Note that this method sets the "shouldStop" flag when it catches an InterruptedException (to avoid dozens of nested "throws InterruptedException" method declarations. This means that the simulation Thread will automatically terminate after an InterruptedException was caught.


toString

public java.lang.String toString()
standard identification method

Overrides:
toString in class SimKernel