Stateflow | ![]() ![]() |
Overview
A target is a program that executes a Stateflow model or a Simulink model containing a Stateflow state machine. Stateflow and companion tools can build targets for virtually any computer.
Target Types
Simulink and its companion tools can build the following types of targets:
A simulation target is a compiled Simulink S-function (MEX file) that enables Simulink to simulate a Stateflow model. See Parsing for more information.
An RTW target is an executable program that implements a Simulink model. The model represented by an RTW target can include non-Stateflow as well as Stateflow blocks. An RTW target can also run on computers that do not have a floating-point instruction set. Building an RTW target requires the Real-Time Workshop and Stateflow Coder.
Building a Target
Building a target involves the following steps:
See Configuring a Target for more information. You need to perform this step only if you are building a stand-alone or RTW target or are including custom code in the target. See "Building Custom Code into the Target" on page 9-3.
Stateflow automatically builds or rebuilds simulation targets, when you initiate simulation of a state machine. You must explicitly initiate the build process for other types of targets. See Starting a Build for more information.
Configuring and building a target requires a basic understanding of how Stateflow builds targets, in the case of simulation and stand-alone targets, and how Real-Time Workshop builds targets, in the case of RTW targets. See How Stateflow Builds Targets for information on how Stateflow builds targets. Real-Time Workshop uses basically the same process for building targets that contain state machines as it uses for building targets that do not. See the Real-Time Workshop User's Guide for information on how Real-Time Workshop builds targets.
Rebuilding a Target
You can rebuild a target at any time by repeating step 2. When rebuilding a target, Stateflow rebuilds only those parts corresponding to charts that have changed logically since the last build. When rebuilding a target, you need to perform step 1 only if you want to change the target's custom code or configuration.
Building Custom Code into the Target
You can configure the target build process to include to build custom code, that is, C code supplied by you, into the target (see Specifying Custom Code Options). This capability facilitates creation of applications that integrate Stateflow state machines. In particular, it allows you to use Stateflow or Real-Time Workshop to build the entire application, including both the portions that you supply and the state machine target code generated by Stateflow (or by Real-Time Workshop and Stateflow, when building applications that include other types of Simulink blocks).
How Stateflow Builds Targets
Stateflow builds a target for a particular state machine as follows. It begins by parsing the charts that represent the state machine to ensure that the machine's logic is valid. If any errors occur, Stateflow displays the errors in the MATLAB command window (see Parsing) and halts.
If the charts parse, Stateflow next invokes a code generator to convert the state machine into C source code. The code generator accepts various options that control the code generation process. You can specify these options via the Stateflow user interface (see Adding a Target to a State Machine's Target List).
The code generator also generates a makefile to build the generated source code into an executable program. The generated makefile can optionally build custom code that you specify into the target (see Specifying Custom Code Options).
Finally Stateflow builds the target, using a C compiler and make utility that you specify (see Setting Up Target Build Tools for more information).
![]() | Semantic Rules Summary | Setting Up Target Build Tools | ![]() |