| Stateflow User's Guide |
 |
Configuring the Stateflow Blocks in Library Models for Real-Time Workshop
For library models you configure the Stateflow blocks in your model for Real-Time Workshop by configuring a Stateflow RTW target. When the model is built, the configuration for this target is carried into the Simulink RTW configuration and resolved under actual Simulink conditions.
To configure an existing Stateflow RTW target for a library model, do the following:
- From the Stateflow diagram editor Tools menu, select Open RTW Target.
- The Stateflow RTW Target Builder dialog appears, as shown.

- Select one of the following build options:
- Real-Time Workshop build -- to build or rebuild the RTW target.
- Real-Time Workshop options -- to change parameters for your RTW build in Simulink. Once you select this option, the button to the right of this field is renamed RTW Options. Selecting this button displays the Configuration Parameters dialog for Simulink.
- Stateflow Target -- to build only Stateflow code in the RTW target.
- Select Coder Options to specify Stateflow code generation options for the RTW target.
- The RTW Coder Options dialog box appears, as shown.

- Select any or all of the following coder options:
- Comments in generated code -- Include comments in the generated code.
- Use bitsets for storing state configuration -- Use bitsets for storing state configuration variables. This can significantly reduce the amount of memory required to store the variables. However, it can increase the amount of memory required to store target code if the target processor does not include instructions for manipulating bitsets.
- Use bitsets for storing boolean data -- Use bitsets for storing Boolean data. This can significantly reduce the amount of memory required to store Boolean variables. However, it can increase the amount of memory required to store target code if the target processor does not include instructions for manipulating bitsets.
- Compact nested if-else using logical AND/OR operators -- Improves readability of generated code by compacting nested if-else statements using logical AND (
&&) and OR (||) operators.
- Recognize if-elseif-else in nested if-else statements -- Improves readability of generated code by recognizing and emitting an
if-elseif-else construct in place of deeply nested if-else statements.
- Replace constant expressions by a single constant -- Improves readability by preevaluating constant expressions and emitting a single constant. This optimization also opens up opportunities for eliminating dead code.
-
For example, the generated code
becomes
in the first phase of this optimization. The second phase eliminates the if statement, resulting in simply
- Minimize array reads using temporary variables -- In certain microprocessors, global array read operations are more expensive than accessing a temporary variable on stack. Using this option minimizes array reads by using temporary variables when possible.
- Preserve constant data names -- Preserve the names of constant data in generated code. This option is useful when the target contains custom code that accesses Stateflow data.
- Preserve symbol names -- (See note below before using.) Preserve symbol names (names of states and data) in generated code. This option is useful when the target contains custom code that accesses Stateflow data.
- Append symbol names with parent names -- (See note below before using.) Generate a state or data name by appending the name of the item's parent to the item's name.
- Use chart names with no mangling -- (See note below before using.) Preserve the names of chart entry functions so that they can be invoked by user-written C code.
| Note
When you use the options Preserve constant data names, Preserve symbol names, Append symbol names with parent names, or Use chart names with no mangling, the names of symbols in generated code are not mangled to make them unique. Because these options do not check for symbol conflicts in generated code, use them only when your symbol names are unique within the model. Conflicts in generated names cause errors such as variable aliasing and compilation errors.
|
- Select (check) the Use settings for all libraries option if you want the settings that you specify for this target to apply to all the Stateflow charts contributed by library models as well.
- To integrate custom code with Stateflow generated code for the RTW target, select Target Options.
- See Integrating Custom Code with Stateflow Targets for details on using the RTW target to integrate custom code with generated code for the Stateflow diagrams in the model.
- To finish configuring the simulation target, do one of the following:
- Click Apply to apply the selected options.
- Click OK to apply the options and close the dialog.
- Click Build to build the RTW target.
- This creates a new RTW target if one did not previously exist.
| Note
To tell Stateflow to recognize C bitwise operators (~, &, |, ^, >>, and so on) in action language statements and encode them as C bitwise operations, select the Enable C-bit operations property in the Chart Properties dialog.
|
Custom code options are selected through the Target Options button. To specify custom code options for your rtw target, see Integrating Custom Code with Stateflow Targets.
| Note
Configuring an RTW target requires additional steps. See Real-Time Workshop documentation for more information.
|
| Configuring Stateflow Blocks in Nonlibrary Models for Real-Time Workshop | | Configuring a Custom Target in Stateflow |  |
© 1994-2005 The MathWorks, Inc.