主要内容

使用有条件执行的子系统的变体子系统块

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控制器和两个启用子系统块,LinearNonlinear作为变体选择。变体条件LinearNonlinearblocks areVSSMODE==0VSSMODE==1, 分别。如果你使用启用子系统block for theLinear选择,然后Nonlinearchoice must also be an启用子系统.

When you generate code from this model, theLinearNonlinear选择是通过相应的变体条件保护的。

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块,LinearNonlinear作为变体选择。这variant conditions set onLinearNonlinear选择是vss_mode == 0.vss_mode == 1, 分别。这Variantfcncall.块有一个根级函数调用Inport块,FCN., 和the same name is given to the control ports on theLinearNonlinear选择块。这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 forLinearNonlinear选择是通过相应的变体条件保护的。有关配置模型以生成代码的详细信息,请参阅用于代码生成准备含有变体的模型.

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==1is 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 theIn1Out1blocks 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 tocode 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.

相关话题