Real-Time Workshop User's Guide    

Nonvirtual Subsystem Code Generation Options

For any nonvirtual subsystem, you can choose the following code generation options from the RTW system code pop-up menu in the subsystem Block parameters dialog:

The sections below discuss the Auto, Inline, and Function options.

Auto Option

In the current release, the Auto option causes the Real-Time Workshop to inline the subsystem, unless it is a function-call subsystem with multiple callers. In that case, a function is generated.

In a future release, the Auto option will also create functions when multiple instances of a subsystem are detected. If there are multiple instances or multiple callers of the subsystem, the subsystem will not be inlined. To take advantage of this capability, you should choose the Auto option. Choose Inline or Function when you want specifically to inline a subsystem or generate a separate function and code module.

To use the Auto option:

  1. Select the subsystem block. Then select Subsystem parameters from the Simulink Edit menu. The Block Parameters dialog opens, as shown in Figure 3-7.

    Alternatively, you can open the Block Parameters dialog by:

  1. If the subsystem is virtual, select Treat as atomic unit as shown in Figure 3-7. This makes the subsystem nonvirtual, and the RTW system code option becomes enabled.

    If the system is already nonvirtual, the RTW system code option is already enabled.

  1. Select Auto from the RTW system code pop-up menu as shown in Figure 3-7.
  2. Click Apply and close the dialog.

Figure 3-7: Auto Code Generation Option for a Nonvirtual Subsystem

Inline Option

As noted above, subsystem code can be inlined only if the subsystem is nonvirtual.

Exceptions to Inlining.   Note that there are certain cases in which the Real-Time Workshop will not inline a nonvirtual subsystem, even though the Inline option is selected. These cases are:

To generate inlined subsystem code:

  1. Select the subsystem block. Then select Subsystem parameters from the Simulink Edit menu. The Block Parameters dialog opens, as shown in Figure 3-8.

    Alternatively, you can open the Block Parameters dialog by:

  1. If the subsystem is virtual, select Treat as atomic unit as shown in Figure 3-8. This makes the subsystem atomic, and the RTW system code pop-up menu becomes enabled.

    If the system is already nonvirtual, the RTW system code menu is already enabled.

  1. Select Inline from the RTW system code menu as shown in Figure 3-8.
  2. Click Apply and close the dialog.

Figure 3-8: Inlined Code Generation for a Nonvirtual Subsystem

When you generate code from your model, the Real-Time Workshop writes inline code within model.c to perform subsystem computations. You can identify this code by system/block identification tags, such as the following.

See Tracing Generated Code Back to Your Simulink Model for further information on system/block identification tags.

Function Option

This option lets you direct the Real-Time Workshop to generate a separate function and (optionally) a separate file for the subsystem. When you select the Function option, two additional options are enabled:

Figure 3-9 shows the Block Parameters dialog with the Function option selected.

RTW Function Name Options Menu.   This menu offers the following choices:

RTW File Name Options Menu.   This menu offers the following choices:

To generate both a separate subsystem function and a separate file:

  1. Select the subsystem block. Then select Subsystem parameters from the Simulink Edit menu, to open the Block Parameters dialog.

    Alternatively, you can open the Block Parameters dialog by:

  1. If the subsystem is virtual, select Treat as atomic unit as shown in Figure 3-9. This makes the subsystem atomic, and the RTW system code menu becomes enabled.

    If the system is already nonvirtual, the RTW system code menu is already enabled.

  1. Select Function from the RTW system code menu as shown in Figure 3-9.
  2. Set the function name, using the RTW function name options described in RTW Function Name Options Menu.
  3. Set the filename, using any RTW file name option other than Auto (options are described in RTW File Name Options Menu).

    Figure 3-9 shows the use of the UserSpecified filename option.

  1. Click Apply and close the dialog.

Figure 3-9: Subsystem Function Code Generation
with Separate User-Defined File Name


 Nonvirtual Subsystem Code Generation Modularity of Subsystem Code