Main Content

Receive and Send Communication Interfaces

Within a platform environment, a component receives data from and sends data to other components by calling the platform data receive and data send services. To represent calls to the data receive and data send services in a component model and configure the relevant data elements for code generation:

  1. In the component model:

    • Represent a data receive request by using a root-level inport (In Bus Element or Inport block).

    • Represent a data send request by using a root-level outport (Out Bus Element or Outport block).

  2. For function platform deployment, when the root-level inports and outports communicate with platform services that use the during-execution communication method and concurrent data access is possible, create a memory buffer to hold the value that the function receives constant during function execution by using the Safeguard block that is provided in the Component Deployment Guidelines for Embedded Coder Support Package. Insert and connect the safeguard mechanism to:

    • The output port of the component model root-level inport

    • The input port of the component model root-level outport

  3. If you have not already done so, open the Embedded Coder app.

  4. In the Code Mappings editor or by using the code mappings programming interface, configure the code interfaces for the root-level inport and outport. At a minimum, set these properties:

    • Storage Class, which controls the appearance and placement of the data element in the generated code.

    • Identifier, which names the model element in the generated code. The code generator uses the identifier in names constructed for access functions.

    • GetFunction or SetFunction, which specifies the naming rule for the name of the platform data receive or data send service function.

    For root-level inports and outports intended to use during-execution communication, use the DuringExecution storage class that is provided in the Component Deployment Guidelines for Embedded Coder Support Package.

    For a list of storage classes supported by Embedded Coder®, see Choose Storage Class for Controlling Data Representation in Generated Code.

A best practice is to represent communication I/O ports at the root-level of a component model by using In Bus Element and Out Bus Element blocks.

  • As a named signal interface, these blocks reduce wiring in the model and avoid issues with port reordering.

  • As a structured data type, these blocks enable use of arrays of buses.

To represent a bus as a signal interface, use an In Bus Element or Out Bus Element block that has the Bus virtuality attribute set to virtual. Virtual buses provide a way to group signals so that you can access them as a whole or select specific signals. A virtual bus consisting of one signal is equivalent to using an Inport or Outport block.

To enforce the composition of a bus interface, use a bus object. A bus object specifies the architectural properties of a bus, such as element names, hierarchy, order, and data types. A bus object is analogous to a structure definition in C. The object defines members of the bus but does not create the bus.

To reduce the number of function arguments that are passed to a reference model in the generated code, choose one of these options for configuring a In Bus Element:

  • Set the block Bus virtuality attribute to nonvirtual and, in the model code mappings, for the inport, set the storage class.

  • Set the block Bus virtuality attribute to virtual or inherited and, in the model code mappings, for the inport, set the storage class to Default.

If you have a requirement to represent root-level I/O in the generated code as a structured data type, model the inport or outport as a nonvirtual bus. The data type of a nonvirtual bus must be a Simulink.Bus object that is defined in the model base workspace or data dictionary.

See Also

| | | |

Related Topics