Main Content

Code Interface Configurations

For C code generation, code interface configurations define templates that inform the code generator about requirements for the appearance, placement, and behavior of interface code. To generate interface code that aligns with specific target environment requirements, someone must define a code interface configuration for your project. A code interface configuration can be data or service oriented. Embedded Coder® provides a default data interface configuration for generating code for application deployment. You can create custom code interface configurations for application and component deployment. Before generating code for a model, a modeler associates a code interface configuration that is defined in an Embedded Coder Dictionary with the model and, in the Embedded Coder app, maps model elements to code interfaces defined in the stored configuration. The code generator uses the mappings to substitute model-specific information into the interfaces defined in the code interface configuration.

Relationship between code interface configuration and model element code mappings.

You can create data or service interface configurations. This table compares the interfaces that you can define for each type of configuration.

Data Interface ConfigurationService Interface Configuration
Function customization template for initialize and terminate functionsFunction customization template for initialize and terminate functions
Function customization template for periodic and aperiodic functionsFunction customization template for periodic and aperiodic functions
Storage classes for direct access to data in memoryStorage classes SignalStruct and ParamStruct and storage classes that you create for direct access to data in memory
Function memory section for placing callable entry-point function code in memoryFunction memory section for placing callable entry-point function code in memory
Data memory section for direct access to data in memoryData memory section for direct access to data in memory
 Receiver service interfaces
 Sender service interfaces
 Data transfer service interfaces
 Timer service interfaces
 Parameter tuning interfaces
 Parameter argument tuning interfaces
 Measurement interfaces

The code generator uses the code interface configuration to produce this interface code:

  • Entry-point function prototypes for callable initialize and terminate functions

  • Entry-point function prototypes for callable periodic or aperiodic functions

  • Calls to target environment services

  • Variable assignments

  • Compiler pragma statements that identify areas of memory where functions and data are stored

Options for Code Interface Configuration Storage

The code interface configuration for a model resides in an Embedded Coder Dictionary. The coder dictionary can reside within the model (model-owned) or can be a separate .sldd file that models can share.

Comparison of model-owned and shared code interface configurations

Model-Owned Embedded Coder Dictionary

By default, Simulink® associates a model with a model-owned Embedded Coder Dictionary. A model-owned dictionary contains a code interface configuration that applies to the owner model only. You can customize the configuration. Use a model-owned dictionary for models of smaller scope and that do not share code interface requirements with other models. To customize the default model-owned dictionary, on the Embedded Coder app toolstrip, click Code Interface > Embedded Coder Dictionary (Model).

Shared Embedded Coder Dictionary

A shared code Embedded Coder Dictionary:

  • Resides in an *.sldd.

  • Is independent of models that use it. A model and the dictionary that contains the code interface configuration are separate entities.

  • Can be created from the Model Explorer.

  • Can be linked to multiple models.

The separation of the model and dictionary enables you to:

  • Standardize code generated from models designed across your organization for a specific target environment.

  • Generate code that meets requirements of different target environments from a model.

Because the dictionary that contains a code interface configuration and the model are separate entities, modelers must link the dictionary to models. Depending on how you create the dictionary, the link to a model might be set up automatically (see Deploy Code Generation Definitions). Once a model is linked with a code interface configuration, the modeler can map interface elements represented in the model to the configured interfaces (function customization templates, storage classes, and services).

To configure a model with a service interface, you must link the model to a shared coder dictionary.

To create a shared Embedded Coder Dictionary, in the Model Explorer, click New > Create Embedded Coder Dictionary or in the Embedded Coder app, click Code Interface > Set up shared Embedded Coder Dictionary.

Code Interface Configurations for Data Objects

To create code interface configurations for data objects that you store in the base workspace or in a Simulink data dictionary, use the Custom Storage Class designer to create a configuration in a package. For these data objects, you apply code generation settings to the data object instead of applying them in the mapping of a model. When an item in a model uses the data object and its code generation settings, the code mapping for the item reflects the configuration of the data object.

If you want to use the same code interface configuration in model code mappings and in data objects, you do not need to store one copy of the configuration in an Embedded Coder Dictionary and another copy in a package. Instead, store the configuration in a package (by using the Custom Storage Class Designer). Then, configure one or more Embedded Coder Dictionaries to refer to the configuration in the package. When you want to make changes to the configuration, you make the changes in only one place, the package.

For more information, see Create Storage Classes by Using the Custom Storage Class Designer.

Related Topics