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. You can import code by calling an external function, by using C Function blocks, C Caller blocks, or S-functions. To place external code at specific locations in generated code, you can include Custom Code blocks in a model or use model configuration parameters in the Custom pane. 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.
Blocks
Topics
Workflow Overview
- 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 Hardware-Independent External 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. - 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. - Call External Device Drivers
Call external device drivers from generated code. - Integrate External Code with Stateflow Charts
Use Stateflow® charts to integrate external code with generated code. - Build Integrated Code Within the Simulink Environment
Add support files and control model code generation and builds within the Simulink Environment.