hades.models.fsm
Class FsmWrapper

java.lang.Object
  extended byhades.simulator.SimObject
      extended byhades.models.fsm.FsmWrapper
All Implemented Interfaces:
java.lang.Cloneable, ContextToolTip, java.io.Serializable, Simulatable

public class FsmWrapper
extends SimObject
implements java.io.Serializable

FsmWrapper - A simple adapter class that allows to integrate JavaFSM state machines into HADES designs.

For documentation about JavaFSM and the class/source files check the JavaFSM homepage

FsmWrapper provides all functionality required to integrate a JavaFSM state machine into the HADES editor and simulation, namely the SimObject interface, a (dynamically constructed) Symbol, and the mapping from StdLogic1164 logic values to the 01X logic model used in JavaFSM.
On the other hand, all state machine editing functions are provided by JavaFSM. FsmWrapper will start the JavaFSM editor whenever the user selects "edit..." from the HADES popup menu on a FsmWrapper object.

On instantiation of a FsmWrapper, the following steps are taken:

  1. A FSM object is created and initialized from a resource file. The name of the resource file is provided by FsmWrapper. For a newly created FsmWrapper, a default state machine is loaded from "/hades/models/fsm/default.fsm".
  2. FsmWrapper determines the number and names of inputs and outputs of the FSM and constructs the Port objects required to interface the FSM to the HADES simulation.
  3. FsmWrapper constructs the graphical Symbol for the FSM with all input and output, as well as "clock" and "reset" ports and an extra output port "currentState". Also, an "hades.models.fsm.FsmRenderer" is prepared which is later used to display the current FSM state in the Symbol.
  4. During simulation, all events on the input ports (including clock and reset) are converted to the JavaFSM logic model and propagated to the FSM. The corresponding result values are scheduled on the output ports of the FsmWrapper. Also, the new state (active state and transistions) of the FSM is displayed in the FsmWrapper symbol.

Please note the following differences between the standalone JavaFSM application/applet and the JavaFSM state machines in HADES.

  1. The JavaFSM main window (MainFrame) is not used, because HADES already provides the main editor window with the graphical representation, the simulation engine, the input values during simulation, and the waveform display.
  2. The buttons (menu items?!) to create/rename/delete input and output signals are provided by the JavaFSM editor window (instead of MainFrame).
  3. To avoid problems with the HADES editor, inputs and outputs cannot be created or deleted once any HADES signals are connected to the FSM.

See Also:
FSM, Serialized Form

Field Summary
protected  boolean debug
           
(package private)  java.lang.String DEFAULT_FSM_NAME
           
protected  FSM fsm
           
protected  FsmRenderer fsmRenderer
           
protected  java.lang.String fsmResourceName
           
(package private)  int n_inputs
           
(package private)  int n_outputs
           
protected  Port port_CLK
           
protected  Port port_NR
           
protected  Port port_STATE
           
protected  double t_delay
           
protected  StdLogic1164 value_0
           
protected  StdLogic1164 value_1
           
protected  StdLogic1164 value_U
           
protected  StdLogic1164 value_X
           
 
Fields inherited from class hades.simulator.SimObject
classloader, console, editor, name, parent, ports, propertySheet, simulator, symbol, versionId, visible
 
Constructor Summary
FsmWrapper()
          FsmWrapper(): the default constructor as used for all SimObjects in HADES.
 
