To specify code generation parameters for linked atomic subcharts from the same library:
Open the library model that contains your atomic subchart.
Unlock the library.
Right-click the library chart and select Block Parameters.
In the dialog box, specify the following parameters:
On the Main tab, select parameter Treat as atomic unit.
On the Code Generation tab, set parameter
Function packaging to Reusable
function
.
Set File name options to User
specified
.
For File name, enter the name of the file without an extension.
Click OK to apply the changes.
(OPTIONAL) Customize the generated function names for atomic subcharts:
Set model configuration parameter System target
file to ert.tlc
.
For model configuration parameter Subsystem methods, specify the format of the function names using a combination of the following naming rule tokens:
$R
— root model name
$F
— type of interface function for the
atomic subchart
$N
— block name
$H
— subsystem index
$M
— name-mangling text
Click OK to apply the changes.
When you generate code for your model, a separate file stores the code for linked atomic subcharts from the same library.
To specify code generation parameters for an unlinked atomic subchart:
In your chart, right-click the atomic subchart and select Properties.
In the dialog box, specify the following properties:
Set property Code generation function packaging
to Reusable function
.
Set Code generation file name options to
User specified
.
For Code generation file name, enter the name of the file without extension.
Click OK to apply the changes.
(OPTIONAL) Customize the generated function names for atomic subcharts:
Set model configuration parameter System target
file to ert.tlc
.
For model configuration parameter Subsystem methods, specify the format of the function names using a combination of the following naming rule tokens:
$R
— root model name
$F
— type of interface function for the
atomic subchart
$N
— block name
$H
— subsystem index
$M
— name-mangling text
Click OK to apply the changes.
When you generate code for your model, a separate file stores the code for the atomic subchart. For more information, see Generate Code from Atomic Subcharts.
To convert state A to an atomic subchart, right-click the state and select Group & Subchart > Atomic Subchart. State A changes to an atomic subchart:
Open the properties dialog box for A.
Set property Code generation function packaging to
Reusable function
.
Set Code generation file name options to
User specified
.
For Code generation file name, enter
saturator
as the name of the file.
Click OK.
Set model configuration parameter System target file
to ert.tlc
.
Select model configuration parameters Create code generation report and Open report automatically.
Select parameters Code-to-model and Model-to-code.
Click Apply.
Set model configuration parameter Subsystem methods
to the format scheme $R$N$M$F
, where:
$R
is the root model name.
$N
is the block name.
$M
is the mangle token.
$F
is the type of interface function for the
atomic subchart.
For more information, see Subsystem methods.
Click Apply.
To generate code for your model, press Ctrl+B. In the code generation report that appears, you see a separate file that contains the generated code for the atomic subchart.
To inspect the code for saturator.c
, click the hyperlink in the
report to see the following code:
Line 28 shows that the during
function generated for the atomic
subchart has the name ex_reuse_states_A_during
. This name follows
the format scheme $R$N$M$F
specified for Subsystem
methods:
$R
is the root model name,
ex_reuse_states
.
$N
is the block name, A
.
$M
is the mangle token, which is empty.
$F
is the type of interface function for the atomic
subchart, during
.
Note
The line numbers shown can differ from the numbers that appear in your code generation report.
This model shows how to partition an atomic subsystem into its own source file. Once a subsystem is specified as atomic, on the Subsystem Block Parameter dialog, on the Code Generation tab, you can specify how the subsystem is represented in the generated code using the Function packaging parameter:
Inline
: an Inlined function
Function
: function with I/O passed as global data
Reusable function
: function with I/O passed as function arguments
Auto
: Simulink Coder optimizes based on context
With the Function
and Reusable function
options, you can specify a function and file name with Function name and File name, respectively. In the model, rtwdemo_filepart
, SS1
subsystem is configured as Reusable function
with function name myfun
and file name myfile
.
open_system('rtwdemo_filepart')
This capability only partitions the code for a subsystem. The data is declared and owned by the parent model. For full system encapsulation (i.e., data and functions), use Model Reference.
bdclose('rtwdemo_filepart');