|On this page…|
If you have a Simulink® model named mainModel, which contains two Stateflow® blocks named chart1 and chart2, you have a machine named mainModel that parents two charts named chart1 and chart2.
When you simulate the Stateflow chart for mainModel, you generate code for mainModel that compiles into an S-function MEX-file. MEX-file extensions are platform-specific, as described in the MATLAB® software documentation. For example, on 32-bit Windows® PC platforms, you generate a MEX-file for mainModel named mainModel_sfun.mexw32. On Linux® x86-64 platforms, you generate mainModel_sfun.mexa64.
S-function MEX files appear in the current MATLAB folder. You can change this location at the MATLAB command prompt with a cd command.
Most of the code files that you generate reside in a subfolder of the current MATLAB folder. This table summarizes the default folder structure for different targets.
|Target Type||Model Type||Folder Under <pwd>/slprj/_sfprj/<mainModel>|
These definitions apply to the table:
<pwd> is the current working folder.
<mainModel> is the name of the main model.
<libModel> is the name of the library model.
<sys_targ> is the type of embeddable target (for example, grt or ert).
For embeddable targets, the integrated C code for the entire model resides in the subfolder <mainModel>_<sys_targ>_rtw of the current MATLAB folder. The executable file generated for the entire model resides in the current MATLAB folder.
Tip To use a root folder different from <pwd> for storing generated files, open the Simulink Preferences Window and update the File generation control section.
For more information, see File generation control in the Simulink documentation.
For a simulation target, you generate these files:
<model>_sfun.h is the machine header file. It contains:
All the defined global variables needed for the generated code
Type definition of the Stateflow machine-specific data structure that holds machine-parented local data
External declarations of any Stateflow machine-specific global variables and functions
Custom code strings that you specify
<model>_sfun.c is the machine source file. It includes the machine header file and all the chart header files (described below) and contains Simulink interface code.
<model>_sfun_registry.c is a machine registry file that contains Simulink interface code.
cn_<model>.h is the chart header file for the chart chartn, where n = 1, 2, 3, and so on, depending on how many charts your model has (see the following note). This header file contains type definitions of the chart-specific data structures that hold chart-parented local data and states.
cn_<model>.c is the chart source file for chartn, where n = 1, 2, 3, and so on, depending on how many charts your model has (see the following note). This source file includes the machine header file and the corresponding chart header file and also contains:
Chart-parented data initialization code
Chart execution code (state entry, during, and exit actions, and so on)
Chart-specific Simulink interface code
For library models, a static library file named <libModel>_sfun resides in the same folder as the source code. The file extension depends on the platform. On a Windows operating system, the library file is <libModel>_sfun.lib, but on a UNIX® operating system, the library file is <libModel>_sfun.a.
For an embeddable target, you generate integrated C code for the entire model:
You also generate intermediate code files during the target building process:
cn_<model>.tlh, where n = 1, 2, 3, and so on, depending on how many charts your model has
cn_<model>.tlc, where n = 1, 2, 3, and so on, depending on how many charts your model has
Other auxiliary files can appear depending on the type of embeddable target you choose for code generation.
You generate makefiles for your model that are platform and compiler-specific. On UNIX platforms, you generate a gmake-compatible makefile named <mainModel>_sfun.mku that compiles all your generated code into an executable. On PC platforms, you generate an ANSI-C compiler-specific makefile based on your C-MEX setup:
|Compiler||Makefile||Symbol Definition File|
|Microsoft® Visual C++®||<mainModel>_sfun.mak||<mainModel>_sfun.def (required to build S-function MEX-files)|
|lcc-win32 (default ANSI-C compiler)||<mainModel>_sfun.lmk||None|
Note: For a list of supported compilers, see: