Manage File Packaging of Generated Code Modules
The code generator produces code modules. The file packaging configuration controls where the code generator places code into code modules and header files.
To locate and examine the generated code files, use the Code view or the HTML code generation report. The code generation report provides hyperlinks in the comments that you can click to view the generated code in a MATLAB® web browser. For more information, see Traceability in Generated Code.
Generated Code Modules
The code generator creates a build folder in your working folder
to store generated source code. The build folder contains object files,
a makefile, and other files created during the code generation process.
The default name of the build folder is
.model
_ert_rtw
Code Modules and Header Files Affected by File Packaging summarizes the structure of source code that the code generator produces.
You can customize the generated set of files in several ways:
File packaging formats: Manage the number of source files generated for your model. Select model configuration parameter File packaging format. For more information, see Customize Generated Code Modules.
Nonvirtual subsystem code generation: Instruct the code generator to produce separate functions within separate code files for nonvirtual subsystems. You can control the names of the functions and of the code files. For more information, see Generate Subsystem Code as Separate Function and Files.
Storage classes: Define and use storage classes that partition generated data structures into different files based on file names that you specify. For more information, see Organize Parameter Data into a Structure by Using Struct Storage Class.
Module packaging: Direct the generated code into a required set of
.c
or.cpp
and.h
files, and control the internal organization of the generated files. For details, see Code Interface Configuration.
Code Modules and Header Files Affected by File Packaging
File | Description |
---|---|
| By default, contains entry points for code implementing the model algorithm (for
example, |
| Contains local macros and local data that the model and subsystems require. This file
is included in the |
| Declares model data structures and a public interface
to the model entry-points and data structures. Provides an interface
to the real-time model data structure ( The code generator:
If you interface handwritten code to generated
code for one or more models, include |
| Contains (if conditionally generated) the declarations
for the parameters data structure, the constant block I/O data structure,
and any zero representations for the
model structure data types. If the model does not use these data structures
and zero representations, |
| Provides forward declarations for the real-time model data structure and the parameters data structure. Function declarations of reusable functions can require these declarations. Provides type definitions for user-defined types that the model uses. |
Certain utility files such as | Utility files that support fixed-point arithmetic operations or that define zero-crossing functions. Other utility files are not affected by file packaging and are instead affected by the Shared code placement model configuration parameter. The code generator generates utility code if the model contains blocks that require it. |
User-Written Code Modules
Code that you write to interface with generated model code usually includes a customized main module. Base this module on a main program produced by the code generator. This customized main module can also include interrupt handlers, device driver blocks and other S-functions, and other supervisory or supporting code. Steps to set up the development environment to support a customized main module include:
Establish a working folder for your own code modules.
Put your working folder on the MATLAB path.
At minimum, inform the build process about the location of your source and object files with model configuration parameter Additional build information.
Your development process could require generating code for a particular microprocessor or development board and deploying the code on target hardware with a cross-development system. To accomplish these goals, make more extensive modifications to the ERT-based system target file.
For information on how to customize your ERT-based system target file for your production requirements, see Custom Software for Target Hardware.
Customize Generated Code Modules
Model configuration parameter File packaging
format specifies how the code generator packages generated source code
into files. You can set the parameter to Modular
,
Compact (with separate data file)
, and
Compact
. This table describes the generated files and the
removed files for each file packaging format.
Generated Files According to File Packaging Format
File Packaging Format | Generated Files | Removed Files |
---|---|---|
Modular (default) |
subsystem files (optional) user-defined files that contain Simulink functions and entry-point functions (optional)
Utility files that support nonfinite values or that
define zero-crossing functions, such as | None |
Compact (with separate data file) |
|
Utility files that support nonfinite values or that define
zero-crossing functions, such as |
Compact |
|
Utility files that support nonfinite values or that define
zero-crossing functions, such as |
This table describes content placement from the removed files.
Removed Files According to File Packaging Format
Removed File | Generated Content In File |
---|---|
| and
|
|
|
|
|
You can specify a different file packaging format for each referenced model.
Model configuration parameter Shared code placement interacts with file
packaging operations. If you set Shared code placement to
Shared location
, the code generator produces separate files for
utility code in a shared location, regardless of the file packaging format. If you set
Shared code placement to Auto
, the code
generator generates code for utilities according to the file packaging format
selection.
Modular
: Some shared utility files are in the build folder.Compact (with separate data file)
: Utility code is generated in
.model
.cCompact
: Utility code is generated in
.model
.c
File packaging formats Compact
and Compact
(with separate data file)
generate
for
models containing:model
_types.h
A Variant Subsystem block. The
file includes preprocessor directives defining the variant objects associated with a variant block.model
_types.hStorage classes generating a separate header file.
File packaging formats Compact
and Compact
(with separate data file)
are not compatible with:
A model containing a subsystem, which is configured to generate separate source files
A model containing a noninlined S-function
A model for which Shared code placement is set to
Auto
, which uses data objects for which Data scope is set toExported
Note
The File packaging format parameter does not impact Stateflow® charts in which you select the Treat exported functions as globally visible parameter. These exported functions are global and shared by other source files. Therefore, the functions must produce headers with function declarations, which other source files can include.