You can generate code for a model reference hierarchy to achieve:
Incremental code generation – generate code only if the model has changes since the code was previously generated
Incremental loading – load referenced model when it is required which speeds up model loading
Modular development – develop and maintain referenced model independently from the models that use it
Code reuse – generate reusable code from referenced model
To learn about considerations when generating code for a referenced model, see Code Generation of Referenced Models. For an example on how to generate code for a referenced model, see Generate Code for Referenced Models.
Code Generation of Referenced Models
This section describes model referencing considerations that apply specifically to code generation by the Simulink® Coder™.
Simulink Coder Model Referencing Requirements
A model reference hierarchy must satisfy various Simulink Coder requirements, as described in this section.
Minimize occurrences of algebraic loops by selecting the Minimize algebraic loop occurrences parameter on the Model Reference pane.
Generate Code for Referenced Models
Introduces generating code for models referenced with Model blocks, and using Model Explorer to browse code files.
Generate Reusable Code from Model Reference Hierarchy
Generate reusable code from a top model with Model blocks.
Combine Code Generated for Multiple Models
Generate a single executable program from multiple models or multiple copies of the same model.
By default, the Simulink engine rebuilds simulation targets before the Simulink Coder software generates model reference targets.
Establish Data Ownership in a Model Hierarchy
In the generated code, place the definitions of global variables with the components that define them.
Storage Classes for Signals Used with Model Blocks
Models containing Model blocks can use signals
of storage class Auto
without restriction.
Code Generation Model Referencing Limitations
Be aware of limitations that apply to using a model hierarchy for code generation.
Customize Library File Suffix and File Type
You can control the library file suffix and file type extension that the Simulink Coder code generator uses to name generated model reference libraries.
Simulink Cache Files for Incremental Code Generation
Share Simulink cache files in team-based development to reduce build time and avoid unnecessary code regeneration.