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 .
|System Derivatives||Specify external system derivative code|
|System Disable||Specify external system disable code|
|System Enable||Specify external system enable code|
|System Initialize||Specify external system initialization code|
|System Outputs||Specify external system outputs code|
|System Start||Specify external system startup code|
|System Terminate||Specify external system termination code|
|System Update||Specify external system update code|
What external code integration is.
For application integration points, characterize external code, identify code generation integration requirements, and choose a workflow.
Examples that show scenarios of external code integration with the Legacy Code Tool.
Use of untrusted custom code entails risk.
Call external algorithmic code, which is hardware-independent and reusable, from generated code.
Place C/C++ code into code generated for a model.
Call external device drivers from generated code.
Configure the code generator to replace functions and operators for alignment with external code or run-time environment requirements.
Generate standalone executable programs that do not require an external real-time executive or operating system.
Run an executable program with a target support package for Linux®, Microsoft® Windows®, or Wind River® VxWorks® operating systems.
Add support files and control model code generation and builds within the Simulink Environment.
Integrate C/C++ source code, which you generate from a model component, with code developed outside the Simulink® environment.
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.
When you export the generated code into your external code, exchange signal, state, and parameter data.
Generate code that matches the data interfaces, appearance, and organization of external code.
Identify required files and interfaces for calling generated code in an external build process.
The generated code exchanges signal, state, and parameter data with the calling environment through a data interface.
Control how generated code exchanges data with a calling environment.
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.
Customize entry-point function names and step function arguments for Simulink Function and Function Caller blocks.
Learn about generated C entry-point functions, configuration options, and how to interface with them.
C++ class code interface packaging to provide C++ class
interfaces to code generated from Simulink models.
Configure code generation settings for a model according to specifications from an interface control document.
Import specifications from an interface control document and configure code generating settings for a model according to the specifications.
Configure the signals, states, and parameters in a Simulink model to match the data interface of your existing C code.
Generate code that you can compile together with existing, external code. The bodies of code exchange structured and enumerated data.
Generate code that imports parameter data from your external code.
Generate code that imports an array parameter whose dimension lengths your external
code sets with macros (
Generate code that accesses parameter data through a structure pointer that handwritten code defines.
Configure how the code generator applies identifiers (symbols), comments, code styles, code format, and organization.
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.