Compare System Target File Support Across Products
When you select a system target file (such as grt.tlc
), the selection
defines the run-time environment and the code generation features. Identify the system target
file features that match your code generation workflow goals.
The code generator uses the system target file to produce code intended for execution on certain target hardware or on a certain operating system. The system target file invokes other run-time environment-specific files. For more information on configuring model code generation parameters for target hardware, see Configure Run-Time Environment Options.
Different types of system target files support a selection of generated code features. In
the system target file, the value of the CodeFormat
TLC variable and
corresponding rtwgensettings.DerivedFrom
field value identify the system
target file type and generated code features. These selections apply your code generation
control decisions at several points in the code generation process. Your selections include
whether and how the model build generates:
Certain data structures (for example,
SimStruct
orrtModel
)Static or dynamic memory allocation code
Calling interface for generated model functions
For custom system target file development, the CodeFormat
value differs
among code generation targets:
If the system target file does not include a value for the
CodeFormat
TLC variable, the default value isRealTime
for generic real-time target (GRT). The correspondingrtwgensettings.DerivedFrom
field value isgrt.tlc
(default value).If you are developing a custom system target file and you have Embedded Coder software, consider setting the
CodeFormat
TLC variable value toEmbedded-C
for embedded real-time target (ERT). The correspondingrtwgensettings.DerivedFrom
field value isert.tlc
. The ERT system target file supports more generated code features than the GRT system target file.
This example shows how the value for the CodeFormat
TLC variable and
corresponding rtwgensettings.DerivedFrom
field value are set in
ert.tlc
.
%assign CodeFormat = "Embedded-C" /% BEGIN_RTW_OPTIONS rtwgensettings.DerivedFrom = 'ert.tlc'; END_RTW_OPTIONS %/
Note
Use the value for the CodeFormat
TLC variable with its corresponding
rtwgensettings.DerivedFrom
field value to generate code for the model.
If you do not select a value explicitly, the default values apply. For the
rtwgensettings.DerivedFrom
field, use 'ert.tlc'
or
'grt.tlc'
. For more information, see System Target File Structure.
For a description of the optimized call interface generated by default for the GRT and ERT system target files, see Configure Generated C Function Interface for Model Entry-Point Functions.
Code generation with the GRT and ERT system target files uses the real-time model data
structure (rtModel
). This structure encapsulates model-specific information
in a much more compact form than the simulation structure, SimStruct
. Many
efficient features of generated code depend on generation of rtModel
rather
than SimStruct
, including:
Integer absolute and elapsed timing services
Independent timers for asynchronous tasks
Generation of improved C API code for signal, state, and parameter monitoring
Pruning the data structure to minimize its size (ERT-derived system target files only)
For a description of the rtModel
data structure, see Real-Time Model Data Structure.
Compare Product System Target Files
You can select from a range of system target files by using the System Target File Browser. This selection lets you experiment with configuration options and save your model with different configurations.
You cannot build or generate code for non-GRT system target files, unless you have the required software on your system. For example, you require Embedded Coder® for ERT system target files, Simulink® Desktop Real-Time™ for SLDRT system target files, and so on.
Selecting a system target file for your model selects either the toolchain approach or the template makefile approach for build process control. For more information about these approaches, see Approaches for Building Code Generated from Simulink Models.
System Target Files Available from System Target File Browser
Supported System Target File | File Names | Reference |
---|---|---|
Embedded Coder (for PC or UNIX® platforms) |
| |
Create Visual C++® Solution File for Embedded Coder |
(Requires CMake toolchain. See note.) | |
Embedded Coder for AUTOSAR |
| |
Generic Real-Time (for PC or UNIX platforms) |
| |
Create Visual C++ Solution File |
(Requires CMake toolchain. See note.) | |
Rapid Simulation (default for PC or UNIX platforms) |
| Accelerate, Refine, and Test Hybrid Dynamic System on Host Computer by Using RSim System Target File |
Rapid Simulation for UNIX platforms |
| Accelerate, Refine, and Test Hybrid Dynamic System on Host Computer by Using RSim System Target File |
Rapid Simulation for Visual C++ compiler |
| Accelerate, Refine, and Test Hybrid Dynamic System on Host Computer by Using RSim System Target File |
S-Function for PC or UNIX platforms |
| |
S-Function for UNIX platforms |
| |
S-Function for Visual C++ compiler |
| |
ASAM-ASAP2 Data Definition |
(Will be removed in a future release. See Generate ASAP2 and CDF Calibration Files for information about how to generate A2L Files) | |
Simulink Desktop Real-Time |
| Set Run in Kernel Mode Code Generation Parameters (Simulink Desktop Real-Time) |
Simulink Real-Time™ |
| Simulink Real-Time Options Pane (Simulink Real-Time) |
Note
To create and build a Visual C++ Solution (.sln
) file with Debug configuration, in the
Toolchain
field, specify a CMake toolchain, for example, Microsoft Visual Studio
Project 2019 | CMake (64-bit Windows)
or Microsoft Visual
Studio Project 2017 | CMake (64-bit Windows)
. For more information about
CMake toolchains, see Configure CMake Build Process.
Compare Code Styles and STF Support
The code generator produces two styles of code. One code style is suitable for rapid prototyping (and simulation by using code generation). The other style is suitable for embedded applications. This table maps system target files to corresponding code styles.
Code Styles Listed by System Target File
System Target File | Code Style | Purpose |
---|---|---|
Embedded Coder embedded real-time (ERT) | Embedded | A starting point for embedded application development of C/C++ generated code. |
Simulink Coder™ generic real-time (GRT) | Rapid prototyping | A starting point for creating a rapid prototyping target hardware that does not use real-time operating system tasking primitives and for verifying the generated C/C++ code on your desktop computer. |
Rapid simulation (RSim) | Rapid prototyping | Provides non-real-time simulation on your desktop computer and a high-speed or batch simulation tool. |
S-function | Rapid prototyping | Creates a C MEX S-function for simulation within another Simulink model. |
Simulink Desktop Real-Time | Rapid prototyping | Runs a model in real time at interrupt level while your desktop computer runs Microsoft® Windows® in the background. |
Simulink Real-Time | Rapid prototyping | Runs a model in real time on a desktop computer running the Simulink Real-Time kernel. |
Third-party vendors supply additional system target files to support code generation for
their products. For more information about third-party products, see the vendor website or
the MathWorks® Connections program web page: https://www.mathworks.com/products/connections
.
Compare Generated Code Features by Product
The code generation process for real-time system target files (such as GRT) provides many embedded code optimizations. Selecting an ERT-based system target file offers more extensive features than GRT. The system target file selection determines the available features for the code generation product. As you select the code generation target that matches your development process, use this table to compare code generation features available with Simulink Coder and features available with Embedded Coder.
Compare Code Generation Features for Simulink Coder Versus Embedded Coder
Feature | Simulink Coder | Embedded Coder |
---|---|---|
|
|
|
Custom storage classes (CSCs) | Code generation ignores CSCs. Objects are assigned a CSC default to
| Code generation with CSCs is supported |
HTML code generation report | Basic HTML code generation report | Enhanced report with additional detail and hyperlinks to the model |
Symbol formatting | Symbols (for signals, parameters, and so on) are generated in accordance with hard-coded default | Detailed control over generated symbols |
User-defined maximum identifier length for generated symbols | Supported | Supported |
Generation of terminate function | Generated | Option to suppress the terminate function |
Combined output/update function | Separate output/update functions are generated | Option to generate combined output/update function |
Optimized data initialization | Not available | Options to suppress generation of unnecessary initialization code for zero-valued memory, I/O ports, and so on |
Comments generation | Basic options to include or suppress comment generation | Options to include Simulink block descriptions, Stateflow® object descriptions, and Simulink data object descriptions in comments |
Module Packaging Features (MPF) | Not supported | Extensive code customization features See Manage Replacement of Simulink Data Types in Generated Code and MPT Data Object Properties. |
System target file-optimized data types header file | Requires full | Generates optimized |
User-defined types | User-defined types default to base types in code generation | User-defined data type aliases are supported in code generation |
Rate grouping | Not supported | Supported |
Auto-generation of main program module | Not supported. Static main program module is provided. | Automated and customizable generation of main program module is supported (static main program also available) |
Reusable (multi-instance) code generation | Option to generate reusable code with dynamic memory allocation | Option to generate reusable code with static or dynamic memory allocation |
Software constraint options | Support for floating-point, complex, and nonfinite numbers is enabled | Options to enable or disable support for floating-point, complex, and nonfinite numbers |
Application life span | Defaults to | User-specified. Determines most efficient word size for integer timers |
ANSI®-C/C++ code generation | Supported | Supported |
ISO®-C/C++ code generation | Supported | Supported |
GNU®-C/C++ code generation | Supported | Supported |
Generate scalar inlined parameters as | Not supported | Supported |
MAT-file variable name modifier | Supported | Supported |
Data exchange: C API, ASAP2, external mode | Supported | Supported |
Compare Generated Code Features by STF
The code generator supports a selection of generated code features for different types
of system target files. In each system target file, the value of the
CodeFormat
TLC variable identifies the set of features.
This table summarizes how different system target files support applications.
Application | System Target File (STF) |
---|---|
Fixed- or variable-step acceleration | RSIM, S-Function, Model Reference |
Fixed-step real-time deployment | GRT, ERT, Simulink Real-Time, Simulink Desktop Real-Time, ... |
This table summarizes the various options available for each System target file selection, with the exceptions noted.
Features Supported in Code Generated for System Target Files (STF)
System Target Files (STF) | ||||||||
---|---|---|---|---|---|---|---|---|
Feature |
(See note 1.) |
(See note 1.) |
(See note 1.) |
(See note 1.) |
(See note 1.) |
(See note 1.) |
(See note 1.) | Other (See note 1.) |
Static memory allocation | X | X |
|
| X | X | X | |
Dynamic memory allocation | X (See notes 4, 5.) | X (See notes 4, 5.) |
| X | X |
| X |
|
Continuous time | X | X |
| X | X | X | X |
|
C/C++ MEX S-functions | X | X |
| X | X | X | X |
|
S-function (inlined) | X | X |
| X | X | X | X | X |
Minimize RAM/ROM usage |
| X |
|
|
|
| X2 | X |
Supports external mode | X | X |
|
| X | X | X |
|
Rapid prototyping | X |
|
|
|
| X | X | X |
Production code |
| X |
|
|
|
| X2 | X (See note 3.) |
Batch parameter tuning and Monte Carlo methods |
|
| X |
| X |
|
|
|
System-level Simulator |
|
| X |
|
|
|
|
|
Executes in hard real time | X (See note 3.) | X (See note 3.) |
|
|
| X | X | X5 |
Non-real-time executable included | X | X |
|
| X |
|
|
|
Multiple instances of model | X (See notes 4, 5.) | X (See notes 4, 5.) |
| X4 |
|
| X (See notes 4, 5.) | X (See notes 4, 5.) |
Supports variable-step solvers |
|
|
| X | X |
|
|
|
Supports SIL/PIL | X | X |
|
|
|
|
| X |
Notes
System Target Files:
grt.tlc
— Generic real-time targetert.tlc
— Embedded real-time targetert_shrlib.tlc
— Embedded real-time target shared libraryrtwsfcn.tlc
(To be removed) — S-function targetrsim.tlc
— Rapid simulation targetsldrt.tlc
— Simulink Desktop Real-Time targetspeedgoat.tlc
— Simulink Real-Time targetOther — The Simulink Coder embedded real-time capabilities support other system target files
Does not apply to GRT-based system target files. Applies to only ERT-based system target files.
The default GRT and ERT
rt_main
files emulate execution of hard real time. When explicitly connected to a real-time clock, they execute in hard real time.You can generate code for multiple instances of a Stateflow chart or subsystem containing a chart, except when the chart contains exported graphical functions.
In the Configuration Parameters dialog box, for the Code interface packaging field, select
Reusable function
.