外部代码集成
选择并应用集成路径和方法
代码生成器提供了多种方法,可将现有代码或自定义代码与生成的代码集成。现有代码是指现有的人工代码,或者要与代码生成器生成的代码进行集成的环境中的代码。自定义代码是指您在代码生成器的编译过程中包含的现有代码或其他由用户指定的代码行。现有代码和自定义代码统称为外部代码。
要集成外部代码,您可以将现有外部代码导入到代码生成器生成的代码中、将生成的代码导出到现有外部代码库中,或者同时执行以上两种操作。例如,您可以通过调用外部函数或使用代码继承工具导入代码,或者在模型中包含 Custom Code 模块,从而将外部代码放置在生成的代码中的特定位置。导入外部代码时,生成的代码将与生成的调度代码进行对接。
您可以将生成的代码作为插件函数导出,以便在外部开发环境中使用。导出生成的代码时,您需要手动将该代码与您应用程序运行时环境中的调度机制进行对接。
要了解如何根据应用程序要求选择方法的指导原则,请参阅Choose an External Code Integration Workflow。
模块
主题
快速入门
- 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.
将外部代码导入到生成的代码中
- 调用可重用的外部算法代码进行仿真和代码生成
从生成的代码中调用外部算法代码,该代码独立于硬件并可重用。 - Place External C/C++ Code in Generated Code
Place C/C++ code into code generated for a model. - 集成外部 C++ 对象方法
通过使用代码继承工具,集成已有的 C++ 对象方法。 - 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. - 在 Simulink 环境中编译集成的代码
在 Simulink 环境中添加支持文件和控制模型代码生成与编译。
控制数据和代码接口
- 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 Data Between External Calling Code and Generated Code
When you export the generated code into your external code, exchange signal, state, and parameter data. - 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.
控制生成的代码以满足其他集成要求
- Generate Code That Matches Appearance of External Code
Configure how the code generator applies identifiers (symbols), comments, code styles, code format, and organization.