External Code Import
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. 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.
For guidance on choosing an approach based on your application requirements, see Choose an External Code Integration Workflow .
Place Code in Generated Header and Source Files
Place Code in Generated System Functions
|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|
- Choose an External Code Integration Workflow
For application integration points, characterize external code, identify code generation integration requirements, and choose a workflow.
- Untrusted Custom Code, Custom Targets, and Callbacks
Use of untrusted custom code entails risk.
Import External Code Into Generated Code
- 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
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.
- Build Integrated Code Within the Simulink Environment
Add support files and control model code generation and builds within the Simulink Environment.
- External Code Integration Examples
Examples that show scenarios of external code integration with the Legacy Code Tool.