Variant Systems with Conditional Systems

You can use the conditionally executed systems (control ports) such as Enable, Trigger, Reset, and the Function-Call Subsystems within the Variant Subsystem block. When the Variant activation time parameter is set to code compile in the Block Parameters dialog box, a mix of control ports in a Variant Subsystem block as variant choice is not supported. Also, all control port types must have the same names. For more information on conditionally executed systems, see Conditionally Executed Subsystems Overview.

Export-Function Model with Variant Subsystem

Consider a Variant model containing a Variant Subsystem block. If you use Function-Call system as a variant choice for the Linear Subsystem block then the other Subsystem block (Nonlinear) within the Variant Subsystem block must also be Function-Call system. Additionally, the control ports in Linear and Nonlinear blocks and the corresponding inport block must have the same name (fcn).

In the generated code, the code inside fcn definition is guarded by C preprocessor conditionals inside export function.

fcn() {
#if VSSMODE==0
// code for Linear choice
.......
#endif 
#if VSSMODE==1
// code for Nonlinear choice
.......
#endif 

You can also have a similar modeling pattern with multi-point entry function using Model block. An example is as follows:

In the above example, fcln1, fcln2, and fcln3 are routed through the Variant Subsystem using Model blocks as variant choices.

These conditions are not supported when using conditionally executed systems within a Variant Subsystem block as variant choice:

  • Action ports as Variant choices

  • Variant choices containing Iterator port with generate preprocessor conditionals set to ON

  • Models with Initialize, Reset, Terminate, and Simulink functions

    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.

Variant Subsystem with Enable Subsystem as Choice

Consider a Variant model containing a Variant Subsystem block. If you use Enable Subsystem as a variant choice for the Linear Subsystem block then the other Subsystem block (Nonlinear) within the Variant Subsystem block must also be Enable Subsystem.

This model simulates and generates code based on VSSMODE value.

Snippet of the generated code is as shown below.

step() {
#if VSSMODE==0
// code for Linear choice
.......
#elif VSSMODE==1
// code for Nonlinear choice
.......
#endif

Related Topics