使用布尔数据优化逻辑信号生成的代码
通过将逻辑信号存储为布尔数据来优化生成的代码。当您选择模型配置参数将逻辑信号实现为布尔数据(与双精度数据相比)时,生成逻辑信号的模块会输出布尔信号。
优化:
减少 ROM 和 RAM 消耗。
提高执行速度。
示例模型
考虑模型 LogicalAsBoolean
。Relational Operator
、Logical Operator
和 HitCrossing
模块的输出是 double
,即使它们代表逻辑数据。
model = 'LogicalAsBoolean';
open_system(model);
生成代码
编译模型。
slbuild(model)
### Searching for referenced models in model 'LogicalAsBoolean'. ### Total of 1 models to build. ### Starting build procedure for: LogicalAsBoolean ### Successful completion of build procedure for: LogicalAsBoolean Build Summary Top model targets: Model Build Reason Status Build Duration =================================================================================================================== LogicalAsBoolean Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 18.283s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 20.335s
查看未经优化的生成代码。这些代码行在 LogicalAsBoolean.h
中。
hfile = fullfile('LogicalAsBoolean_grt_rtw',... 'LogicalAsBoolean.h'); coder.example.extractLines(hfile,'/* External outputs','/* Parameters (default storage) */',1,0);
/* External outputs (root outports fed by signals with default storage) */ typedef struct { real_T Out1; /* '<Root>/Out1' */ real_T Out2; /* '<Root>/Out2' */ real_T Out3; /* '<Root>/Out3' */ } ExtY_LogicalAsBoolean_T;
启用优化
打开配置参数对话框。
选择将逻辑信号实现为布尔数据(与双精度数据相比)参数。
或者,您可以使用命令行 API 来启用优化:
set_param(model,'BooleanDataType','on');
生成优化代码
生成的代码将逻辑信号输出存储为布尔数据。
编译模型。
slbuild(model)
### Searching for referenced models in model 'LogicalAsBoolean'. ### Total of 1 models to build. ### Starting build procedure for: LogicalAsBoolean ### Successful completion of build procedure for: LogicalAsBoolean Build Summary Top model targets: Model Build Reason Status Build Duration =============================================================================================== LogicalAsBoolean Generated code was out of date. Code generated and compiled. 0h 0m 6.2926s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 6.7386s
查看优化后生成的代码。这些代码行在 LogicalAsBoolean.h
中。
coder.example.extractLines(hfile,'/* External outputs','/* Parameters (default storage) */',1,0);
/* External outputs (root outports fed by signals with default storage) */ typedef struct { boolean_T Out1; /* '<Root>/Out1' */ boolean_T Out2; /* '<Root>/Out2' */ boolean_T Out3; /* '<Root>/Out3' */ } ExtY_LogicalAsBoolean_T;
关闭模型和代码生成报告。
bdclose(model)