Main Content

本页的翻译已过时。点击此处可查看最新英文版本。

代码集成

选择并应用集成路径和方法

代码生成器提供了多种方法,可将现有代码或自定义代码与生成的代码集成。现有代码是指现有的人工代码,或者要与代码生成器生成的代码进行集成的环境中的代码。自定义代码是指您在代码生成器的编译过程中包含的现有代码或其他由用户指定的代码行。现有代码和自定义代码统称为外部代码

要集成外部代码,您可以将现有外部代码导入到代码生成器生成的代码中、将生成的代码导出到现有外部代码库中,或者同时执行以上两种操作。例如,您可以通过调用外部函数或使用代码继承工具导入代码,或者在模型中包含 Custom Code 模块,从而将外部代码放置在生成的代码中的特定位置。导入外部代码时,生成的代码将与生成的调度代码进行对接。

您可以将生成的代码作为插件函数导出,以便在外部开发环境中使用。导出生成的代码时,您需要手动将该代码与您应用程序运行时环境中的调度机制进行对接。

要了解如何根据您的应用程序要求选择方法的指导原则,请参阅Choose an External Code Integration Workflow

模块

全部展开

Model HeaderSpecify external header code
Model SourceSpecify external source code
System DerivativesSpecify external system derivative code
System DisableSpecify external system disable code
System EnableSpecify external system enable code
System InitializeSpecify external system initialization code
System OutputsSpecify external system outputs code
System StartSpecify external system startup code
System TerminateSpecify external system termination code
System UpdateSpecify external system update code

主题

快速入门

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.

将外部代码导入到生成的代码中

调用可重用的外部算法代码进行仿真和代码生成

从生成的代码中调用外部算法代码,该代码独立于硬件并可重用。

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.

在 Simulink 环境中编译集成的代码

在 Simulink 环境中添加支持文件和控制模型代码生成与编译。

将生成的代码导出到外部代码中

生成要导出到外部代码库的组件源代码

将从模型组件生成的 C/C++ 源代码与在 Simulink® 环境之外开发的代码集成在一起。

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.

在 Simulink 环境之外编译集成的代码

标识在外部编译过程中调用生成的代码所需的文件和接口。

控制数据和代码接口

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.

为模型入口函数配置 C 代码生成

了解生成的 C 入口函数、配置选项以及如何与它们对接。

Configure Generated Code According to Interface Control Document Specifications

Configure code generation settings for a model according to specifications from an interface control document.

数据布局和存储

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.

Generate C++ Class Interface to Model or Subsystem Code

Generate a C++ class interface to code generated from a model or subsystem.

Generate Code for String Blocks by using the Standard C++ String Library

Generate C++ code for Simulink string blocks.