Method Summary
 void configure()
          configure(): This method constructs the JavaFSM editor for our current FSM.
 void constructDynamicSymbol()
          constructDynamicSymbol(): This method is called by the editor as soon as a Symbol for the FSM is needed.
 SimObject copy()
          copy(): This function is used to create a clone of the current FSM.
 void elaborate(java.lang.Object arg)
          elaborate(): we store a reference to our simulation engine.
 void evaluate(java.lang.Object arg)
          evaluate():
 java.lang.String[] getExternalResources()
          return a String[] array of length 1 with our current FSM design name
 FSM getFSM()
          return a reference to our FSM
 java.lang.String getFsmResourceName()
          return the current (Java 1.1 resource-) name of our FSM data file.
 java.awt.Component getPropertySheet()
          return a reference to the 'property sheet' or configuration window for this SimObject.
 boolean initialize(java.lang.String s)
          initialize a FSM from a String which contains the integer version ID and the (Java 1.1) resource name of the FSM data file, e.g.
 void invalidateFSM()
          mark the outputs of our FSM as invalid, because some inputs are not connected or have unknown ('X', 'U', 'Z') values.
 boolean mayChangeIO()
          check whether it is possible to change the I/O of our FSM.
 boolean needsDynamicSymbol()
          a FsmWrapper needs a dynamical symbol
 boolean needsExternalResources()
          we use one external resource: the FSM file to initialize us.
 void rebuildFSM(FSM fsm)
          rebuildFSM(): to be called by the FSM editor any time the FSM has changed.
 void resetFSM()
          reset our FSM to its initial state and schedule all resulting output values.
 void scheduleStateOutput(double time)
           
 void setFSM(FSM fsm)
          set a new FSM.
 void setFsmResourceName(java.lang.String s)
          set a new (Java 1.1 resource-) name for the FSM data file.
 void setValue(Port port, StdLogic1164 value, double time)
          set a new output "value" for Port "p" at time "time": this method constructs and schedules the corresponding SimEvent.
 void taktFSM()
          we had an rising edge on the CLK input.
 java.lang.String toString()
          toString(): the usual info method.
 void updateMealyFSM()
          calculate the new state of this Mealy machine.
 void updateMooreFSM()
          update the internal state (activated transistions) of this Moore machine.
 void write(java.io.PrintWriter ps)
          write all required state information to stream ps: currently this includes the versionID and the resource name of our FSM data file.
 
Methods inherited from class hades.simulator.SimObject
getBindkey, getClassLoader, getDebug, getEditor, getFullName, getName, getParent, getPort, getPorts, getResourceAsStream, getSimulator, getSymbol, getSymbolResourceName, getToolTip, getVersionId, isVisible, keyPressed, message, mousePressed, setClassLoader, setConsole, setDebug, setEditor, setName, setParent, setPorts, setSimulator, setSymbol, setVersionId, setVisible, tearDown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fsm

protected FSM fsm

fsmResourceName

protected java.lang.String fsmResourceName

n_inputs

int n_inputs

n_outputs

int n_outputs

DEFAULT_FSM_NAME

final java.lang.String DEFAULT_FSM_NAME
See Also:
Constant Field Values

t_delay

protected double t_delay

port_NR

protected Port port_NR

port_CLK

protected Port port_CLK

port_STATE

protected Port port_STATE

value_U

protected StdLogic1164 value_U

value_X

protected StdLogic1164 value_X

value_0

protected StdLogic1164 value_0

value_1

protected StdLogic1164 value_1

fsmRenderer

protected FsmRenderer fsmRenderer

debug

protected boolean debug
Constructor Detail

FsmWrapper

public FsmWrapper()
FsmWrapper(): the default constructor as used for all SimObjects in HADES. We allocate a default FSM which is used until another FSM is loaded by the initialize() method.

Method Detail

needsDynamicSymbol

public boolean needsDynamicSymbol()
a FsmWrapper needs a dynamical symbol

Overrides:
needsDynamicSymbol in class SimObject
See Also:
hades.models.fsm.FsmWrapper.buildSymbol

constructDynamicSymbol

public void constructDynamicSymbol()
constructDynamicSymbol(): This method is called by the editor as soon as a Symbol for the FSM is needed. We create an empty symbol and delegate the details to our private method buildSymbol()

Overrides:
constructDynamicSymbol in class SimObject

needsExternalResources

public boolean needsExternalResources()
we use one external resource: the FSM file to initialize us.

Overrides:
needsExternalResources in class SimObject

getExternalResources

public java.lang.String[] getExternalResources()
return a String[] array of length 1 with our current FSM design name

Overrides:
getExternalResources in class SimObject

