Deploy the Generated Code
After you generate and verify code, deploy it. In this step of the tutorial, you explore
mechanisms for deploying the code generated from the component model
ComponentDeploymentFcn
.
For component deployment, you have multiple workflow options. In each case, you must
integrate your generated code with an external main
program that handles
function scheduling.
You can:
Integrate generated source code with an external
main
function and other target environment source code, and build an executable program.Link a generated component model library with an external
main
function and other target environment code to create an executable program.Use the
codebuild
command to build a component model library from generated source code. Then, within or outside of the MATLAB® environment, link the library with an externalmain
function and other target environment code to create an executable program.
Get Meta-Information About Generated Code Interface for Integration
By default, the code generator creates a code descriptor file
(codedescriptor.dmr
) in the build folder
ComponentDeploymentFcn_ert_rtw
. That file contains meta-information
about the generated code, including:
Data interfaces (inports, outports, parameters, data stores, and internal data)
Function interfaces (initialize, output, update, and terminate)
Execution information for the data and function interfaces, such as timing requirements
Model hierarchy information and information for referenced models
You can use the code descriptor programming interface to get the contents of the code descriptor file and use the returned meta-information to confirm that generated interfaces meet integration requirements. You can also use the programming interface to provide input to tools that generate interfaces for target platform services.
For more information, see Get Code Description of Generated Code.
Integrate Generated Component Code with Target Code Environment
To integrate generated component code with a main
function and
other target environment code, you must:
Match the data and function interfaces of the generated code with other interfaces of existing system code.
Connect input data.
Connect output data.
Access other data, such as block state values, local parameters, and time.
The model used in this tutorial is designed and configured so that the generated code aligns with the code interfaces of the target environment.
The target environment software calls the generated entry-point functions, which provide input data and scheduling information.
The generated algorithm calculates output data that the calling environment uses.
The set of input and output data and the data access mechanisms constitute the interfaces of the entry-point functions.
In a model, root-level inports and outports represent the primary inputs and outputs of the component algorithm. By default, the code generator aggregates this input and output data into standard structures.
You can generate code for a component model and compile a component model library by
clearing the model configuration parameter Generate code only and
initiating a model build. If code for the component model is already generated, you can
build a component model library by using the codebuild
function with the path
.
You can link the generated component model library with a codeGenerationFolder
/modelBuildFolder
/services/libmain
function
and other target environment code to create an executable program.
For the component model library, you can also create:
A CMake configuration (
CMakeLists.txt
) file by using thecodebuild
function. See Configure CMake Build Process.A ZIP file by setting model configuration parameter Package code and artifacts and using the
packNGo
function. Then, you can relocate the ZIP file to another development environment, such as a dedicated application build system. See Relocate or Share Generated Code.
For more information, see Approaches for Building Code Generated from Simulink Models and Deploy Component Algorithm as Component Model Library by Using CMake.
Share and Archive Code Generation Report
The Quick Start tool configures a model to produce an HTML code generation report. In addition to a summary of model and code information, the report includes:
Subsystem report
Generated code files
Code interface report
Traceability report
Static code metrics report
Code replacements report
Coder assumptions report
Optionally, model web view
You can use this report outside of the Simulink® environment, so it is suitable for sharing or for archival purposes. You can open the report from the Quick Start tool or, on the C Code tab, click Open Report.
The default location for the code generation report files is in the
html
subfolder of the build folder,
.
In this case, model
_target
_rtw/html/
is the setting of model
configuration parameter System target file. The default name for the
top-level HTML report file is target
index.html
.
Identify and Package Files for Deployment
After you review and, if necessary, refine the code interfaces generated for a model,
identify files required to build the integrated code. You can generate code for a component
model and compile a component model library for deployment by clearing model configuration
parameter Generate code only and initiating a model build. If code for
the component model is already generated, you can build a component model library by using
the codebuild
function with the path
.
You can link the generated component model library with a codeGenerationFolder
/modelBuildFolder
/services/libmain
function
and other target environment code to create an executable program.
When you generate source code without compiling and linking, you can build a component model library outside of the MATLAB environment by using a CMake workflow. You can create a:
CMake configuration (
CMakeLists.txt
) file by using thecodebuild
function. See Configure CMake Build Process.ZIP file by setting model configuration parameter Package code and artifacts and using the
packNGo
function. ThepackNGo
function finds and packages files that you need to build an executable image. Then, you can relocate the ZIP file to another development environment, such as a dedicated application build system. See Relocate or Share Generated Code.
Build Integrated Code Into Executable Program
Embedded Coder® provides extensive capabilities for customizing the build process. For example:
Choose between a CMake, toolchain, or template makefile approach. See Approaches for Building Code Generated from Simulink Models.
Compile a component model library that you can link with a
main
function and other target environment code to create an executable program. See Deploy Component Algorithm as Component Model Library by Using CMake.Control compiler optimizations. See Control Compiler Optimizations.
Reduce build time by building referenced models in parallel. See Reduce Build Time for Referenced Models by Using Parallel Builds.
Customize build processing that occurs after code generation to include third-party tools. See Customize Post-Code-Generation Build Processing.
Compile code in another development environment. See Compile Code in Another Development Environment.