Documentation

External Code Integration

Choose and apply integration paths and methods

The code generator includes a variety of approaches for integrating legacy or custom code with generated code.Legacy codeis existing handwritten code or code for environments that you integrate with code that the code generator produces.Custom codeis legacy code or other user-specified lines of code that you include in the code generator build process. Collectively, legacy and custom code are calledexternal 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.

您可以导出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, seeChoose an External Code Integration Workflow.

Blocks

Model Header Specify external header code
Model Source Specify external source code
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

Topics

开始

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.

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.

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.

Export Generated Code Into External Code

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.

Build Integrated Code Outside the Simulink Environment

Use an external application development environment to build generated code that you integrate with external code.

Control Data and Code Interfaces

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.

Configure Simulink Function Code Interface

Generate code for Simulink functions and function callers.

Control Generation of Function Prototypes

Configure model function prototypes in generated code.

Control Generation of C++ Class Interfaces

UseC++ classcode interface packaging to provide C++ class interfaces to code generated from Simulink models.

Control Generated Code to Match Other Integration Requirements

Generate Code That Matches Appearance of External Code

Configure how the code generator applies identifiers (symbols), comments, code styles, code format, and organization.

Was this topic helpful?