| Simulink® | ![]() |
legacy_code('help')
specs =
legacy_code('initialize')
legacy_code('sfcn_cmex_generate', specs)
legacy_code('compile', specs, compilerOptions)
legacy_code('slblock_generate', specs, modelname)
legacy_code('sfcn_tlc_generate', specs)
legacy_code('rtwmakecfg_generate', specs)
legacy_code('backward_compatibility')
A structure with the following fields
| Field | Description |
|---|---|
| Name the S-function | |
SFunctionName (Required) | A string specifying a name for the S-function to be generated by the Legacy Code Tool. |
| Define Legacy Code Tool Function Specifications | |
InitializeConditionsFcnSpec | A nonempty string specifying a reentrant function that the S-function calls to initialize and reset states. You must declare this function by using tokens that Simulink® software can interpret as explained in Declaring Legacy Code Tool Function Specifications. |
OutputFcnSpec | A nonempty string specifying the function that the S-function calls at each time step. You must declare this function by using tokens that Simulink software can interpret as explained in Declaring Legacy Code Tool Function Specifications. |
StartFcnSpec | A string specifying the function that the S-function calls when it begins execution. This function can access S-function parameter arguments only. You must declare this function by using tokens that Simulink software can interpret as explained in Declaring Legacy Code Tool Function Specifications. |
TerminateFcnSpec | A string specifying the function that the S-function calls when it terminates execution. This function can access S-function parameter arguments only. You must declare this function by using tokens that Simulink software can interpret as explained in Declaring Legacy Code Tool Function Specifications. |
| Define Compilation Resources | |
HeaderFiles | A cell array of strings specifying the file names of header files required for compilation. |
SourceFiles | A cell array of strings specifying source files required for compilation. You can specify the source files using absolute or relative pathnames. |
HostLibFiles | A cell array of strings specifying library files required for host compilation. You can specify the library files using absolute or relative pathnames. |
TargetLibFiles | A cell array of strings specifying library files required for target (that is, standalone) compilation. You can specify the library files using absolute or relative pathnames. |
IncPaths | A cell array of strings specifying directories containing header files. You can specify the directories using absolute or relative pathnames. |
SrcPaths | A cell array of strings specifying directories containing source files. You can specify the directories using absolute or relative pathnames. |
LibPaths | A cell array of strings specifying directories containing host and target library files. You can specify the directories using absolute or relative pathnames. |
| Specify a Sample Time | |
SampleTime | One of the following: 'inherited' (default) — Sample time is inherited from the source block. 'parameterized' — Sample time is represented as a tunable parameter. Generated code can access the parameter by calling MEX API functions, such as mxGetPr or mxGetData. Fixed — Sample time that you explicitly specify. For information on how to specify sample time, see Specifying Sample Time. If you specify this field, you must specify it last. |
| Define S-Function Options | |
Options | A structure that controls S-function options. The structure's fields include: isMacro — A logical value specifying whether the legacy code is a C macro. By default, its value is false (0). isVolatile — A logical value specifying the setting of the S-function SS_OPTION_NONVOLATILE option (see SS_OPTION_NONVOLATILE). By default, its value is true (1). canBeCalledConditionally — A logical value specifying the setting of the S-function SS_OPTION_CAN_BE_CALLED_CONDITIONALLY option (see SS_OPTION_CAN_BE_CALLED_CONDITIONALLY). By default, its value is true (1). useTlcWithAccel — A logical value specifying the setting of the S-function SS_OPTION_USE_TLC_WITH_ACCELERATOR option (see SS_OPTION_USE_TLC_WITH_ACCELERATOR). By default, its value is true (1). language — A string specifying either 'C' or 'C++' as the target language of the S-function that Legacy Code Tool will produce. By default, its value is 'C'. |
The name of a Simulink model into which Legacy Code Tool is to insert the masked S-function block generated when you specify legacy_code with the action string 'slblock_generate'. If you omit this argument, the block appears in an empty model editor window.
The legacy_code function creates a MATLAB® structure for registering the specification for existing C or C++ code and the S-function being generated. In addition, the function can generate, compile and link, and create a masked block for the specified S-function. Other options include generating
A TLC file for simulation in Accelerator mode or code generation
An rtwmakecfg.m file that you can customize to specify dependent source and header files that reside in a different directory than that of the generated S-function
legacy_code('help') displays instructions for using Legacy Code Tool.
specs = legacy_code('initialize') initializes the Legacy Code Tool data structure, specs, which registers characteristics of existing C or C++ code and properties of the S-function that the Legacy Code Tool generates.
legacy_code('sfcn_cmex_generate', specs) generates an S-function source file as specified by the Legacy Code Tool data structure, specs.
legacy_code('compile', specs, compilerOptions) compiles and links the S-function generated by the Legacy Code Tool based on the data structure, specs, and any compiler options that you might specify. The following examples show how to specify no options, one option, and multiple options:
legacy_code('compile', s);
legacy_code('compile', s, '-DCOMPILE_VALUE1=1');
legacy_code('compile', s,...
{'-DCOMPILE_VALUE1=1', '-DCOMPILE_VALUE2=2',...
'-DCOMPILE_VALUE3=3'});legacy_code('slblock_generate', specs, modelname) generates a masked S-Function block for the S-function generated by the Legacy Code Tool based on the data structure, specs. The block appears in the Simulink model specified by modelname. If you omit modelname, the block appears in an empty model editor window.
legacy_code('sfcn_tlc_generate', specs) generates a TLC file for the S-function generated by the Legacy Code Tool based on the data structure, specs. This option is relevant if you want to
Force Accelerator mode in Simulink software to use the TLC inlining code of the generated S-function. See the description of the ssSetOptions SimStruct function and SS_OPTION_USE_TLC_WITH_ACCELERATOR S-function option for more information.
Use Real-Time Workshop® software to generate code from your Simulink model. See Using the Legacy Code Tool to Automate the Generation of Files for Fully Inlined S-Functions for more information.
legacy_code('rtwmakecfg_generate', specs) generates an rtwmakecfg.m file for the S-function generated by the Legacy Code Tool based on the data structure, specs. This option is relevant only if you use Real-Time Workshop software to generate code from your Simulink model. See Using the rtwmakecfg.m API and Using the Legacy Code Tool to Automate the Generation of Files for Fully Inlined S-Functions in the Real-Time Workshop documentation for more information.
legacy_code('backward_compatibility') automatically updates syntax for using Legacy Code Tool, as made available from MATLAB Central in releases before R2006b, to the supported syntax described in this reference page and in Integrating Existing C Functions into Simulink® Models with the Legacy Code Tool in Writing S-Functions.
Integrating Existing C Functions into Simulink® Models with the Legacy Code Tool in the Writing S-Functions documentation
Using the Legacy Code Tool to Automate the Generation of Files for Fully Inlined S-Functions in the Real-Time Workshop documentation
![]() | getfullname | libinfo | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |