Control Generation of Functions for Subsystems
What is a Subsystem Function?
A subsystem function is a function that the code generator produces for a subsystem in a model. The function interface and how the code generator packages the code depends on whether the subsystem is a virtual or atomic (nonvirtual) subsystem and how you configure the subsystem block parameters. For more information, see Subsystem, Atomic Subsystem, CodeReuse Subsystem.
Options for Controlling Generation of Subsystem Function Code
You can design and configure a model in a way that controls how the code generator produces code from subsystems.
|Generate inlined code from a selected subsystem.||Generate Inlined Subsystem Code|
|Generate code for only a subsystem.||Generate Code and Executables for Individual Subsystems|
|Generate separate functions without arguments, and optionally place the subsystem code in a separate file.||Generate Subsystem Code as Separate Function and Files|
|Generate a single reentrant function for a subsystem that is included in multiple places within a model.||Generate Reentrant Code from Subsystems|
|Generate a single reentrant function for a subsystem that is included in multiple places in a model reference hierarchy.||Generate Reusable Code from Library Subsystems Shared Across Models|
|Generate code for a reusable library subsystem that contains multiple function interfaces.||Library-Based Code Generation for Reusable Library Subsystems|
Subsystem Function Dependence
generated from subsystems can be completely independent of code generated for a model. When
generating code for a subsystem, the code can reference global data structures of the model,
even if the subsystem function code is in a separate file. Each subsystem code file contains
include directives and comments describing the dependencies. The code
generator checks for cyclic file dependencies and warns about them at build time. For
descriptions of how the code generator packages code, see Manage Build Process File Dependencies.
To generate subsystem function code that is independent of the code generated for the parent model, place the subsystem in a library and configure it as a reusable subsystem, as explained in Generate Reusable Code from Library Subsystems Shared Across Models.
If you have an Embedded Coder® license, you can generate code for library consisting of reusable subsystems that have different function interfaces. For more information, see Library-Based Code Generation for Reusable Library Subsystems.
Preserve Subsystem Boundaries in Generated Code
This example shows how to preserve the boundary of a virtual subsystem. By selecting subsystem parameter Treat as atomic unit, you instruct the code generator to build code for the subsystem so that it executes as an atomic unit. Once you mark a system as atomic, you can specify how the code generator represents the subsystem in code by setting the block parameter Code Generation Function Packaging. You can specify that the code generator produce these code implementations for the subsystem:
Inline: Inline the subsystem code at the call sites
Function: A void/void function with I/O and internal data in global data structure
Reusable function: A re-entrant function with data passed in as part of function arguments
Auto: Let Simulink Coder optimize the implementation based on context
1. Generate code and a code generation report.
2. Use the generated report to inspect the generated source file
SS1, the code generator produces reusable function code with function name
Simulink and Simulink Coder can avoid artificial algebraic loops if you select parameter Minimize algebraic loop occurrences. See the Simulink documentation for information on minimizing occurrences of algebraic loops.
model = 'rtwdemo_atomic'; open_system(model);