Main Content

Generate Inlined Subsystem Code

To inline subsystem code with your model code, configure a nonvirtual subsystem. In the Subsystem Parameters dialog box, the Function packaging parameter specifies the format of the subsystem generated code. This parameter has these settings:

  • Auto

  • Inline

  • Nonreusable function

  • Reusable function

The code generator can generate inlined code for the Auto or Inline settings. The inline setting explicitly directs the code generator to inline the subsystem code unconditionally.

The default Auto setting directs the code generator to generate the most efficient code for the subsystem based on the type and number of instances of the subsystem that exist in the model. When there is only one instance of a subsystem, the Auto setting inlines the subsystem code. In Embedded Coder®, when there are multiple instances of a subsystem that are not too complex, the Auto setting inlines the code for each subsystem. Otherwise, the Auto setting generates a single copy of the function (as a reusable function). For a function-call subsystem that has multiple callers, the Auto setting generates subsystem code that is consistent with the Nonreusable function setting.

Configure Subsystem to Inline Code

  1. Right-click the Subsystem block. From the context menu, select Block Parameters (Subsystem).

  2. In the Subsystem Parameters dialog box, if the subsystem is virtual, select Treat as atomic unit. This option makes the subsystem nonvirtual. On the Code Generation tab, the Function packaging option is now available.

  3. Click the Code Generation tab and select Auto or Inline from the Function packaging parameter.

  4. Click Apply and close the dialog box.

    The border of the subsystem thickens, indicating that it is nonvirtual.

When you generate code from your model, the code generator inlines subsystem code within model.c or model.cpp (or in that file's parent system source file). You can identify this code by system and block identification tags, such as:

/* Atomic SubSystem Block: <Root>/AtomicSubsys1 */

Exceptions to Inlining

There are certain cases in which the code generator does not inline a nonvirtual subsystem, even though you select the Inline setting.

  • If a noninlined S-function calls a function-call subsystem, the code generator ignores the Inline setting. Because noninlined S-functions use function pointers to make function calls, the code generator must generate a function with all arguments present.

  • In a feedback loop involving function-call subsystems, the code generator generates a function instead of inlined code for one of the subsystems. Based on the internal, sorted order of the subsystems, the code generator selects which subsystem to generate a function.

  • If an S-function, an Async Interrupt, or a Task Sync block with the option SS_OPTION_FORCE_NONINLINED_FCNCALL set to TRUE calls a subsystem, the code generator generates a function instead of inlined code for the subsystem. The VxWorks® block library (vxlib1) contains the user-defined Async Interrupt and Task Sync blocks.[1]

The Function packaging parameter is disabled in Simulink Function blocks.

See Also

[1] VxWorks is a registered trademark of Wind River® Systems, Inc.