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:
The Simulink requirements listed in:
The Simulink limitations listed in Signal Requirements and Limitations (Simulink)
The Simulink Coder limitations listed in Code Generation Model Referencing Limitations
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 Pane | Option | Requirement |
---|---|---|
Solver | Start time | Some 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. |
Language | Must 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 |
Configuration Requirements for Model Referencing with ERT System Target Files (Requires Embedded Coder License)
Dialog Box Pane | Option | Requirement |
---|---|---|
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-function | If 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 | |
Support complex numbers | If | |
Suppress error status in real-time model | If | |
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. |
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.
In the Simulink Editor, from the Modeling tab, select Model Advisor.
Select By Task.
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).
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.
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.
If you have an Embedded Coder license, a custom target must meet various requirements to support model referencing. For details, see Support Model Referencing.