ptolemy.domains.tdl.kernel
Class TDLModuleDirector

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.actor.Director
              extended by ptolemy.domains.fsm.kernel.FSMDirector
                  extended by ptolemy.domains.fsm.kernel.ModalDirector
                      extended by ptolemy.domains.tdl.kernel.TDLModuleDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Executable, Initializable, QuasiTransparentDirector, ExplicitChangeContext, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class TDLModuleDirector
extends ModalDirector

Director for a TDL (= Timing Definition Language) module. A TDL module consists of modes, modes consist of TDL tasks and TDL tasks are SDF actors. All actions inside a TDL module are executed periodically and the timing information is specified in parameters. This director parses the parameters and builds a schedule for all the TDL actions. The schedule is represented in a graph showing the dependencies between the TDL actions (see TDLActionsGraph).

In the initialization, output ports and actuators are initialized with values specified in the parameters of the ports. The schedule is generated and events are scheduled. Events that are safe to process at current model time are executed, then the fireAt(time) of the enclosing director is called with the time stamp of the next event. Events are processed in the order specified in the graph.

Since:
Ptolemy II 8.0
Version:
$Id: TDLModuleDirector.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Patricia Derler
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  double _currentWCET
          Current worst case execution time, this is set when the execution of a TDL task is started
private  TDLActionsGraph _graph
          Current node in the TDL actions graph.
private  java.util.HashMap<Node,Time> _nextEventsTimeStamps
          Store time stamps from _fireAt() to detect missed executions
private  java.util.HashMap<Node,java.util.List<TDLAction>> _nodesDependentoOnPreviousActions
          Nodes containing actions that depend on previous actions.
private  Time _previousAdditionalScheduleTime
          The minimum time to be added to schedule the next action in the _fireAt() method.
private  java.util.LinkedList _receivers
          All receivers.
 
Fields inherited from class ptolemy.domains.fsm.kernel.ModalDirector
_actorsFired
 
Fields inherited from class ptolemy.domains.fsm.kernel.FSMDirector
_currentLocalReceiverMap, _enabledRefinements, _enabledTransition, _localReceiverMaps, controllerName
 
Fields inherited from class ptolemy.actor.Director
_actorsFinishedExecution, _currentTime, _finishRequested, _initializables, _stopRequested, timeResolution
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
TDLModuleDirector(CompositeEntity container, java.lang.String name)
          Construct a director in the given container with the given name.
 
Method Summary
private  boolean _chooseTransition(Transition transition)
          Check if transition (=mode switch) should be executed.
private  void _fireAt(Node node, Time additionalTime)
          Schedule a refiring of this actor for a TDL action.
private  java.util.Collection _getAllTasks()
          Get all tasks for a module.
private  java.util.List<Node> _getEventsToFire(Time scheduleTime, Time modePeriod)
          Return events that can be fired at current model time.
private  Time _getSmallestTimeStampInEventsToFire()
          Returns the smallest time stamp of the events that will be fired next.
private  boolean _guardIsTrue(NamedObj obj)
          Test a guard expression on an actor.
private  boolean _hasGuard(NamedObj obj)
          Test if an object has a guard expression.
private  void _initializeOutputPorts()
          Initialize output ports by reading initial value and initializing the receivers.
private  void _initializePort(IOPort port)
          Initialize a port with an initial token.
private  void _resetReceivers()
          Reset the TDL Receivers.
private  void _transferTaskInputs(Transition transition)
          After a mode switch, tasks that exist in the source and the target state must have the same port values.
private  void _updateActuator(IOPort port)
          Update actuator by transferring the outputs.
private  void _updateInputPort(IOPort port)
          Update input port, for TDL that means a sensor value is read.
private  void _updateInputs()
          Read input values and update inputMap the updated inputMap is required when guards are evaluated.
private  void _updateOutputPort(IOPort port)
          Update output port, for TDL this means an actuator is updated.
