Simulink Coder Model Referencing Requirements

A model reference hierarchy must satisfy various Simulink® Coder™ requirements, as described in this section. In addition to these requirements, a model referencing hierarchy to be processed by the Simulink Coder software must satisfy:

Configuration Parameter Requirements

A referenced model uses a configuration set in the same way a top model does, as described in Manage Configuration Sets for a Model (Simulink). By default, every model in a hierarchy has its own configuration set, which it uses in the same way that it would if the model executed independently.

Because each model can have its own configuration set, configuration parameter values can be different in different models. Furthermore, some parameter values are intrinsically incompatible with model referencing. The response of the Simulink Coder software to an inconsistent or unusable configuration parameter depends on the parameter:

  • Where an inconsistency has no significance, the product ignores or resolves the inconsistency without posting a warning.

  • Where a nontrivial and possibly acceptable solution exists, the product resolves the conflict silently; resolves it with a warning; or generates an error.

  • If an acceptable resolution is not possible, the product generates an error. You must then change parameter values to eliminate the problem.

When a model reference hierarchy contains many referenced models that have incompatible parameter values, or a changed parameter value must propagate to many referenced models, manually eliminating configuration parameter incompatibilities can be tedious. You can control or eliminate such overhead by using configuration references to assign an externally-stored configuration set to multiple models. See Share a Configuration with Multiple Models (Simulink) for details.

The following tables list configuration parameters that can cause problems if set in certain ways, or if set differently in a referenced model than in a parent model. Where possible, the Simulink Coder software resolves violations of these requirements automatically, but most cases require changes to parameters in your models.

Configuration Requirements for Model Referencing with All System Target Files

Dialog Box PaneOptionRequirement
SolverStart timeSome system target files require the start time of models to be zero.

Hardware Implementation

All options

Values must be the same for top and referenced models.

Code Generation

System target file

Must be the same for top and referenced models.

LanguageMust be the same for top and referenced models.
Generate code only

Must be the same for top and referenced models.

Identifiers

Maximum identifier length

Cannot be longer for a referenced model than for its parent model.

Interface

Code replacement library

Must be the same for top and referenced models.

C API options

The C API check boxes must be the same for top and referenced models.

ASAP2 interface

Can be on or off in a top model, but must be off in a referenced model. If it is not, the Simulink Coder software temporarily sets it to off during code generation.

Configuration Requirements for Model Referencing with ERT System Target Files (Requires Embedded Coder License)

Dialog Box PaneOptionRequirement

Comments > Advanced parameters

Ignore custom storage classes

Must be the same for top and referenced models.

Identifiers

Global variables
Global types
Subsystem methods
Local temporary variables
Constant macros
$R token must appear.

Signal naming

Must be the same for top and referenced models.

M-functionIf specified, must be the same for top and referenced models.

Parameter naming

Must be the same for top and referenced models.

#define naming

Must be the same for top and referenced models.

Interface

Support floating-point numbers

Must be the same for both top and referenced models

Support non-finite numbers

If off for top model, must be off for referenced models.

Support complex numbers

If off for top model, must be off for referenced models.

Suppress error status in real-time model

If on for top model, must be on for referenced models.

Code Placement

Use owner from data object for data definition placement

Must be the same for top and referenced models.

Signal display level

Must be the same for top and referenced models.

Parameter tune level

Must be the same for top and referenced models.

Configuration Parameters Changed During Code Generation

For referenced models, if these Configuration Parameters > Code Generation > Identifiers parameters have settings that do not contain a $R token (which represents the name of the referenced model), code generation prepends the $R token to the identifier format:

  • Global variables (CustomSymbolStrGlobalVar)

  • Global types (CustomSymbolStrType)

  • Subsystem methods (CustomSymbolStrFcn)

  • Constant macros (CustomSymbolStrMacro)

You can use the Model Advisor to identify models in a model referencing hierarchy for which code generation changes configuration parameter settings.

  1. In the Simulink Editor, from the Modeling tab, select Model Advisor.

  2. Select By Task.

  3. Run the Check code generation identifier formats used for model reference check.

If a script that operates on generated code uses identifier formats that code generation changes, then update the script to use the updated identifier format (which includes an appended $R token).

For more information about identifiers, see Identifier Format Control (Embedded Coder).

Naming Requirements

Within a model that uses model referencing, names of the constituent models cannot collide. When you generate code from a model that uses model referencing, the Maximum identifier length parameter must be large enough to accommodate the root model name and the name-mangling text. A code generation error occurs if Maximum identifier length is not large enough.

When a name conflict occurs between a symbol within the scope of a higher-level model and a symbol within the scope of a referenced model, the symbol from the referenced model is preserved. Name mangling is performed on the symbol from the higher-level model.

Embedded Coder Naming Requirements

The Embedded Coder® product lets you control the formatting of generated symbols in much greater detail. When generating code with an ERT target from a model that uses model referencing:

  • The $R token must be included in the Identifier format control parameter specifications (in addition to the $M token) except for Shared utilities identifier format.

  • The Maximum identifier length must be large enough to accommodate full expansions of the $R and $M tokens.

See Model Configuration Parameters: Code Generation Identifiers for more information.

Custom Target Requirements

If you have an Embedded Coder license, a custom target must meet various requirements to support model referencing. For details, see Support Model Referencing.