| Using Stateflow | Search  Help Desk |
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.
A stand-alone target is an executable program that enables a specific type of computer (the target machine) to execute a Stateflow model. The target can be built to run on computers that do not have a floating-point instruction set, a feature useful in embedded control applications. A stand-alone target does not require Simulink to run. Building a stand-alone target requires Stateflow Coder.
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:..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 is a MATLAB M-file, namedsfc.m, that translates a Stateflow state diagram into an equivalent C source code representation. The code generator accepts various command-line 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").
In the case of stand-alone targets, the code generator optionally generates a main program that exercises each of the state machine's charts. If you do not select this option, you must provide the main program for the stand-alone target. See "Creating a Target Main Program" for more information. (Simulink serves as the main program for a simulation target. Hence, you do not need to provide a main program for a simulation target.)
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).