private  void _updateReceivers(java.util.Collection portList)
          Update the TDL receivers.
 void fire()
          Select all actions that can be fired at the current model time.
 CausalityInterface getCausalityInterface()
          Return a causality interface for the composite actor that contains this director.
static int getFrequency(NamedObj obj)
          Get frequency of the task.
 Time getModelTime()
          Return the current model time which is the model time of the excecutive director.
 Time getModePeriod(NamedObj obj)
          Get mode period from state parameter "period".
static java.lang.String getSlots(NamedObj obj)
          Get frequency of the task.
 double getWCET()
          Return the worst case execution time of the actor or 0 if no worst case execution time was specified.
static double getWCETParameter(Actor actor)
          Return the worst case execution time of the actor or 0 if no worst case execution time was specified.
 void initialize()
          Initialize the director, calculate schedule and schedule first firing.
static boolean isFast(NamedObj obj)
          Find out if task (=actor) or actuator (=output port) is fast task.
 Receiver newReceiver()
          Return a new TDLReceiver.
 boolean prefire()
          Check if at the current time there is something to do.
 void scheduleEventsAfterAction(Node node)
          Schedules actions which depend on the action specified in the given node.
 boolean transferInputs(IOPort port)
          Don't read inputs as this is specifically scheduled by a TDLModule.
 boolean transferOutputs(IOPort port)
          Outputs are only transferred when scheduled, therefore do nothing if transfer outputs is called by another actor.
 void wrapup()
          Clear private variables and lists.
 
Methods inherited from class ptolemy.domains.fsm.kernel.ModalDirector
clone, invalidateSchedule, postfire
 
Methods inherited from class ptolemy.domains.fsm.kernel.FSMDirector
_buildLocalReceiverMaps, _checkTransition, _chooseTransition, _currentLocalReceivers, _getLastChosenTransition, _readInputs, _readOutputsFromRefinement, _setCurrentConnectionMap, _setCurrentState, attributeChanged, defaultDependency, fireAt, getContext, getController, getModelNextIterationTime, getModifiedVariables, getParseTreeEvaluator, handleModelError, implementsStrictActorSemantics, isStrict, setContainer, setModelTime
 
Methods inherited from class ptolemy.actor.Director
_description, _fireContainerAt, _isEmbedded, _isTopLevel, _transferInputs, _transferOutputs, addInitializable, createSchedule, finish, fireAt, fireAtCurrentTime, getCurrentTime, getErrorTolerance, getGlobalTime, getModelStartTime, getModelStopTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, initialize, invalidateResolvedTypes, isFireFunctional, isStopRequested, iterate, preinitialize, preinitialize, removeInitializable, requestInitialization, setCurrentTime, stop, stopFire, suggestedModalModelDirectors, supportMultirateFiring, terminate
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 

Field Detail

_currentWCET

private double _currentWCET
Current worst case execution time, this is set when the execution of a TDL task is started


_graph

private TDLActionsGraph _graph
Current node in the TDL actions graph.


_nextEventsTimeStamps

private java.util.HashMap<Node,Time> _nextEventsTimeStamps
Store time stamps from _fireAt() to detect missed executions


_nodesDependentoOnPreviousActions

private java.util.HashMap<Node,java.util.List<TDLAction>> _nodesDependentoOnPreviousActions
Nodes containing actions that depend on previous actions.


_previousAdditionalScheduleTime

private Time _previousAdditionalScheduleTime
The minimum time to be added to schedule the next action in the _fireAt() method.


_receivers

private java.util.LinkedList _receivers
All receivers.

Constructor Detail

TDLModuleDirector

public TDLModuleDirector(CompositeEntity container,
                         java.lang.String name)
                  throws IllegalActionException,
                         NameDuplicationException
Construct a director in the given container with the given name. The container argument must not be null, or a NullPointerException will be thrown. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace.

Parameters:
container - Container of this director.
name - Name of this director.
Throws:
IllegalActionException - If the name has a period in it, or the director is not compatible with the specified container.
NameDuplicationException - If the container not a CompositeActor and the name collides with an entity in the container.
Method Detail

