主要内容

内联不变信号

在生成的代码中转换不变信号的符号名称

模型配置窗格: 代码生成 / 优化

描述

内联不变信号参数指示代码生成器将不变信号的符号名称转换为常量值。

不变信号是在 Simulink® 仿真期间不发生变化的模块输出信号。例如,在以下模型中,信号 S3 是不变信号。不变信号不变常量不同。两个常量(1 和 2)以及增益值 3 是不变常量。要内联不变常量,请将默认参数行为设置为内联

Model containing two constant blocks that feed into a Sum block. The Sum block output feeds into a gain block, whose output is the signal s3.

类别:优化

依赖项

当您将默认参数行为设置为内联时,将启用此参数。

设置

off (默认) | on
On

Simulink Coder™ 软件在生成的代码中使用模型参数的数值,而不是其符号名称。如果不变信号是非标量复信号,或该信号连接到的模块输入端口采用该信号的地址,则它不是内联信号。

Off

在生成的代码中使用模型参数的符号名称。

示例

全部展开

此示例说明如何使用内联不变信号来优化生成代码。此优化将不变信号的符号名转换为常量值。

InlineInvariantSignals 优化可以:

  • 减少 ROM 和 RAM 消耗量。

  • 提高执行速度。

示例模型

以模型 InvariantSignalsInline 为例。

model = 'InvariantSignalsInline';
open_system(model);

生成代码

使用 Simulink® Coder™ 编译模型。

slbuild(model)
### Searching for referenced models in model 'InvariantSignalsInline'.
### Total of 1 models to build.
### Starting build procedure for: InvariantSignalsInline
### Successful completion of build procedure for: InvariantSignalsInline

Build Summary

Top model targets:

Model                   Build Reason                                         Status                        Build Duration
=========================================================================================================================
InvariantSignalsInline  Information cache folder or artifacts were missing.  Code generated and compiled.  0h 0m 7.5391s

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 8.2049s

查看生成的代码而不进行优化。这些代码行位于 InvariantSignalsInline.c 中。

cfile = fullfile('InvariantSignalsInline_grt_rtw',...
    'InvariantSignalsInline.c');
coder.example.extractLines(cfile,'/* Output and update for atomic system',...
    '/* Model output', 1, 0);
/* Output and update for atomic system: '<Root>/InlinedConstFcn' */
void InvariantSignal_InlinedConstFcn(int32_T rtu_In1,
  B_InlinedConstFcn_InvariantSi_T *localB, const ConstB_InlinedConstFcn_Invari_T
  *localC)
{
  /* Product: '<S1>/Product' */
  localB->Product = rtu_In1 * localC->Sum_p;
}

启用优化

  1. 打开“配置参数”对话框。

  2. 优化窗格上,选择内联不变信号

您也可以使用命令行 API 启用优化:

set_param(model, 'InlineInvariantSignals', 'on');

生成代码并进行优化

生成代码使用折叠常量的数值,而不是创建额外的结构体。

使用 Simulink Coder 编译模型。

slbuild(model)
### Searching for referenced models in model 'InvariantSignalsInline'.
### Total of 1 models to build.
### Starting build procedure for: InvariantSignalsInline
### Successful completion of build procedure for: InvariantSignalsInline

Build Summary

Top model targets:

Model                   Build Reason                     Status                        Build Duration
=====================================================================================================
InvariantSignalsInline  Generated code was out of date.  Code generated and compiled.  0h 0m 6.4573s

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 7.3518s

InvariantSignalsInline.c 中查看优化后的生成代码。

coder.example.extractLines(cfile,...
    '/* Output and update for atomic system', '/* Model output', 1, 0);
/* Output and update for atomic system: '<Root>/InlinedConstFcn' */
void InvariantSignal_InlinedConstFcn(int32_T rtu_In1,
  B_InlinedConstFcn_InvariantSi_T *localB)
{
  /* Product: '<S1>/Product' */
  localB->Product = rtu_In1 << 5;
}

关闭模型和代码生成报告。

bdclose(model)

推荐的设置

应用情形设置
调试Off
可追溯性Off
效率On
安全预警无影响

编程用法

参数:InlineInvariantSignals
类型:字符向量
值:'on' | 'off'
默认值:'off'

版本历史记录

在 R2006a 之前推出