| Contents | Index |
| On this page… |
|---|
Configuring Support for Numeric Data Configuring Support for Time Values Setting Up Support for Non-Inlined S-Functions Configuring Model Function Generation and Argument Passing |
The first step to configuring a model for code generation is to choose and configure a code generation target. When you select a target, other model configuration parameters change automatically to best serve requirements of the target. For example:
Code interface parameters
Build process parameters, such as the template make file
Target hardware parameters, such as word size and byte ordering
Use the Browse button on the Code Generation pane to open the System Target File Browser (see Selecting a Target). The browser lets you select a preset target configuration consisting of a system target file, template makefile, and make command.
If you select a target configuration by using the System Target File Browser, your selection appears in the System target file field (target.tlc).
If you are using a target configuration that does not appear in the System Target File Browser, enter the name of your system target file in the System target file field. Click Apply or OK to configure for that target.
Targets and Code Formats describes the use of the browser and includes a complete list of available target configurations.
You also can select a system target file programmatically from MATLAB code, as described in Selecting a System Target File Programmatically.
After selecting a system target, you can modify model configuration parameter settings.
If you want to switch between different targets in a single workflow for different code generation purposes (for example, rapid prototyping versus product code deployment), set up different configuration sets for the same model and switch the active configuration set for the current operation. For more information on how to set up configuration sets and change the active configuration set, see Manage a Configuration Set in the Simulink documentation.
The Browse button in the Target Selection subpane of the Code Generation > General pane lets you select an ERT target with the System Target File Browser. See Targets and Code Formats for a general discussion of target selection.
The code generator provides variants of the ERT target including the following:
Default ERT target
ERT target for generating and building a Visual C++® Solution (.sln) file for the Visual C++ IDE
ERT target for generating a Windows® or UNIX® host-based shared library
These targets are based on a common system target file, ert.tlc. They are displayed in the System Target File Browser as shown in the figure below.

