Simulink® PLC Coder™ converts subsystems to function block units according to the following rules:
Generates a function block for the top-level atomic subsystem for which you generate code.
Generates a function block for an atomic subsystem whose Function
packaging parameter is set to Reusable
function
.
Inlines generated code from atomic subsystems, whose Function
packaging parameter is set to Inline
,
into the function block that corresponds to the nearest ancestor subsystem.
This nearest ancestor cannot be inlined.
For code generation from a subsystem with no
inputs or outputs, you must set the Function packaging parameter
of the block to Reusable function
.
These topics use code generated with CoDeSys Version 2.3.
You can partition generated code using the following Subsystem block parameters on the Code Generation tab. See the Subsystem block documentation for details.
Function packaging
Function name options
Leave the File name options set to the
default, Auto
.
Use the Function packaging parameter to specify the code format to generate for an atomic (nonvirtual) subsystem. The Simulink PLC Coder software interprets this parameter depending on the setting that you choose:
Setting | Coder Interpretation |
---|---|
Auto | Uses the optimal format based on the type and number of subsystem instances in the model. |
Reusable function | Generates a function with arguments that allows reuse of subsystem code when a model includes multiple instances of the subsystem. |
Nonreusable function |
The Simulink
PLC Coder does not support |
Inline | Inlines the subsystem unconditionally. |
For example, in the plcdemo_hierarchical_virtual_subsystem
,
you can:
Inline the S1 subsystem code by setting Function
packaging to Inline
. This setting creates
one function block for the parent with the S1 subsystem inlined.
Create a function block for the S2 subsystem by setting Function
packaging to Reusable function
or
Auto
. This setting creates two function blocks,
one for the parent, one for S2.
You can use the Function name options parameter
to change the name of a subsystem from the one on the block label.
When the Simulink
PLC Coder generates software, it uses the string
you specify for this parameter as the subsystem name. For example,
see plcdemo_hierarchical_virtual_subsystem
:
Open the S1 subsystem block parameter dialog box.
If the Treat as atomic unit check box is not yet selected, select it.
Click the Code Generation tab.
Set Function packaging to Reusable
function
.
Set Function name options to User
specified
.
In the Function name field, specify
a custom name. For example, type my_own_subsystem
.
Save the new settings.
Generate code for the parent subsystem.
Observe the renamed function block.
The code for plcdemo_simple_subsystem
is
an example of generating code with one function block. The atomic
subsystem for which you generate code does not contain other subsystems.
The plcdemo_hierarchical_virtual_subsystem
example
contains an atomic subsystem that has two virtual subsystems, S1 and
S2, inlined. A virtual subsystem does not have the Treat
as atomic unit parameter selected. When you generate code
for the hierarchical subsystem, the code contains only the FUNCTION_BLOCK
HierarchicalSubsystem
component. There are no
additional function blocks for the S1 and S2 subsystems.
The plcdemo_hierarchical_subsystem
example contains an atomic subsystem
that has two nonvirtual subsystems, S1 and S2. Virtual subsystems have the
Treat as atomic unit parameter selected. When you generate
code for the hierarchical subsystem, that code contains the FUNCTION_BLOCK
HierarchicalSubsystem
, FUNCTION_BLOCK S1
, and
FUNCTION_BLOCK S2
components.