使用有条件执行的子系统的变体子系统块
You can use conditionally executed subsystems that use control input ports such asEnabled,Triggered,重置, 和theFunction-Call子系统作为变体选择变体子系统堵塞。有关有条件执行的系统的更多信息,请参阅有条件地执行的子系统概述.
Note
当。。。的时候Variant activation time参数的变体子系统block is set tocode compile
,所有变体选项中的控制端口块类型必须相同。例如,您无法使用启用子系统和Function-Call Subsystemblocks as choices within a变体子系统块有code compile
激活时间。
变体选择块上的控制输入端口和父级上的相应输入端口变体子系统block must have the same name.
创建一个具有启用子系统的变体子系统作为选择
考虑这个模型变体子系统block named控制器
和两个启用子系统块,Linear
和Nonlinear
作为变体选择。变体条件Linear
和Nonlinear
blocks areVSSMODE==0
和VSSMODE==1
, 分别。如果你使用启用子系统block for theLinear
选择,然后Nonlinear
choice must also be an启用子系统.
When you generate code from this model, theLinear
和Nonlinear
选择是通过相应的变体条件保护的。
step() { #if VSSMODE==0 // code for Linear choice ....... #elif VSSMODE==1 // code for Nonlinear choice ....... #endif
使用Variant Subsystem块创建导出功能模型
Export-function models are Simulink®为可以与外部环境和调度程序集成的独立函数生成代码的模型。你可以使用一个变体子系统块Function-Call Subsystemblocks as variant choices to create an export-function model. For more information on export-function models, seeExport-Function Models Overview.
Consider a model containing a变体子系统block namedVariantfcncall.
with twoFunction-Call Subsystem块,Linear
和Nonlinear
作为变体选择。这variant conditions set onLinear
和Nonlinear
选择是vss_mode == 0.
和vss_mode == 1
, 分别。这Variantfcncall.
块有一个根级函数调用Inport块,FCN.
, 和the same name is given to the control ports on theLinear
和Nonlinear
选择块。这Variant activation time参数Variantfcncall.
被设定为code compile
.
您还可以使用类似的建模模式,使用多点输入功能模型块。
In this example, the inputsfcln1
,fcln2
, 和fcln3
通过一个变体子系统block,模型
,使用模型blocks as variant choices.
Code Generation for Export-Function Model
When you generate code from this model, the definition of the export function,FCN.
, contains theC
预处理器条件#if
和#万一
. The code forLinear
和Nonlinear
选择是通过相应的变体条件保护的。有关配置模型以生成代码的详细信息,请参阅用于代码生成准备含有变体的模型.
void fcn(void) { /* RootInportFunctionCallGenerator: '/RootFcnCall_InsertedFor_fcn_at_outport_1' */ #if VSSMODE == 0 rtDWork.Linear.DiscreteFilter = rtU.In1 - 0.5 * rtDWork.Linear.DiscreteFilter_states; rtDWork.Linear.DiscreteFilter_states = rtDWork.Linear.DiscreteFilter; #endif /* VSSMODE == 0 */ #if VSSMODE == 1 rtDWork.Nonlinear.DiscreteFilter = look1_binlxpw(rtU.In1, rtCP_LookupTable_bp01Data, rtCP_LookupTable_tableData, 4U) - 0.5 * rtDWork.Nonlinear.DiscreteFilter_states; rtDWork.Nonlinear.DiscreteFilter_states = rtDWork.Nonlinear.DiscreteFilter; #endif /* VSSMODE == 1 */ #if VSSMODE == 0 rtY.Out1 = rtDWork.Linear.DiscreteFilter; #endif /* VSSMODE == 0 */ #if VSSMODE == 1 rtY.Out1 = rtDWork.Nonlinear.DiscreteFilter; #endif /* VSSMODE == 1 */ }
生成代码中的保护函数定义
保护整个expor的定义t function,FCN.
, using a variant condition, use a变体源block as shown in this example.
In the generated code, the definition of the export function,FCN()
, is guarded withA==1
.
#if A == 1 void fcn(void) { ….. } #endif
This function can be referred using a code snippet similar to this one.
...... #if a == 1 fcn()#endif ......
Propagate Variant Conditions from Variant Subsystem Blocks to Conditional Subsystems
将变体条件传播到条件子系统时,对所有端口设置相同的条件。
Consider this model. The变体子系统block,Variantfcncall.
,有条件子系统块作为选择。inport.FCN.
在Variantfcncall.
corresponds to the control input ports on the variant choice blocks. A single-input, single-output变体源块the conditionA==1
is connected to theFCN.
港口。这Variantfcncall.
block gets the variant condition of the signal connected to theFCN.
港口。分配给块的条件然后传播到连接到其输入和输出端口的块。设置后模拟此模型A = 1
, the variant conditionA==1
传播到Variantfcncall.
block and to theIn1
和Out1
blocks connected to it, as shown in the Variant Conditions Legend.
限制
在使用条件执行的系统作为变体选择时,不支持这些条件金宝app变体子系统block:
Action Portblocks in the variant choices.
迭代器港口blocks in the variant choices of a变体子系统withVariant activation timeset to
code compile
.将模型配置为AutoSAR组件,其可作为变体子系统选择。
初始化功能,重置Function,Terminate Function, 和Simulink Function块。
Note
Initialize and Terminate event ports are always unconditional because they control both the model default and block-specific initialize and terminate events of the referenced model. If you define an Initialize function block in the referenced model, it corresponds to an explicit initialize event.