Main Content

Set Configuration Parameters for Code Generation of Model Hierarchies

A model reference hierarchy must satisfy various Simulink® Coder™ requirements, as described in this topic. A model referencing hierarchy to be processed by the Simulink Coder software must also satisfy:

Configuration Parameter Requirements

A referenced model uses a configuration set in the same way a top model does. 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 code generator to an inconsistent or unusable configuration parameter depends on the parameter:

  • Where a parameter inconsistency has no significance, the code generator ignores or resolves the inconsistency without posting a warning.

  • Where a nontrivial and possibly acceptable solution exists to an inconsistent parameter, the code generator resolves the conflict silently; resolves it with a warning; or generates an error.

  • If an acceptable resolution is not possible, the code generator produces an error. You must then change parameter values to eliminate the issue.

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 time-consuming. You can control or eliminate such overhead by using configuration references to assign an externally stored configuration set to multiple models. For more information, see Share a Configuration with Multiple Models.

To select a code generation target for a model reference hierarchy without modifying the individual models, use a configuration reference in the Simulink data dictionary. For more information, see Use Configuration Reference to Select Code Generation Target (Embedded Coder).

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 code generator resolves violations of these requirements, but most cases require you to make changes to parameters in your models.

Configuration Requirements for Model Referencing with 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.

Generate C API for options

The C API check boxes that you select 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 off, the code generator temporarily sets it to off during code generation.

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

Dialog Box PaneOptionRequirement

Identifiers

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

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

Ignore custom storage classes

Must be the same for top and referenced models.

Support floating-point numbers

Must be the same for 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.

Remove error status field in real-time model data structure

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. The code generator performs name mangling 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 (in addition to the $M token) must be included in the Identifier format control parameter specifications except for Shared utilities identifier format.

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

For more information, see Model Configuration Parameters: Code Generation Identifiers.

Custom Target Requirements

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

Miscellaneous Considerations

Minimize occurrences of algebraic loops by selecting the Minimize algebraic loop occurrences parameter on the Model Referencing pane. The setting of this option affects only generation of code from the model. For more information about direct feed through, see Algebraic Loop Concepts.

Use the Integer rounding mode parameter on your model's blocks to simulate the rounding behavior of the C compiler that you intend to use to compile code generated from the model. This setting appears on the Signal Attributes pane of the parameter dialog boxes of blocks that can perform signed integer arithmetic, such as the Product and n-D Lookup Table blocks.

For most blocks, the value of Integer rounding mode completely defines rounding behavior. For blocks that support fixed-point data and the Simplest rounding mode, the value of Signed integer division rounds to also affects rounding. For details, see Rounding (Fixed-Point Designer).

Related Topics