fire

public void fire()
          throws IllegalActionException
Select all actions that can be fired at the current model time. After executing an action, schedule actions that are executed next according to the schedule. If an action with a WCET > 0 was started, schedule a refiring and return.

Specified by:
fire in interface Executable
Overrides:
fire in class ModalDirector
Throws:
IllegalActionException - If there is more than one transition enabled, or there is no controller, or thrown by any choice action.

getModePeriod

public Time getModePeriod(NamedObj obj)
Get mode period from state parameter "period".

Parameters:
obj - The object
Returns:
The value of the "period" parameter. If there is no period parameter or it cannot be converted to a double, then return 1.0.

getModelTime

public Time getModelTime()
Return the current model time which is the model time of the excecutive director.

Overrides:
getModelTime in class Director
Returns:
The current time.
See Also:
Director.setModelTime(Time)

getWCETParameter

public static double getWCETParameter(Actor actor)
Return the worst case execution time of the actor or 0 if no worst case execution time was specified.

Parameters:
actor - The actor for which the worst case execution time is requested.
Returns:
The worst case execution time.

getWCET

public double getWCET()
               throws IllegalActionException
Return the worst case execution time of the actor or 0 if no worst case execution time was specified.

Returns:
The worst case execution time.
Throws:
IllegalActionException

initialize

public void initialize()
                throws IllegalActionException
Initialize the director, calculate schedule and schedule first firing.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class ModalDirector
Throws:
IllegalActionException - If the superclass throws it.

isFast

public static boolean isFast(NamedObj obj)
Find out if task (=actor) or actuator (=output port) is fast task.

Parameters:
obj - The object that could be a fast task or actuator.
Returns:
True if it is a fast task.

getCausalityInterface

public CausalityInterface getCausalityInterface()
Return a causality interface for the composite actor that contains this director. This class returns an instance of TDLCausalityInterface.

Overrides:
getCausalityInterface in class Director
Returns:
A representation of the dependencies between input ports and output ports of the container.

getFrequency

public static int getFrequency(NamedObj obj)
Get frequency of the task.

Parameters:
obj - The object that could be a fast task or actuator.
Returns:
True if it is a fast task.

getSlots

public static java.lang.String getSlots(NamedObj obj)
Get frequency of the task.

Parameters:
obj - The object that could be a fast task or actuator.
Returns:
True if it is a fast task.

newReceiver

public Receiver newReceiver()
Return a new TDLReceiver.

Overrides:
newReceiver in class FSMDirector
Returns:
A new TDL receiver.

prefire

public boolean prefire()
                throws IllegalActionException
Check if at the current time there is something to do.

Specified by:
prefire in interface Executable
Overrides:
prefire in class ModalDirector
Returns:
True if there is something to do now.
Throws:
IllegalActionException - Thrown if execution was missed, input ports could not be transferred or by parent class.

scheduleEventsAfterAction

public void scheduleEventsAfterAction(Node node)
                               throws IllegalActionException
Schedules actions which depend on the action specified in the given node.

Parameters:
node - Given node.
Throws:
IllegalActionException - Not thrown here but in the base class.

transferOutputs

public boolean transferOutputs(IOPort port)
Outputs are only transferred when scheduled, therefore do nothing if transfer outputs is called by another actor.

Overrides:
transferOutputs in class Director
Parameters:
port - output port.
Returns:
True.

transferInputs

public boolean transferInputs(IOPort port)
                       throws IllegalActionException
Don't read inputs as this is specifically scheduled by a TDLModule.

Overrides:
transferInputs in class FSMDirector
Parameters:
port - Input port.
Returns:
True if ports transferred inputs.
Throws:
IllegalActionException - Thrown if inputs are about to be transferred for a non opaque input port.

wrapup

public void wrapup()
            throws IllegalActionException
Clear private variables and lists.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class Director
Throws:
IllegalActionException - If the wrapup() method of one of the associated actors throws it.

