Code Interfaces and Code Interface Specification
Generated application and component code interacts with target environment services through these generated code interfaces:
Entry-point functions that target software, such as a scheduler, can call
Function calls to target software, such as platform service functions
This figure shows an example of interaction between a component and platform services in a target execution environment.
The arrows indicate the direction of function interface calls. The target function
scheduler calls component entry-point functions:
component calls target platform services to read input, write output, transfer data between
callable functions, and get time values.
For the code generator to produce code that can interact with target environment services, you must make the code generator aware of service interface requirements by using a combination of:
Model elements in your top model
A code interface configuration
Code mappings that associate the model elements with interfaces defined in the code interface configuration
The following figure shows the relationship among:
Target environment service interface requirements (input to the deployment process)
Code interface specification (how you use Simulink® and Embedded Coder® tooling to communicate the target environment interface requirements to the code generator)
Target environment code integration and execution (what you do with the code generator output)
You inform the code generator about how to generate C or C++ interface code by mapping model elements that represent interfaces, such as functions and root-level inport and outports, to code interfaces that are defined in a code interface configuration file. For example, in the Simulink Editor, you can model an interface for reading data from a target platform receiver service by using a root-level Inport or In Bus Element block. For application deployment, you might also need to include custom blocks that handle data communication requirements. When designing a top model for component deployment, follow the recommended modeling guidelines in Modeling Guidelines for Generated Code.
The code generator supports two types of code interfaces: data and service. You set up the mappings in the Embedded Coder app by using the Code Mappings editor or by using the code mappings programming interface.
For C code interfaces:
The code mappings reflect code interface choices that are defined in an Embedded Coder Dictionary. For a project or organization, someone defines a code interface configuration that aligns with interface requirements of a target execution environment. Then, for each model that you intend to deploy to that environment, you associate the models with that configuration.
You can create and apply a data or service code interface configuration depending on your deployment objectives for your project models. For both types of code interfaces, you configure each type of callable entry-point interface as a function customization template, which defines how the code generator produces code for functions.
This table compares the two types of C code interfaces that you can define in an Embedded Coder Dictionary.
|Data Interface||Service Interface|
|For application deployment.||For component deployment.|
|You configure each interface as a storage class, which specifies the appearance and placement of data elements in the generated code. Storage classes apply direct-access data communication.||For each interface, you specify function prototype information and data communication method requirements for the generated code. You can configure an interface for direct-access, outside-execution, or during-execution data communication, as required by the target platform.|
|The code generator applies constraints when producing code so that it is easier to integrate the code for use in a specific target environment. For more information about the constraints, see Service Interface Constraints and Limitations.|
If you need to use a data interface to configure a component for deployment, see the Component Deployment Guidelines for Embedded Coder Support Package. If you design and configure a component model according to the guidelines, the code generator produces code that aligns with interface requirements of a specific target platform.
For C++ code generation, you configure a model to use a data code interface. You do not create a code interface configuration. In the Embedded Coder app, you map functions that are represented in a top model to method prototypes. You map data elements that are represented in the top model to data visibility and member access function settings.