Class PtidesPreemptiveEDFDirector
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.cg.kernel.generic.CodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
-
- ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director
-
- ptolemy.cg.adapter.generic.program.procedural.c.adapters.ptolemy.domains.ptides.kernel.PtidesPreemptiveEDFDirector
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
PtidesPreemptiveEDFDirector
,PtidesPreemptiveEDFDirector
,PtidesPreemptiveEDFDirector
public class PtidesPreemptiveEDFDirector extends Director
Code generator adapter associated with the PtidesPreemptiveEDFDirector class. This class is also associated with a code generator. Also unlike the Ptolemy implementation, the execution does not depend on the WCET of actor.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Jia Zou, Isaac Liu, Jeff C. Jensen
- Pt.AcceptedRating:
- red (jiazou)
- Pt.ProposedRating:
- red (jiazou)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
NamedProgramCodeGeneratorAdapter.VariableScope
-
Nested classes/interfaces inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
ProgramCodeGeneratorAdapter.Channel
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description java.util.Map<Actor,java.lang.Integer>
actuators
Map of Actors to actuator number.java.util.Map<Actor,java.lang.Integer>
sensors
Map of Sensor to sensor number.-
Fields inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
_component, _defaultBlocks, _eol, _templateParser
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Constructor Summary
Constructors Constructor Description PtidesPreemptiveEDFDirector(PtidesDirector ptidesPreemptiveEDFDirector)
Construct the code generator adapter associated with the given PtidesBasicDirector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
_generateActorFireCode()
Fire methods for each actor.protected java.lang.String
_generateActorFuncProtoCode()
Generate actor function prototypes.protected java.lang.String
_generateActuatorActuationFuncArrayCode()
Return the code for the actuatorActuations array.protected java.lang.String
_generateActuatorActuationFuncProtoCode()
Return the code for Actuation_*(void) function prototypes.protected java.lang.String
_generateClearEventHeadCode(Actor actor)
This code reset the Event_Head pointer for each channel to null.protected java.lang.String
_generateDirectorHeader()
Generate code for director header.protected java.lang.String
_generatePtrToEventHeadCodeInputs()
Generate a pointer to the event head.protected java.lang.String
_generateTypeConvertStatement(ProgramCodeGeneratorAdapter.Channel source, ProgramCodeGeneratorAdapter.Channel sink, int offset)
Generate the type conversion statement for the particular offset of the two given channels.protected void
_modelStaticAnalysis()
Traverse all the entities in the model and place them in the sensors and actuators variables.java.util.Map<java.lang.String,java.lang.String>
generateAdditionalCodeFiles()
Generate the assembly file associated for this PtidyOS program.java.lang.String
generateInitializeCode()
Generate the initialize code for the associated PtidesBasic director.java.lang.String
generateMainLoop()
Generate a main loop for an execution under the control of this director.java.lang.String
generatePreinitializeCode()
Generate the preinitialize code for this director.void
generateTransferInputsCode(IOPort inputPort, java.lang.StringBuffer code)
Generate code for transferring all input tokens to the inside.void
generateTransferOutputsCode(IOPort outputPort, java.lang.StringBuffer code)
Generate code for transferring all output tokens to the outside.java.lang.String
generateTypeConvertFireCode()
Generate the type conversion fire code.java.lang.String
generateVariableDeclaration()
Generate variable declarations for inputs and outputs and parameters.java.util.Set
getSharedCode()
Generate the shared code.-
Methods inherited from class ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director
_ceilToPowerOfTwo, _generateVariableDeclaration, _generateVariableInitialization, _getParameter, generateCodeForGet, generateCodeForSend, generateConstructorCode, generateFireCode, generateFireFunctionCode, generateModeTransitionCode, generatePostfireCode, generatePreinitializeMethodBodyCode, generateTransferInputsCode, generateTransferOutputsCode, generateVariableDeclaration, generateVariableInitialization, generateVariableInitialization, generateWrapupCode, getComponent, getIncludeDirectories, getLibraries, getLibraryDirectories, getModifiedVariables, getParameter, getReference
-
Methods inherited from class ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
_generateFireCode, analyzeTypeConvert, copyFilesToCodeDirectory, generatePrefireCode, generateSimpleName, generateTypeConvertFireCode, getAddTimeString, getBufferSize, getBufferSize, getDeclareSharedCode, getDefaultBlocks, getFireFunctionParameters, getHeaderFiles, getName, getParameterValue, getReference, getReference, getSinkChannels, getSourceTimeString, getTimeSourcePortName, getTypeConvertChannels, getTypeConvertReference, getTypeConvertSinkChannels, setupAdapter, targetType
-
Methods inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
_generateBlockByName, getAdapter, getCodeGenerator, getTemplateParser, processCode, setCodeGenerator, setTemplateParser, toString
-
Methods inherited from class ptolemy.cg.kernel.generic.CodeGeneratorAdapter
createDecoratorAttributes, generateName
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getContainedObject, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateExistence, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getContainer, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
-
-
-
-
Constructor Detail
-
PtidesPreemptiveEDFDirector
public PtidesPreemptiveEDFDirector(PtidesDirector ptidesPreemptiveEDFDirector)
Construct the code generator adapter associated with the given PtidesBasicDirector.- Parameters:
ptidesPreemptiveEDFDirector
- The associated director ptolemy.domains.ptides.kernel.PtidesBasicDirector
-
-
Method Detail
-
generateAdditionalCodeFiles
public java.util.Map<java.lang.String,java.lang.String> generateAdditionalCodeFiles() throws IllegalActionException
Generate the assembly file associated for this PtidyOS program. Here we return an empty string, but the target specific adapter should overwrite it.- Returns:
- The generated assembly file code.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generateInitializeCode
public java.lang.String generateInitializeCode() throws IllegalActionException
Generate the initialize code for the associated PtidesBasic director.- Overrides:
generateInitializeCode
in classDirector
- Returns:
- The generated initialize code.
- Throws:
IllegalActionException
- If the adapter associated with an actor throws it while generating initialize code for the actor.
-
generateMainLoop
public java.lang.String generateMainLoop() throws IllegalActionException
Generate a main loop for an execution under the control of this director. In this base class, this simply delegates to generateFireCode() and generatePostfireCOde().- Overrides:
generateMainLoop
in classNamedProgramCodeGeneratorAdapter
- Returns:
- Whatever generateFireCode() returns.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generatePreinitializeCode
public java.lang.String generatePreinitializeCode() throws IllegalActionException
Generate the preinitialize code for this director. The preinitialize code for the director is generated by appending the preinitialize code for each actor.- Overrides:
generatePreinitializeCode
in classDirector
- Returns:
- The generated preinitialize code.
- Throws:
IllegalActionException
- If getting the adapter fails, or if generating the preinitialize code for a adapter fails, or if there is a problem getting the buffer size of a port. NOTE: fire code for each function, as well as the scheduler, should all go here Take care of platform independent code.
-
generateTransferInputsCode
public void generateTransferInputsCode(IOPort inputPort, java.lang.StringBuffer code) throws IllegalActionException
Generate code for transferring all input tokens to the inside. In general, this is not allowed, because PtidesBasicDirector resides in an independent platform. Thus, it only connects to the outside through sensors, actuators, and network interfaces, and we use InputDevice and OutputDevice to generate sensor, actuator, and network interface code. The only place where this method is used is when a EmbeddedCodeActor is used inside of a Ptides director. In this case, the director for the EmbeddedCodeActor also has a PtidesBasicDirector, and that PtidesBasicDirector needs to transfer tokens inside of the EmbeddedCodeActor, which is done in this method. Note, since the inside EmbeddedCodeActor could _ONLY_ have a PTIDES director if the outside director is also a PTIDES director, we are sure the outside receiver much also have a PTIDES receiver.- Overrides:
generateTransferInputsCode
in classDirector
- Parameters:
inputPort
- The port to transfer tokens.code
- The string buffer that the generated code is appended to.- Throws:
IllegalActionException
- If thrown while transferring tokens.
-
generateTransferOutputsCode
public void generateTransferOutputsCode(IOPort outputPort, java.lang.StringBuffer code) throws IllegalActionException
Generate code for transferring all output tokens to the outside. In general, this is not allowed, because PtidesBasicDirector resides in an independent platform. Thus, it only connects to the outside through sensors, actuators, and network interfaces, and we use InputDevice and OutputDevice to generate sensor, actuator, and network interface code. The only place where this method is used is when a EmbeddedCodeActor is used inside of a Ptides director. In this case, the director for the EmbeddedCodeActor also has a PtidesBasicDirector, and that PtidesBasicDirector needs to transfer tokens outside of the EmbeddedCodeActor, which is done in this method. However, when an actor is trying to do "$put()$ on an output port that is connected to another output port, then the PtidesBasicReceiver would ensure a new event is created destined to the next actor on the outside, thus this method does not need to generate any code.- Overrides:
generateTransferOutputsCode
in classDirector
- Parameters:
outputPort
- The port to transfer tokens.code
- The string buffer that the generated code is appended to.- Throws:
IllegalActionException
- If thrown while transferring tokens.
-
generateTypeConvertFireCode
public java.lang.String generateTypeConvertFireCode() throws IllegalActionException
Generate the type conversion fire code. Here we don't actually want to generate any type conversion statement, the type conversion is done within the event creation.- Overrides:
generateTypeConvertFireCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- The generated code.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generateVariableDeclaration
public java.lang.String generateVariableDeclaration() throws IllegalActionException
Generate variable declarations for inputs and outputs and parameters. Since we are using Events as holders for data values, we want to overwrite the method in Director to generate nothing. However, in case any of the actors are composite actors, we actually want to generate variable declaration for those actors. This is because the inside composite actors do not know data is stored within Events. Instead, it only has a reference to the input port. Thus, we need to generate a memory address for the input port to allow transfer of data first from the Events to these memory locations, and then from these memory locations to inside of the composite actors.- Overrides:
generateVariableDeclaration
in classDirector
- Returns:
- code The generated code.
- Throws:
IllegalActionException
- If the adapter class for the model director cannot be found.
-
getSharedCode
public java.util.Set getSharedCode() throws IllegalActionException
Generate the shared code. This is the first generate method invoked out of all, so any initialization of variables of this adapter should be done in this method. In this base class, return an empty set. Subclasses may generate code for variable declaration, defining constants, etc.- Overrides:
getSharedCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- An empty set in this base class.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
_generateActuatorActuationFuncArrayCode
protected java.lang.String _generateActuatorActuationFuncArrayCode()
Return the code for the actuatorActuations array.- Returns:
- the code for the actuatorActuations array.
-
_generateActuatorActuationFuncProtoCode
protected java.lang.String _generateActuatorActuationFuncProtoCode()
Return the code for Actuation_*(void) function prototypes.- Returns:
- the code for Actuations_*(void) function prototypes.
-
_generateActorFuncProtoCode
protected java.lang.String _generateActorFuncProtoCode() throws IllegalActionException
Generate actor function prototypes.- Returns:
- actor function prototype methods for each entity.
- Throws:
IllegalActionException
- If thrown while getting the adapter for the actor.
-
_generateDirectorHeader
protected java.lang.String _generateDirectorHeader()
Generate code for director header.- Returns:
- Code that declares the header for director
-
_generateTypeConvertStatement
protected java.lang.String _generateTypeConvertStatement(ProgramCodeGeneratorAdapter.Channel source, ProgramCodeGeneratorAdapter.Channel sink, int offset) throws IllegalActionException
Generate the type conversion statement for the particular offset of the two given channels. This assumes that the offset is the same for both channel. Advancing the offset of one has to advance the offset of the other.- Overrides:
_generateTypeConvertStatement
in classNamedProgramCodeGeneratorAdapter
- Parameters:
source
- The given source channel.sink
- The given sink channel.offset
- The given offset.- Returns:
- The type convert statement for assigning the converted source variable to the sink variable with the given offset.
- Throws:
IllegalActionException
- If there is a problem getting the adapters for the ports or if the conversion cannot be handled.
-
_modelStaticAnalysis
protected void _modelStaticAnalysis() throws IllegalActionException
Traverse all the entities in the model and place them in the sensors and actuators variables.- Throws:
IllegalActionException
- Thrown in derived classes.
-
_generateActorFireCode
public java.lang.String _generateActorFireCode() throws IllegalActionException
Fire methods for each actor.- Returns:
- fire methods for each actor
- Throws:
IllegalActionException
- If thrown when getting the port's adapter.
-
_generateClearEventHeadCode
protected java.lang.String _generateClearEventHeadCode(Actor actor) throws IllegalActionException
This code reset the Event_Head pointer for each channel to null.- Parameters:
actor
- The actor which the input channels reside, whose pointers are pointed to null- Returns:
- The code that clears the event head.
- Throws:
IllegalActionException
- If thrown while getting the width of a port.
-
_generatePtrToEventHeadCodeInputs
protected java.lang.String _generatePtrToEventHeadCodeInputs() throws IllegalActionException
Generate a pointer to the event head.- Returns:
- a pointer to the event head
- Throws:
IllegalActionException
- If thrown while getting the inputs or reading the width of the inputs.
-
-