Main Content

Inline Subsystem Code

You can configure a nonvirtual subsystem to inline the subsystem code with the model code. In the Subsystem Parameters dialog box, setting the Function packaging parameter to Auto or Inline inlines the generated code of the subsystem.

The Auto option is the default. When there is only one instance of a subsystem in the model, the Auto option inlines the subsystem code. When multiple instances of a subsystem exist, the Auto option results in a single copy of the function (as a reusable function). For function-call subsystems with multiple callers, the subsystem code is generated as if you specified Nonreusable function.

To inline subsystem code, select Inline. The Inline option explicitly directs the code generator to inline the subsystem unconditionally.

Configure Subsystem to Inline Code

To configure your subsystem for inlining:

  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.

    If the system is already nonvirtual, the Function packaging option is already selected.

  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 its parent system's source file). You can identify this code by system/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 the Inline option is selected.

  • If the subsystem is a function-call subsystem that is called by a noninlined S-function, the Inline option is ignored. Noninlined S-functions make calls by using function pointers. Therefore, the function-call subsystem must generate a function with all arguments present.

  • In a feedback loop involving function-call subsystems, the code generator forces one of the subsystems to be generated as a function instead of inlining it. Based on the order in which the subsystems are sorted internally, the software selects the subsystem to be generated as a function.

  • If a subsystem is called from an S-function block that sets the option SS_OPTION_FORCE_NONINLINED_FCNCALL to TRUE, it is not inlined. When user-defined Async Interrupt blocks or Task Sync blocks are present, this result might occur. Such blocks must be generated as functions. These blocks are located in the vxlib1 block library and use the SS_OPTION_FORCE_NONINLINED_FCNCALL option. This library demonstrates integration with an example RTOS (VxWorks®).[1]


You can use the blocks in the vxlib1 library (Async Interrupt and Task Sync) for simulation and code generation. These blocks provide starting point examples to help you develop custom blocks for your target environment.

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