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 Analyze all choices during update diagram and generate preprocessor conditionals check box is selected 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

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