initialize

public boolean initialize(java.lang.String s)
initialize a FSM from a String which contains the integer version ID and the (Java 1.1) resource name of the FSM data file, e.g. "1001 /hades/models/fsm/default.fsm".

If the resource file cannot be found, the method tries to load the default state machine.

Overrides:
initialize in class SimObject

write

public void write(java.io.PrintWriter ps)
write all required state information to stream ps: currently this includes the versionID and the resource name of our FSM data file.

Overrides:
write in class SimObject

getFsmResourceName

public java.lang.String getFsmResourceName()
return the current (Java 1.1 resource-) name of our FSM data file.


setFsmResourceName

public void setFsmResourceName(java.lang.String s)
set a new (Java 1.1 resource-) name for the FSM data file.


getFSM

public FSM getFSM()
return a reference to our FSM


setFSM

public void setFSM(FSM fsm)
set a new FSM. This method might be called by the FSM editor. Please note that this method also calls "rebuildFSM()", so that the Symbol and all existing I/O connections are rebuilt.


mayChangeIO

public boolean mayChangeIO()
check whether it is possible to change the I/O of our FSM. A FSM editor should not allow to add, delete, or rename input or output signals, if mayChangeIO() returns "false".

At the moment, changing the I/O works reliably only if no signals are connected to the FSM. Later versions of FsmWrapper should probably be more user-friendly.

See Also:
hades.models.fsm.FsmWrapper.rebuildFSM

rebuildFSM

public void rebuildFSM(FSM fsm)
rebuildFSM(): to be called by the FSM editor any time the FSM has changed. To gain performance, this method first checks whether the I/O of the FSM has changed. If not, we can reuse the old Symbol and just switch the reference to the FSM. Otherwise, we need to reconstruct the Symbol.

See Also:
hades.models.fsm.FsmWrapper.mayChangeIO, hades.models.fsm.FsmWrapper.setFSM

elaborate

public void elaborate(java.lang.Object arg)
elaborate(): we store a reference to our simulation engine. To initialize our FSM, you will have to set its "reset" input to '0'.

Specified by:
elaborate in interface Simulatable
Overrides:
elaborate in class SimObject

evaluate

public void evaluate(java.lang.Object arg)
evaluate():

Specified by:
evaluate in interface Simulatable
Overrides:
evaluate in class SimObject
Parameters:
arg - an arbitrary object argument

resetFSM

public void resetFSM()
reset our FSM to its initial state and schedule all resulting output values.


invalidateFSM

public void invalidateFSM()
mark the outputs of our FSM as invalid, because some inputs are not connected or have unknown ('X', 'U', 'Z') values.


taktFSM

public void taktFSM()
we had an rising edge on the CLK input. Collect all other data inputs and calculate the next state of our FSM. Schedule all resulting output events.


updateMooreFSM

public void updateMooreFSM()
update the internal state (activated transistions) of this Moore machine.


updateMealyFSM

public void updateMealyFSM()
calculate the new state of this Mealy machine. Schedule all output events resulting from input changes.


setValue

public void setValue(Port port,
                     StdLogic1164 value,
                     double time)
set a new output "value" for Port "p" at time "time": this method constructs and schedules the corresponding SimEvent.


scheduleStateOutput

public void scheduleStateOutput(double time)

configure

public void configure()
configure(): This method constructs the JavaFSM editor for our current FSM.

Overrides:
configure in class SimObject

getPropertySheet

public java.awt.Component getPropertySheet()
Description copied from class: SimObject
return a reference to the 'property sheet' or configuration window for this SimObject. We cast the return value to an AWT Component, but typically you can expect either a hades.gui.PropertySheet or an java.awt.Window (Dialog or Frame).

Overrides:
getPropertySheet in class SimObject

copy

public SimObject copy()
copy(): This function is used to create a clone of the current FSM.

Overrides:
copy in class SimObject

toString

public java.lang.String toString()
toString(): the usual info method. We also print the name of the FSM resource file.

Overrides:
toString in class SimObject