The code generator includes a variety of approaches for integrating legacy or custom code with generated code. Legacy code is existing handwritten code or code for environments that you integrate with code that the code generator produces. Custom code is legacy code or other user-specified lines of code that you include in the code generator build process. Collectively, legacy and custom code are called external code.
You integrate external code by importing existing external code into code produced by the code generator, exporting generated code into an existing external code base, or you can do both. For example, you can import code by calling an external function, by using the Legacy Code Tool, or place external code at specific locations in generated code by including Custom Code blocks in a model. When you import external code, the resulting generated code interfaces with generated scheduling code.
You can export generated code as a plug-in function for use in an external development environment. When you export generated code, you intend to interface that code manually with a scheduling mechanism in your application run-time environment.
For guidance on choosing an approach based on your application requirements, see Choose an External Code Integration Workflow .
What Is External Code Integration?
What external code integration is.
Choose an External Code Integration Workflow
For application integration points, characterize external code, identify code generation integration requirements, and choose a workflow.
External Code Integration Examples
Examples that show scenarios of external code integration with the Legacy Code Tool.
Untrusted Custom Code, Custom Targets, and Callbacks
Use of untrusted custom code entails risk.
Call Reusable External Algorithm Code for Simulation and Code Generation
Call external algorithmic code, which is hardware-independent and reusable, from generated code.
Place External C/C++ Code in Generated Code
Place C/C++ code into code generated for a model.
Call external device drivers from generated code.
Apply Function and Operator Code Replacements
Configure the code generator to replace functions and operators for alignment with external code or run-time environment requirements.
Deploy Generated Standalone Executable Programs To Target Hardware
Generate standalone executable programs that do not require an external real-time executive or operating system.
Deploy Generated Component Software to Application Target Platforms
Run an executable program with a target support package for Linux®, Microsoft® Windows®, or Wind River® VxWorks® operating systems.
Build Integrated Code Within the Simulink Environment
Add support files and control model code generation and builds within the Simulink Environment.
Generate Component Source Code for Export to External Code Base
Integrate C/C++ source code, which you generate from a model component, with code developed outside the Simulink® environment.
Generate Shared Library for Export to External Code Base
Build a shared library from a model component and export the library to an application for system simulation, software reuse, or intellectual property protection. Requires an Embedded Coder license.
Exchange Data Between External Calling Code and Generated Code
When you export the generated code into your external code, exchange signal, state, and parameter data.
Integrate External Application Code with Code Generated from PID Controller
Generate code that matches the data interfaces, appearance, and organization of external code.
Build Integrated Code Outside the Simulink Environment
Identify required files and interfaces for calling generated code in an external build process.
How Generated Code Exchanges Data with an Environment
The generated code exchanges signal, state, and parameter data with the calling environment through a data interface.
Control Data and Function Interface in Generated Code
Control how generated code exchanges data with a calling environment.
Design Data Interface by Configuring Inport and Outport Blocks
Customize the data interface of a model to enable integration of the generated code with your own code and to improve code traceability and readability.
Configure Entry-Point Function Interfaces for Simulink Function and Function Caller Blocks
Customize entry-point function names and step function arguments for Simulink Function and Function Caller blocks.
Configure C Code Generation for Model Entry-Point Functions
Learn about generated C entry-point functions, configuration options, and how to interface with them.
Customize Generated C++ Class Interfaces
Use C++ class
code interface packaging to provide C++ class
interfaces to code generated from Simulink models.
Configure Generated Code According to Interface Control Document Interactively
Configure code generation settings for a model according to specifications from an interface control document.
Configure Generated Code According to Interface Control Document
Import specifications from an interface control document and configure code generating settings for a model according to the specifications.
Exchange Data Between External C/C++ Code and Simulink Model or Generated Code
Configure the signals, states, and parameters in a Simulink model to match the data interface of your existing C code.
Exchange Structured and Enumerated Data Between Generated and External Code
Generate code that you can compile together with existing, external code. The bodies of code exchange structured and enumerated data.
Reuse Parameter Data from External Code in the Generated Code
Generate code that imports parameter data from your external code.
Import Parameter Data with Conditionally Compiled Dimension Length
Generate code that imports an array parameter whose dimension lengths your external
code sets with macros (#define
).
Access Structured Data Through a Pointer That External Code Defines
Generate code that accesses parameter data through a structure pointer that handwritten code defines.
Generate Code That Matches Appearance of External Code
Configure how the code generator applies identifiers (symbols), comments, code styles, code format, and organization.
Replace and Rename Data Types to Conform to Coding Standards
Conform to the coding standards of your organization by replacing and renaming
the default Simulink
Coder™ data type aliases, such as real_T
, which the
generated code uses to define data.