You can use the ert_shrlib.tlc target to generate a host-based shared library from your Simulink model. Selecting this target allows you to generate a shared library version of your model code that is appropriate for your host platform, either a Windows dynamic link library (.dll) file or a UNIX shared object (.so) file. This feature can be used to package your source code securely for easy distribution and shared use. For more information, see Shared Object Libraries.
For information on customizing ERT targets, see Custom Target Development.
By default, ERT targets support code generation for integer, floating-point, nonfinite, and complex numbers.
For more information, see Code Generation Pane: Interface in the Simulink Coder reference documentation.
Certain blocks require the value of absolute time (that is, the time from the start of program execution to the present time) , elapsed time (for example, the time elapsed between two trigger events), or continuous time. Depending on the blocks used, you might need to adjust the configuration settings for supported time values.
| To... | Select... |
|---|---|
| Generate code that creates and maintains integer counters for blocks that use absolute or elapsed time values (default) | Support absolute time. For further information on the allocation and operation of absolute and elapsed timers, see the Using Timers chapter of the Simulink Coder documentation. If you do not select this parameter and the model includes block that use absolute or elapsed time values, the build process generates an error. |
| Generate code for blocks that rely on continuous time | Support continuous time. If you do not select this parameter and the model includes continuous-time blocks, the build process generates an error. |
For more information, see Code Generation Pane: Interface in the Simulink Coder reference documentation.
To generate code for noninlined S-Functions in a model, select Support noninlined S-functions. The generation of noninlined S-functions requires floating-point and nonfinite numbers. Thus, when you select Support non-inlined S-functions, the ERT target automatically selects Support floating-point numbers and Support non-finite numbers.
When you select Support non-finite numbers, the build process generates an error if the model includes a C MEX S-function that does not have a corresponding TLC implementation (for inlining code generation).
Note that inlining S-functions is highly advantageous in production code generation, for example in implementing device drivers. To enforce the use of inlined S-functions for code generation, deselect Support non-inlined S-functions.
For more information, see Code Generation Pane: Interface in the Simulink Coder reference documentation.
For ERT targets, you can configure how a model's functions are generated and how arguments are passed to the functions.
| To... | Do... |
|---|---|
| Generate model function calls that are compatible with the main program module of the GRT target (grt_main.c or .cpp) | Select GRT compatible call interface and MAT-file logging . In addition, deselect Suppress error status in real-time model data structure. GRT compatible call interface provides a quick way to use ERT target features with a GRT-based custom target by generating wrapper function calls that interface to the ERT target's Embedded-C formatted code. |
| Reduce overhead and use more local variables by combining the output and update functions in a single model_step function | Select Single output/update function Errors or unexpected behavior can occur if a Model block is part of a cycle and Single output/update function is enabled (the default). See Model Blocks and Direct Feedthrough for details. |
| Generate a model_terminate function for a model not designed to run indefinitely | Select Terminate function required. For more information, see the description of model_terminate. |
| Generate reusable, reentrant code from a model or subsystem | Select Generate reusable code. See Setting Up Support for Code Reuse for details. |
| Statically allocate model data structures and access them directly in the model code | Deselect Generate reusable code. The generated code is not reusable or reentrant. See Entry Point Functions and Scheduling for information on the calling interface generated for model functions in this case. |
| Suppress the generation of an error status field in the real-time model data structure, rtModel, for example, if you do not need to log or monitor error messages | Select Suppress error status in real-time model data structure. Selecting this parameter can also cause the rtModel structure to be omitted completely from the generated code. When generating code for multiple integrated models, set this parameter the same for all of the models. Otherwise, the integrated application might exhibit unexpected behavior. For example, if you select the option in one model but not in another, the error status might not be registered by the integrated application. Do not select this parameter if you select the MAT-file logging option. The two options are incompatible. |
| Launch the Model Step Functions dialog box (see Configuring Function Prototypes) preview and modify the model's model_step function prototype | Click Configure Step Function. Based on the Function specification value you select for your model_step function (supported values include Default model-step function and Model specific C prototype), you can preview and modify the function prototype. Once you validate and apply your changes, you can generate code based on your function prototype modifications. For more information about using the Configure Step Function button and the Model Step Functions dialog box, see Function Prototype Control. |
For more information, see Code Generation Pane: Interface in the Simulink Coder reference documentation.
For ERT targets, you can configure how a model reuses code using the Generate reusable code parameter.
Pass root-level I/O as provides options that control how model inputs and outputs at the root level of the model are passed to the model_step function.
In some cases, selecting Generate reusable code can generate code that compiles but is not reentrant. For example, if any signal, DWork structure, or parameter data has a storage class other than Auto, global data structures are generated. To handle such cases, use the Reusable code error diagnostic parameter to choose the severity levels for diagnostics
In some cases, the Embedded Coder software is unable to generate valid and compilable code. For example, if the model contains any of the following, the code generated would be invalid.
An S-function that is not code-reuse compliant
A subsystem triggered by a wide function call trigger
In these cases, the build terminates after reporting the problem.
For more information, see Code Generation Pane: Interface in the Simulink Coder reference documentation.
A target function library (TFL) is a set of one or more code replacement tables that define the target-specific implementations of math functions and operators to be used in generating code for your Simulink model. The Simulink Coder product provides default TFLs, which you can select from the Target function library drop-down list on the Interface pane of the Configuration Parameters dialog box.
| TFL | Description | Contains tables... |
|---|---|---|
| C89/C90 (ANSI) | Generates calls to the ISO®/IEC 9899:1990 C standard math library for floating-point functions. | ansi_tfl_table_tmw.mat |
| C99 (ISO) | Generates calls to the ISO/IEC 9899:1999 C standard math library. | iso_tfl_table_tmw.mat ansi_tfl_table_tmw.mat |
| GNU99 (GNU) | Generates calls to the Free Software Foundation's GNU® gcc math library, which provides C99 extensions as defined by compiler option -std=gnu99. | gnu_tfl_table_tmw.mat iso_tfl_table_tmw.mat ansi_tfl_table_tmw.mat |
| C++ (ISO) | Generates calls to the ISO/IEC 14882:2003 C++ standard math library. | iso_cpp_tfl_table_tmw.mat private_iso_cpp_tfl_table_tmw.mat iso_tfl_table_tmw.mat ansi_tfl_table_tmw.mat |
TFL tables provide the basis for replacing default math functions and operators in your model code with target-specific code. If you select a library and then hover over the selected library with the cursor, a tool tip is displayed that describes the TFL and lists the code replacement tables it contains. Tables are listed in the order in which they are searched for a function or operator match.

The Simulink Coder product allows you to view the content of TFL code replacement tables using the Target Function Library Viewer, as described in Selecting and Viewing Target Function Libraries. The Embedded Coder product allows you to additionally create and register the code replacement tables that make up a TFL, as described in Code Replacement.
![]() | Application Objectives | Code Appearance | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |