示例模型
模型 rtwdemo_reusable_csc 包含不可重用的子系统 DeltaSubsystem 和 MATLAB Function 模块 Downsample。DeltaSubsystem 包含 MATLAB Function 模块 DeltaX 和 DeltaY。
model ='rtwdemo_reusable_csc';
open_system(model);
配置 Simulink 信号对象以实现重用
在 Apps 库中,在 Code generation 下,点击 Embedded Coder。C Code 选项卡将打开。
要打开 Code Mappings 编辑器,请点击 Code Interface > Individual Element Code Mappings。
在模型中,选择 RCSC_REAL 信号线。要在 Code Mappings 编辑器中查看此信号或任何信号,请在 Signals/States 选项卡上,点击 Add selected signals to code mappings 按钮。
对于表示信号线的行,检查 Storage Class 列。信号对象使用存储类 Reusable,这意味着该对象作为名为 RCSC_REAL 的全局变量出现在生成的代码中。
在模型中,导航到 DeltaSubsystem 子系统中。
在该子系统中选择 RCSC_REAL 信号线。此信号也解析为基础工作区中的信号对象。
使用 Reusable 存储类时,生成的代码可以将 Complex to Real-Imag 模块(在模型的根级别)的输出和 DeltaX 模块(在子系统中)的输出存储在 RCSC_REAL 全局变量中。
生成代码
编译模型。
currentDir = pwd;
[~,cgDir] = rtwdemodir();
rtwbuild(model);
### Starting build procedure for: rtwdemo_reusable_csc
### Successful completion of build procedure for: rtwdemo_reusable_csc
Build Summary
Top model targets built:
Model Action Rebuild Reason
=====================================================================================================
rtwdemo_reusable_csc Code generated and compiled Code generation information file does not exist.
1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 24.041s
对于缓冲区重用,rtwdemo_reusable_csc.c 文件包含以下全局变量:
static real_T RCSC_IMAG[1048