Generated Functions in a Model Reference Hierarchy
When you generate code for a model, the code generator creates a subfolder
<model>_grt_rtw
(Simulink®
Coder™) or a subfolder <model>_ert_rtw
(Embedded Coder®) in your current working folder and places source code files in this
folder. The generated code is in these two primary files:
<model>.c
— This file contains the algorithm code. The generated code is mainly comprised of model data and model entry-point functions that are accessible to a caller by including the<model>.h
file. You can call the generated model entry-point functions from external code or from a version of the generatedmain
function that you modify.<model>.h
— This file contains theextern
declarations for block outputs, continuous states, model output, entry points, and timing data. For more information about data structures, see Data Structures in the Generated Code.
When you generate code for a referenced model hierarchy, the code generator places the
code for the top model in the subfolder
<model>_grt_rtw
(Simulink Coder) or the
subfolder <model>_ert_rtw
(Embedded Coder) in
your current working folder and places the code for referenced models in an
slprj
folder.
Generated Functions in a Top Model
In a model reference hierarchy, the code generator commonly produces these functions for a top model.
Function Name | Description |
---|---|
<model>_step | Execution function that contains the output and update code
for the blocks in a Simulink model. This function calls the
referenced model function. The code generator produces this
function by default. To generate separate functions for output
and update code, clear the model configuration parameter
Single output/update
function. For more information, see model_step . |
<model>_initialize | Initialization function that executes the initialization code
for a Simulink model. The code generator calls this function
once at the start of the application code. This function might
call the
<ref_model>_Init
function of a referenced model to initialize states and
<ref_model>_initialize
for zero initialization. For more information, see model_initialize . |
<model>_terminate | Termination function that contains the code to turn off a
system. For ERT-based models, you can suppress generation of
this function by clearing the model configuration parameter
Terminate function
required. For more information, see model_terminate . |
Generated Functions in a Referenced Model
The functions generated for a referenced model are internal functions used by the code generator. These functions are not intended to interface with external code. In a model reference hierarchy, the code generator commonly produces these functions for a referenced model.
Function Name | Description |
---|---|
<ref_model>_Init | Initialization function in a referenced model that is called
from a top model entry-point function
<model>_initialize .
The
<model>_initialize
of the top model initializes the code for the model reference
hierarchy and calls the
<ref_model>_Init
of the child model to initialize the states to their initial
condition. |
<ref_model> | Execution function that serves a similar purpose as
<model>_step
of a top model but is not an entry-point function for the
external code. The two functions differ in terms of the scope.
The <ref_model>
function computes the outputs from internal state and updates
that state. The
<model>_step does
the same but calls the individual
<ref_model>
function of the referenced models. |
<ref_model>_initialize | Initialization function that executes the initialization code
for a referenced model. The code generator calls this function
from a top model entry-point function
<model>_initialize .
The
<model>_initialize
of the top model initializes the code for the model reference
hierarchy and calls the
<ref_model>_initialize
of the child model to zero-initialize the referenced model
code. |