Main Content

Data Interfaces

If you are deploying a top model as an application or generating C++ code, configure the model to use a data code interface. Service code interface configurations are recommended for deploying component C code (see Service Interfaces). If you need to use a data code interface for deployed C component code, see Component Deployment Guidelines for Embedded Coder Support Package.

Model Code Interfaces lists modeling elements that you can use to represent interfaces for interacting with target environment resources. To configure the modeling elements for code generation, in the Code Mappings editor or by using the code mappings programming interface, you map the interface elements represented in the model to data code interfaces. What you map the elements to depends on whether you are generating C or C++ code.

C Data Interfaces

When generating C code from a top model for application deployment, you map model data elements to storage classes. A storage class specifies the appearance and placement of data elements in the generated code. Storage classes apply direct-access data communication. The list of storage classes available for mapping is determined by the Embedded Coder Dictionary that is associated with the model. The dictionary can define default settings, which can simplify the mapping process when the default mappings apply for your model.

To represent data interface elements in a model and configure them for C code generation:

  1. In the model, include data interface elements as recommended in Model Code Interfaces.

  2. Open the Embedded Coder app.

  3. If you are using a shared Embedded Coder Dictionary, link your model to that dictionary. Select Code Interface > Set up shared Embedded Coder Dictionary. In the Set Up Embedded Coder Dictionary dialog box, specify an existing coder dictionary file or create a new one.

  4. If you want to set up default mappings for categories of model elements, select Code Interface > Default Code Mappings. In the Code Mappings editor, on the Data Defaults and Function Defaults tabs, configure default mappings.

  5. Select Code Interface > Individual Element Code Mappings.

  6. In the Code Mappings editor, on each element category tab, inspect the mappings and property settings for individual interface elements. If necessary, adjust the settings.

  7. Save your interface configuration changes by saving the model.

If you prefer, you can map data elements to storage classes by using the code mappings programming interface (see coder.mapping.api.CodeMapping).

For an example, see Configure Model Data Interface for C Code Generation.

For more information, see Code Mappings editor, C Data and Function Interfaces, and Code Interface Definitions.

C++ Data Interfaces

When generating C++ code for deployment, you:

  • Map functions that are represented in a model to method prototypes.

  • Map model data interface elements to data visibility and member access function settings.

Data visibility can be private or public. Optionally, you can configure access members for model data as get or set methods as a structure. For inports and outports, you can configure individual access functions and set up data access to be direct (by value) or by pointer. For configurable data types, inline member function definitions are supported.

To represent data interface elements in a model and configure them for C++ code generation:

  1. In the model, include data interface elements as recommended in Model Code Interfaces.

  2. Open the Embedded Coder app.

  3. Select Code Interface > Code Mappings.

  4. In the Code Mappings editor, on the Data and Functions tabs, inspect the mappings for the interface elements. If necessary, adjust the settings.

  5. Save your interface configuration changes by saving the model.

If you prefer, you can configure C++ data interfaces by using the code mappings programming interface (see coder.mapping.api.CodeMappingCPP).

For examples, see Configure C++ Class Interface for Rate-Based Models and Configure C++ Class Interface for Export-Function Models.

For more information, see Code Mappings editor and C++ Data and Function Interfaces.