| Stateflow User's Guide |
 |
Specifying Custom Code Options for Stateflow Targets
You include custom code in Stateflow simulation, RTW, and custom targets in the tabbed option pages of the Stateflow Target Options dialog. Use the following procedure to specify configuration options to build custom code into a Stateflow target:
- Open the Target Builder dialog for the Stateflow simulation, RTW, or custom target as described in the following sections:
- You do this when you configure one of the targets as described in the following topics:
You also access the Target Builder dialog for an RTW or custom target when you first create it. See Adding a Stateflow Target for instructions.
- In the Target Builder dialog, select the Target Options button.
- The Target Options dialog appears, as shown:
- Specify your custom code in the edit boxes of the following tabbed pages of the Target Options dialog:
- Include Code -- Enter code lines (for example,
#include test.h) to include at the top of a generated header file that declares custom functions and data used by the generated code. These code lines are included at the top of all generated source code files and are visible to all generated code.
-
Since the code specified in this option is included in multiple source files that are linked into a single binary, there are some limitations on what you can and cannot include. For example, you should not include a global variable definition such as int x; or a function body such as
These code lines cause linking errors because their symbols are defined multiple times in the source files of the generated code. You can, however, include extern declarations of variables or functions such as
extern int x; or extern void myfun(void);.
- Include Paths -- Enter a space-separated list of the directory paths that contain custom header files to be included either directly (see Include Code option) or indirectly in the compiled target. See Specifying Relative Paths for Custom Code for instructions on entering directory path names.
- Source Files -- Enter a list of source files to be compiled and linked into the target. You can separate source files with either a comma, a space, or a new line. See Specifying Relative Paths for Custom Code for instructions on entering directory path names.
- Libraries -- Enter a space-separated list of static libraries containing custom object code to be linked into the target. See Specifying Relative Paths for Custom Code for instructions on entering directory path names.
- Generated Code Directory -- For custom targets you can specify an optional directory to receive the generated code.
- Initialization Code -- Code statements that are executed once at the start of simulation. You can use this initialization code to invoke functions that allocate memory or perform other initializations of your custom code. This option does not apply to custom targets.
- Termination Code -- Enter code statements that are executed at the end of simulation. You can use this code to invoke functions that free memory allocated by the custom code or perform other cleanup tasks. This option does not apply to custom targets.
- Reserved Names -- Sometimes the names of variables and functions in Stateflow generated code matches the names of variables or functions specified in custom code. When this occurs, the compiler reports a "redeclaration" or "redefinition" of the variable or function name. When you encounter an error like this, enter the name that causes this conflict. Stateflow changes the name in its generated code.
- Click Apply to apply the specification to the target or OK to apply the specifications and close the dialog.
- If you make a change in one of your custom code options, to force the target rebuild to incorporate your changes you must either change one of the charts slightly (this forces a rebuild when you simulate again) or go to the Simulation Target Builder dialog box and select the Rebuild All option.
References
For additional information on specifying custom code for your target, see the following online articles:
| Integrating Custom Code with Stateflow Targets | | Specifying Relative Paths for Custom Code |  |
© 1994-2005 The MathWorks, Inc.