setFunctionDefault
Set default function customization template and memory section for model functions category
Since R2020b
Description
setFunctionDefault(
sets the default function customization template and memory section for the specified
category of model entry-point functions.coderMapObj
,funcCategory
,Name=Value
)
You cannot specify default function interfaces for models with an attached Embedded Coder Dictionary that defines a service interface configuration.
Examples
Programmatically Get and Set Function Defaults in Code Mappings of Simulink Models
Use the programmatic interface to retrieve and configure function defaults in the code mappings of a Simulink model.
To interactively observe how your commands are reflected in the Code Mappings editor and the model dictionary, make sure the Code Mappings editor is open with the Function Defaults tab selected, and the model dictionary open with the Function Customization Template section selected. To learn how to open the Code Mappings editor, see Open the Code Mappings Editor – C. To learn how to open the model dictionary, see Open the Embedded Coder Dictionary.
Open the model CoderMapAPI
.
simulinkModel = "ECoderMapAPI";
open_system(simulinkModel);
Get the code mappings object of this model.
codeMapObj = coder.mapping.api.get(simulinkModel);
Specify FunctionName
as an empty string for all model functions so that their names in the generated code are determined by the value you set for the function defaults.
setFunction(codeMapObj,find(codeMapObj,"Functions"),FunctionName=string.empty);
Get the default customization template of the InitializeTerminate
and Execution
functions.
exeFCNsTemplate = getFunctionDefault(codeMapObj,"Execution","FunctionCustomizationTemplate")
exeFCNsTemplate = 'FCN_Template__2'
initTermFCNsTemplate = getFunctionDefault(codeMapObj,"InitializeTerminate","FunctionCustomizationTemplate")
initTermFCNsTemplate = 'FCN_Template__1'
Generate code from the model.
evalc("slbuild(simulinkModel)");
Model entry-point functions are declared in the generated header file of the model. Store the header file name.
model_h_file = fullfile(simulinkModel+"_ert_rtw",simulinkModel+".h")
model_h_file = "ECoderMapAPI_ert_rtw/ECoderMapAPI.h"
Function Naming Rule of FCN_Template__1
begins with Template_1
and Function Naming Rule of FCN_Template__2 begins with Template_2
. This is the entry-point function declaration section in the generated header file:
/* Model entry point functions */ extern void Template_1_FCN_ECoderMapAPI_initialize(void); extern void Template_2_FCN_ECoderMapAPI_step(void); extern void Template_1_FCN_ECoderMapAPI_terminate(void);
The function names are generated according to the specified Function Customization Template values for those functions.
To open the header file and, enter this command in the MATLAB Command Window:
edit(model_h_file)
Switch between the templates of the two function categories.
setFunctionDefault(codeMapObj,"Execution",FunctionCustomizationTemplate=initTermFCNsTemplate); setFunctionDefault(codeMapObj,"InitializeTerminate",FunctionCustomizationTemplate=exeFCNsTemplate);
Generate code from the model again.
evalc("slbuild(simulinkModel)");
The entry-point function names are updated according to their updated Function Customization Templates:
/* Model entry point functions */ extern void Template_2_FCN_ECoderMapAPI_initialize(void); extern void Template_1_FCN_ECoderMapAPI_step(void); extern void Template_2_FCN_ECoderMapAPI_terminate(void);
Input Arguments
coderMapObj
— Code mapping object
CodeMapping
object
Code mapping object (model code mappings) returned by a call to function
coder.mapping.api.get
.
Example: myCM
funcCategory
— Model function category
InitializeTerminate
| Execution
| SharedUtility
Category of model entry-point functions for which to set the function customization template and memory section.
Example: "Execution"
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: FunctionCustomizationTemplate="exFastFunction"
FunctionCustomizationTemplate
— Name of function customization template
character vector | string scalar
Name of a function customization template defined in the Embedded Coder Dictionary
associated with the model. If you set the default function customization template for
a category of functions to Default
, you can specify a memory
section for the category of functions.
Data Types: char
| string
MemorySection
— Name of memory section
character vector | string scalar
Name of a memory section that is defined in the Embedded Coder Dictionary associated with the model.
Data Types: char
| string
Version History
Introduced in R2020b
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)