Documentation

Manage Build Process File Dependencies

An important control of the size of generated code is managing the number and size of included files (dependencies). To reduce the number of system header files and generated header files that generated code requires, it is helpful to understand the dependencies that the build process generates and the conditions that lead to dependencies.

The dependency relationships among generated source and header files appear in the figure. Arrows coming from a file point to files it includes. Other dependencies exist, for example, on Simulink®header filestmwtypes.handsimstruc_types.h, plus C or C++ library files. The figure maps inclusion relations between only those files that are generated in the build folder. These files can reference utility and model reference code located in a code generation folder. For more information about the folders and files that the build process creates, seeManage Build Process FoldersandManage Build Process Files.

The two tables identify the conditions that control creation of dependency files for GRT and ERT targets. To manage build-related dependencies, consider how these conditions apply to your model and code generation process. Then, configure model parameters and code generation options to manage build process file dependencies.

Due to differences in file packaging options for code generated with ERT-based system target files, the file dependencies differ slightly from file packaging for code generated with GRT-based system target files. SeeManage File Packaging of Generated Code Modules(Embedded Coder).

The parent system header files (model.h) include child subsystem header files (subsystem.h). In more layered models, subsystems similarly include their children's header files in the model hierarchy. As a consequence, subsystems are able to view recursively into their descendant subsystems and view into the root system because everysubsystem.corsubsystem.cppincludesmodel.handmodel_private.h.

In the figure, filesmodel.h,model_private.h, andsubsystem.hdepend on the header filertwtypes.h. If you use system target files that are not based on the ERT system target file, the source files that you generate can have additional dependencies ontmwtypes.handsimstruc_types.h.

System Header Files

系统头文件使函数声明, type definitions, and macro definitions available to the legacy or external code. Some code generation scenarios require including header files that are specific to the code generator product.

The code generator includes some system header files for broadly defined cases. For example, generated code includeswhen the model contains a utility function that requires this header file. This approach helps identify header file dependencies:

  1. Set model configuration parameterShared code placementto'Shared location'and build the model. The code generator places the utility functions in__sharedutilsfolder.

  2. Use a find-in-file utility (for example, grep utility) to search the.cand.hfiles in the__sharedutilsfolder for#include. The search results list the utilities with header file dependencies.

  3. 使用此信息来识别工具雷莫ve from the model and reduce header file dependencies in the generated code.

For more information, seeGenerate Shared Utility Code for Fixed-Point Functions.

System Header File Description and Inclusion Conditions for GRT or ERT System Target Files

Defines math constants

GRT—Generated code does not include this file.

ERT—Generated code includes this file when the code honors your model configuration for solverStop timeand either:

  • Your model configuration enables parameterMAT-file logging. SeeMAT-file logging.

  • Your model configuration enables parameterExternal mode.

Provides floating-point math functions

当你莫GRT-Generated代码包括这个文件del contains a floating-point math function.

ERT—Generated code includes this file when your model contains a floating-point math function, unless a code replacement library entry overrides the function. For more information, seeChoose a Code Replacement Library.

Defines NULL

GRT and ERT—Generated code includes this file when your model contains a utility function that requires this file.

Provides file I/O functions

当你莫GRT-Generated代码包括这个文件del includes aTo Fileblock.

ERT—Generated code includes this file when either:

  • Your model includes aTo Fileblock.

  • Your model configuration enables parameterMAT-file logging. SeeMAT-file logging.

Provides utility functions such as the integer versions ofdiv()andabs()

GRT—Generated code includes this file when either:

  • Your model includes a Stateflow®chart.

  • Your model includes a math function block configured formod()orrem(), which generate calls todiv().

ERT—Generated code includes this file when either:

  • Your model includes a Stateflow chart, and you select model configuration parameterSupport: floating-point numbers.

  • Your model includes a math function block configured formod()orrem(), which generate calls todiv().

Provides memory functions such asmemset()andmemcpy()

当你莫GRT-Generated代码包括这个文件del initialization code callsmemset().

ERT—Generated code includes this file when a block or model initialization code callsmemcpy()ormemset().

For a list of relevant blocks, in the Command Window, type:

showblockdatatypetable

Look for blocks with the N2 note. To omit calls tomemset()from model initialization code, select model configuration parametersRemove root level I/O zero initializationandRemove internal data zero initialization.

Code Generator Header Files

Dependencies in the table for generated header files apply to the system target filesgrt.tlcandert.tlc. System target files derived from these base system target files can have additional header dependencies. Code generation for blocks from blocksets, embedded targets, and custom S-functions can introduce additional header dependencies.

Header File Description and Inclusion Conditions for GRT or ERT System Target Files

builtin_typeid_types.h

Defines an enumerated type corresponding to built-in data types

GRT and ERT—Generated code includes this file when one or more of these conditions apply:

  • Your model contains a Stateflow chart that uses messages.

  • Your model configuration enables:MAT-file logging. SeeMAT-file logging.

  • Your model configuration selects C API options atCode Generation>Interface.

dt_info.h

Defines data structures for external mode

GRT and ERT—Generated code includes this file when your model configuration enables external mode.

ext_work.h

Defines external mode functions

GRT and ERT—Generated code includes this file when your model configuration enables external mode.

fixedpoint.h

Provides fixed-point support for noninlined S-functions

GRT—Generated code includes this file.

ERT—Generated code includes this file when either:

  • Your model uses noninlined S-functions.

  • Your model configuration selects parameterClassic call interface.

model_reference_types.h

Contains type definitions for timing bridges

GRT and ERT—Generated code includes this file when building a reference model or building a model that contains model blocks.

model_types.h

Defines model-specific data types

GRT and ERT—Generated code includes this file.

multiword_types.h

Contains type definitions for multiword-wide data types and their word-size chunks

GRT and ERT—Generated code includes this file when one or more of these conditions apply:

  • Your model uses multiword data types.

  • Your model configuration selects parameterMAT-file logging. SeeMAT-file logging.

  • Your model configuration selectsExternal mode.

For a model that uses multiword data types, the code generator overwrites the file if the data types are greater in length than those of the model for which code was last generated. To avoid overwriting this file, set:

  • ERTMultiwordTypeDefto'User defined'

  • ERTMultiwordLengthto the biggest length that is required by your models.

rtGetInf.h

rtGetNaN.h

rt_nonfinite.h

Support nonfinite numbers

GRT—Generated code includes this file when one or more of these conditions apply:

  • Your model contains S-functions.

  • The generated code requires nonfinite numbers.

  • Your model configuration selects parameterMAT-file logging. SeeMAT-file logging.

  • Your model configuration selects parameterClassic call interface.

ERT—Generated code includes this file when one or more of these conditions apply:

  • Your model contains S-functions.

  • The generated code requires nonfinite numbers.

  • Your model configuration selects parameterMAT-file logging. SeeMAT-file logging.

rt_defines.h

Contains type definitions for special mathematical constants (such as π ande) and defines theUNUSED_PARAMETERmacro

GRT and ERT—Generated code includes this file when either:

  • The generated code requires a mathematical constant definition.

  • The function body does not access a required model function argument.

rt_logging.h

Supports MAT-file logging and includes:

rtwtypes.h builtin_typeid_types.h multiword_types.h rt_mxclassid.h rtw_matlogging.h

GRT—Generated code includes this file.

ERT—Generated code includes this file when you model configuration selects parameterMAT-file logging. SeeMAT-file logging.

rt_mxclassid.h

DefinesmxArrayclass ID enumerations

GRT and ERT—Generated code includes this file when the code includesrt_logging.c.

rtw_continuous.h

Supports continuous time

GRT—Generated code includes this file when the code includessimstruc_types.h.

ERT—Generated code includes this file when your model configuration selects parameterSupport: continuous timeand when the code does not already includesimstruc.h.

rtw_extmode.h

Supports external mode

GRT—Generated code includes this file when the code includessimstruc_types.h.

ERT—Generated code includes this file when your model configuration selects external mode and when the code does not already includesimstruc.h.

rtw_matlogging.h

Supports MAT-file logging

GRT—Generated code includes this file when the code includessimstruc_types.handrt_logging.h.

ERT—Generated code includes this file when the code includesrt_logging.h.

rtw_solver.h

Supports continuous states

GRT—Generated code includes this file when the code includessimstruc_types.h.

ERT—Generated code includes this file when your model configuration selects parameterSupport: continuous timeand when the code does not already includesimstruc.h.

rtwtypes.h

Defines code generator data types

GRT—Generated code includes this file. Uses a verbose version of the file, which includestmwtypes.handsimstruc_types.h. Seesimstruc_types.hfor dependencies.

ERT—Generated code includes this file. Seertwtypes.h.

The code generator overwrites the previously generated rtwtypes.h when you enable (previously disabled) support for:

  • Complex numbers (SupportComplexset to'on').

  • Noninlined S-functions (SupportNonInlinedSFcnsset to'on')

To avoid rewritingrtwtypes.h, you can:

  • Specify support for complex datatypes for your models even if the models do not currently use complex data types.

  • Disable support for noninlined S-functions. In this case, the use of a noninlined S-function produces an error. To avoid the error, convert the S-function to an inlined S-function. For more information, seeInlining S-Functions(Embedded Coder).

simstruc.h

Supports calling noninlined S-functions that use theSimstructdefinition; also includes:

limits.h string.h tmwtypes.h simstruc_types.h

GRT—Generated code includes this file.

ERT—Generated code includes this file when either:

  • Your model uses noninlined S-functions.

  • Your model configuration selects parameterClassic call interface.

simstruc_types.h

Provides definitions that the generated code uses and includes the header files:

rtw_matlogging.h rtw_extmode.h rtw_continuous.h rtw_solver.h sysran_types.h

GRT—Generated code includes this file when the code includesrtwtypes.h.

ERT—Generated code does not include this file. For ERT,rtwtypes.hcontains definitions, andmodel.hcontains header files.

sysran_types.h

Supports external mode

GRT—Generated code includes this file when the code includessimstruc_types.h.

ERT—Generated code includes this file when your model configuration selects external mode and when the code does not already includesimstruc.h.

zero_crossing_types.h

Contains zero-crossing definitions for models with triggered subsystems where the trigger is rising, falling, or either. File is generated only if required by the model as determined by the data type of the trigger signal. For example, if the data type of the trigger signal is Boolean, zero-crossing detection is not needed.

GRT—Generated code does not include this file for GRT code generation targets.

ERT—Generated code includes this file when a model has a conditionally executed subsystem where a trigger uses zero crossing detection.

If generated, the content ofzero_crossing_types.his always the same.

Related Topics