主要内容

本页翻译不是最新的。点击此处可查看最新英文版本。

模型配置集自定义

自定义代码生成器生成代码的方式

模型配置集包含控制代码生成器如何从模型生成代码的参数。要控制生成代码的代码优化、接口、代码样式、编译选项和其他方面,请使用配置参数。当您要对许多模型使用相同的设置时,可以在这些模型之间共享同一个配置集。您还可以使用脚本以编程方式配置模型的代码生成。

模型设置

全部展开

目标选择

系统目标文件控制编译过程的代码生成阶段的文件
语言生成代码的编程语言
语言标准Language standard supported by compiler

编译过程

仅生成代码生成代码与可执行程序
工具链编译可执行程序或库时使用的工具链
工具链详细信息Baseline toolchain settings
代码和工件打包在 ZIP 文件中打包生成的代码和工件
编译配置Build configuration defined by toolchain
编译器优化级别Control application of compiler optimizations
自定义编译器优化标志编译器优化标志
生成联编文件启用生成联编文件以用于编译生成的代码
make 命令Make command and options for initiating build process
模板联编文件用于为指定的系统目标文件生成联编文件的模板联编文件

代码生成目标

选择目标Code generation objective
生成代码前检查模型Choose whether to run Code Generation Advisor checks

高级

内置 FFTW 库回调Use built-in callback for FFTW library usage (自 R2023a 起)
自定义 FFT 库回调Callback for custom FFT library usage
自定义 BLAS 库回调Callback for custom BLAS library usage
自定义 LAPACK 库回调Callback for custom LAPACK library usage
详尽编译启用编译过程阶段和编译器输出的显示
保留 .rtw 文件保留生成的 model.rtw 文件
探查 TLC对用于为模型生成代码的 TLC 文件执行探查
启用 TLC 断言Produce TLC stack trace
生成代码时启动 TLC 覆盖率报告Log coverage of TLC code during code generation
生成代码时启动 TLC 调试器During code generation, start TLC debugger
Zip 文件名ZIP 文件的名称
MATLAB 函数中的大型常量生成Whether to write large deep learning constants to binary data files (自 R2024a 起)
MATLAB 函数中的大型常量阈值(字节)Threshold above which the code generator writes DNN constants to binary data files (自 R2024a 起)
在 Simulink 工具条中显示自定义硬件 AppShow Custom Hardware App in Simulink Toolstrip
在 Simulink 工具条中显示嵌入式硬件 AppShow Embedded Hardware App in Simulink Toolstrip
默认参数行为在生成的代码中表示数值模块参数
使用 memcpy 进行向量赋值Optimize code generated for vector assignments
Memcpy 阈值(字节)Specify minimum array size for which memcpy and memset function calls replace for loops for vector assignments
循环展开阈值 Specify minimum array size width for generating for loops
最大堆栈大小(字节)指定模型中局部变量的最大堆栈大小
内联不变信号在生成的代码中转换不变信号的符号名称
信号存储重用重用信号内存
启用局部模块输出以局部或全局方式声明模块信号
重用局部模块输出重用局部输出变量
消除多余的局部变量(表达式折叠)指定将表达式折叠成单个表达式
使用 memset 将浮点数和双精度值初始化为 0.0Control generation of code that explicitly initializes floating-point data to 0.0
删除涉及饱和处理的从浮点数到整数转换中将 NaN 映射至零的代码Control generation of protective code that handles floating-point to integer conversion for NaN values
删除从浮点数到整数转换中将超出范围值绕回的代码Control generation of wrapping code that handles out-of-range floating-point to integer conversion values
可重用子系统的缓冲区Buffers to enhance reuse of subsystems
使用位集来存储状态配置Bitsets for storing state configuration variables
使用位集来存储布尔数据Bitsets to store Boolean data
自动创建的枚举的基本存储类型Specify storage type and size of enumerations for state outputs
创建代码生成报告Document generated code in an HTML report
自动打开报告Display code generation reports automatically
包括注释在生成的代码中包括注释
Simulink 模块注释包括 Simulink 模块注释
Stateflow 对象注释包含 Stateflow 对象注释
MATLAB 源代码作为注释包括 MATLAB 源代码作为注释
显示已消除模块包含已消除代码块的注释
为 '模型默认' 存储类提供详尽注释Reduce code size or improve code traceability
最大标识符长度指定标识符中的最大字符数
使用与仿真目标相同的保留名称指定是否使用“仿真目标”窗格中的保留名称
保留名称Avoid name conflicts with custom code
头文件防卫式声明前缀要前追加到生成的头文件防卫式声明的自定义文本 (自 R2024a 起)
重复的枚举成员名称Specify the action to take if the code generator detects two enumeration types with same member names
使用与仿真目标相同的自定义代码设置使用“仿真目标”>“自定义代码”窗格中的自定义代码设置
包含头文件在生成的模型头文件中包含自定义代码
包含目录将文件夹添加到包含路径
源文件用生成的代码编译和链接其他源文件
用生成的代码链接附加库
定义向编译器命令行添加预处理器宏定义
初始化代码在生成的模型初始化函数中包含自定义代码
终止代码在生成的模型终止函数中包含自定义代码
其他代码在生成的模型源文件中包含自定义代码

软件环境

代码替换库定义特定目标环境的代码优化的库
共享代码放置共享的生成代码的位置
支持: 非有限数非有限数据的代码生成

代码接口

代码接口打包(组件)Package generated code interface as reusable or nonreusable functions or as a C++ class
代码接口打包(子组件)Package generated code interface for model subcomponent as reusable or nonreusable functions or as a C++ class (自 R2025a 起)
多实例代码错误诊断Severity level of diagnostics for when model violates requirements for generating multi-instance code

数据交换接口

数组布局代码生成器对数组数据使用的布局(列优先或行优先)
外部函数的行优先代码生成兼容性Diagnostic action for functions that use multidimensional arrays and do not specify array layout
生成用于信号的 C API为信号结构体中的信号生成 C API 接口代码
生成用于参数的 C API为参数结构体中的可调参数生成的 C API 接口代码
生成用于状态的 C API为状态结构体中的状态生成的 C API 接口代码
生成用于根级 I/O 的 C APIGenerated C API interface code for root-level inports and outports in root-level I/O structure
外部模式生成的外部模式数据接口
传输层Transport protocol for external mode communication
MEX 文件参量Arguments to pass to external mode interface MEX-file
静态内存分配Dynamic or static memory allocation for external mode communication
静态内存缓冲区大小Size of static memory buffer for external mode communication
自动分配静态内存Automatic static memory buffer allocation for external model communication (自 R2022b 起)
最大持续时间Maximum number of base rate steps for which external mode logs data after trigger event (自 R2022b 起)
将信号记录到 MDF 文件Log signal and output data from generated code to MDF file (自 R2024a 起)

深度学习

目标库Deep learning library to use during code generation for target environment
可学习参数压缩压缩类型,指定为 "none""bfloat16" (自 R2023b 起)
ARM Compute Library 版本Version of ARM Compute Library to use during code generation
ARM Compute Library 架构ARM architecture supported by target hardware
自动调整Code generation that uses cuDNN library with auto tuning enabled (自 R2021a 起)

高级参数

最大字长Maximum word length for generated multiword type definitions
动态大小字符串的缓冲区大小(以字节为单位)具有动态字符串数据类型的信号的缓冲区大小
生成完整文件前注Include code generation information in file banner
单一输出/更新函数Execution entry-point function that includes code for output and update functions
MAT 文件记录导出的数据保存在 MAT 文件中
不生成定点字长检查控制是否生成用来执行定点字长检查的预处理器指令 (自 R2024a 起)
等间距设定的 LUT 对象结构体顺序Order of fields in structure generated for lookup table object with even spacing breakpoint specification
显式值设定的 LUT 对象结构体顺序Order of fields in structure generated for lookup table object with explicit values breakpoint specification
动态大小字符串的缓冲区大小(以字节为单位)具有动态字符串数据类型的信号的缓冲区大小
外部函数的行优先代码生成兼容性Diagnostic action for functions that use multidimensional arrays and do not specify array layout
从 slrealtime 派生的目标Indicates whether or not the currently selected target is derived from the slrealtime target (自 R2022b 起)

主题

代码生成配置集

模型配置参数:代码生成

代码注释

标识符

  • Construction of Generated Identifiers
    For generic real-time (GRT) and rapid simulation (RSim) targets, the code generator automatically constructs identifiers for variables and functions in the generated code.
  • 保留关键字
    如果使用代码生成器生成 C 或 C++ 代码,模型中不能包含为内部使用保留的关键字。

精选示例