_chooseTransition

private boolean _chooseTransition(Transition transition)
                           throws IllegalActionException
Check if transition (=mode switch) should be executed.

Parameters:
transition - The mode switch.
Returns:
True if the mode switch should be done.
Throws:
IllegalActionException - If an error occurs during the transition.

_fireAt

private void _fireAt(Node node,
                     Time additionalTime)
              throws IllegalActionException
Schedule a refiring of this actor for a TDL action.

Parameters:
node - Node containing a TDL action that is scheduled to execute at the given time.
additionalTime - Time to be added to the current model time and the schedule time of the TDL action node.
Throws:
IllegalActionException - Thrown if fireAt() returns false.

_getAllTasks

private java.util.Collection _getAllTasks()
Get all tasks for a module.

Returns:
A list of all tasks.

_getEventsToFire

private java.util.List<Node> _getEventsToFire(Time scheduleTime,
                                              Time modePeriod)
Return events that can be fired at current model time.

Parameters:
scheduleTime - Time in the schedule (= between 0 and modePeriod) which is
modePeriod - Period of the current mode.
Returns:
List of events that can be fired at current model time.

_getSmallestTimeStampInEventsToFire

private Time _getSmallestTimeStampInEventsToFire()
Returns the smallest time stamp of the events that will be fired next.

Returns:
The smallest time stamp of the next events.

_guardIsTrue

private boolean _guardIsTrue(NamedObj obj)
                      throws IllegalActionException
Test a guard expression on an actor.

Parameters:
obj - The object containing a guard expression.
Returns:
True if the guard expression evaluates to true.
Throws:
IllegalActionException - Thrown if guard expression could not be read.

_hasGuard

private boolean _hasGuard(NamedObj obj)
Test if an object has a guard expression.

Parameters:
obj - Object that might have a guard expression.
Returns:
True if the object has a guard parameter.

_initializePort

private void _initializePort(IOPort port)
                      throws IllegalActionException
Initialize a port with an initial token.

Parameters:
port - Port to be initialized.
Throws:
IllegalActionException - Thrown if the initial value parameter could not be read.

_initializeOutputPorts

private void _initializeOutputPorts()
                             throws IllegalActionException
Initialize output ports by reading initial value and initializing the receivers.

Throws:
IllegalActionException - Thrown if the ports could not be initialized.

_resetReceivers

private void _resetReceivers()
Reset the TDL Receivers.


_updateActuator

private void _updateActuator(IOPort port)
                      throws IllegalActionException
Update actuator by transferring the outputs.

Parameters:
port - Actuator that should be updated.
Throws:
IllegalActionException - Thrown if outputs could not be transferred.

_updateInputPort

private void _updateInputPort(IOPort port)
Update input port, for TDL that means a sensor value is read.

Parameters:
port - Port to be updated.

_updateInputs

private void _updateInputs()
                    throws IllegalActionException
Read input values and update inputMap the updated inputMap is required when guards are evaluated.

Throws:
IllegalActionException - Thrown if the controller could not be retrieved or inputs could not be read.

_updateOutputPort

private void _updateOutputPort(IOPort port)
                        throws IllegalActionException
Update output port, for TDL this means an actuator is updated.

Parameters:
port - The output port.
Throws:
IllegalActionException - Thrown if output ports from refinement could not be read.

_updateReceivers

private void _updateReceivers(java.util.Collection portList)
                       throws InvalidStateException,
                              IllegalActionException
Update the TDL receivers. An update of a TDL receiver means that a value previously sent to this port will now be accessible too.

Parameters:
portList - Ports containing TDL receivers that should be updated.
Throws:
IllegalActionException
InvalidStateException

_transferTaskInputs

private void _transferTaskInputs(Transition transition)
                          throws IllegalActionException
After a mode switch, tasks that exist in the source and the target state must have the same port values. This method transfers input ports.

Parameters:
transition - Mode switch that has been made.
Throws:
IllegalActionException - If refinement or Controller could not be retrieved.