Class PtidesPreemptiveEDFDirector

    • Field Detail

      • actuators

        public java.util.Map<Actor,​java.lang.Integer> actuators
        Map of Actors to actuator number.
      • sensors

        public java.util.Map<Actor,​java.lang.Integer> sensors
        Map of Sensor to sensor number.
    • 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 class Director
        Returns:
        The generated initialize code.
        Throws:
        IllegalActionException - If the adapter associated with an actor throws it while generating initialize code for the actor.
      • 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 class Director
        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 class Director
        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 class Director
        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.
      • 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 class Director
        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 class NamedProgramCodeGeneratorAdapter
        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 class NamedProgramCodeGeneratorAdapter
        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.