Stateflow |
 |
Specifying Custom Code Options
You specify configuration options to build custom code into a target with the following procedure:
- Open the Target Builder dialog box.
- See Accessing the Target Builder Dialog for a Target for instructions on how to access this dialog.
- Select the Target Options button.
- The Target Options dialog appears similar to the following:
The Target Options dialog box identifies the target in its window title and contains a drop-down list of options for specifying the code to include in the target and where the code is located. Use the edit box following the list to add, change, and display custom code that you enter for the current option.
- Select any or all of the following options required to specify your code and specify them in the edit box:
- Custom code included at the top of generated code -- Custom C code to be included at the top of a generated header file that is included at the top of all generated source code files. In other words, all generated code sees code specified by this option. Use this option to include header files that declare custom functions and data used by generated code.
-
Since the code specified in the Custom code included at the top of generated code 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 global variable definitions or function bodies, such as int x
or void myfun(void) {...}
,
through this property.
This causes linking errors because these 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)
.
- Custom include directory paths -- Space-separated list of paths of directories containing custom header files to be included either directly (see previous option) or indirectly in the compiled target. See Specifying Path Names in Custom Code Options for instructions on entering the included directory path names.
- Custom source files -- 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 Path Names in Custom Code Options for instructions on entering the included directory path names.
- Custom libraries -- Space-separated list of libraries containing custom object code to be linked into the target. See Specifying Path Names in Custom Code Options for instructions on entering the included directory path names.
- Custom 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.
- Custom termination code -- Code statements that are executed at the end of simulation. You can use this code to invoke functions that free memory allocated by custom code or perform other cleanup tasks.
- Code Generation Directory -- For custom targets you can specify an optional directory to receive the 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 rebuild of the S-function 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 Diagrams | | Specifying Path Names in Custom Code Options |  |