setFunction
Description
setFunction(
sets code mapping information for the specified model function. Use this function to set the
function customization template, memory section, or function name for a model function. For
single-tasking periodic functions and Simulink® functions, you can use this function to set the argument specification,
including argument names, type qualifiers, and argument order. coderMapObj
,modelFunc
,Name=Value
)
Examples
Programmatically Get and Set Function Properties in Code Mappings of Simulink Models
Use the programmatic interface to retrieve and configure properties of functions in the code mappings of a Simulink model.
To interactively observe how your commands are reflected in the Code Mappings editor, make sure the Code Mappings editor is open with the Functions tab selected. To learn how to open the Code Mappings editor, see Open the Code Mappings Editor – C.
Open the model ECoderMapAPI
.
simulinkModel = "ECoderMapAPI";
open_system(simulinkModel);
Get the code mappings object of the model.
codeMapObj = coder.mapping.api.get(simulinkModel);
Get the FunctionName
property of the periodic function and the initialization function.
periodicFcnName = getFunction(codeMapObj,"Periodic:D1","FunctionName")
periodicFcnName = 'myPeriodicFcn'
InitFcnName = getFunction(codeMapObj,"Initialize","FunctionName")
InitFcnName = 'myInitFcn'
Generate code from the model.
evalc("slbuild(simulinkModel)");
Entry-point functions are declared in the model header file. Store the header file name in the variable model_h_file
.
model_h_file = fullfile(simulinkModel+"_ert_rtw",simulinkModel+".h")
model_h_file = "ECoderMapAPI_ert_rtw/ECoderMapAPI.h"
This is the declaration of the entry-point functions in the header file:
/* Model entry point functions */ extern void myInitFcn(void); extern void myPeriodicFcn(void);
The function names are the names stored in periodicFcnName
and InitFcnName
.
To open the header file, enter this command in the MATLAB Command Window:
edit(model_h_file)
Rename the periodic functions.
if(startsWith(periodicFcnName,"my")) setFunction(codeMapObj,"Periodic:D1",FunctionName="yourPeriodicFcn"); else setFunction(codeMapObj,"Periodic:D1",FunctionName="myPeriodicFcn"); end if(startsWith(InitFcnName,"my")) setFunction(codeMapObj,"Initialize",FunctionName="yourInitFcn"); else setFunction(codeMapObj,"Initialize",FunctionName="myInitFcn"); end
Generate code from the model again with the new entry-point function names.
evalc("slbuild(simulinkModel)");
This is the updated declaration of the entry-point functions in the header file.
/* Model entry point functions */ extern void yourInitFcn(void); extern void yourPeriodicFcn(void);
The function names are updated.
Input Arguments
coderMapObj
— Coder mapping object
CodeMapping
object
Coder mapping object of the model whose function is to be set, specified as a
coder.mapping.api.CodeMapping
object.
Example: myCM
modelFunc
— Model function
string scalar | character vector
Model function for which to return a code mapping property value, specified as one of these values:
Specified Value | Type of Model Function |
---|---|
"ExportedFunction: ,
where is the name
of the function-call Inport block in the model | Exported function |
"Initialize" | Initialize function |
"Partition: ,
where is a
partition created explicitly from a block in the model and shown in the
Simulink Schedule Editor (for example, P1 ), or a task
name in the Concurrent Execution dialog box | Partition function |
"PartitionUpdate: ,
where slIdentifier is a partition created
explicitly from a block in the model and shown in the Simulink Schedule Editor (for example, P1 ), or a task
name in the Concurrent Execution dialog box | Partition update function |
"Periodic: ,
where is an
annotation that corresponds to the sample time period for a periodic or
continuous rate of a multitasking model (for example, D1 ) | Periodic multitasking function |
"PeriodicUpdate: ,
where is an
annotation that corresponds to the sample time period for a periodic or
continuous rate of a multitasking model (for example, D1 ) | Periodic multitasking update function |
"Periodic" | Periodic single-tasking function |
"PeriodicUpdate" | Periodic single-tasking update function |
"Reset: , where
is the name of
the reset function in the model | Reset function |
"SimulinkFunction: ,
where is the name
of the Simulink function in the model | Simulink function |
"Terminate" | Terminate function |
If model configuration parameter Single output/update function is cleared, you can specify the updated version of the partition, periodic multitasking or periodic single-tasking function. For information about model partitioning, see Create Partitions.
Example: "Periodic:D1"
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, specified as a character vector or string scalar. If you
set the default function customization template for a category of functions to
Default
, you can specify a memory section for the functions
category.
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, specified as a character vector or string scalar.
Data Types: char
| string
FunctionName
— Name of function
character vector | string scalar
Name for the entry-point function in the generated C code, specified as a character vector or string scalar.
Data Types: char
| string
Arguments
— Argument specification
character vector | string scalar
Argument specification for the entry-point function in the
generated C code, specified as a character vector or string
scalar. The specification is a function prototype that shows
argument names, type qualifiers, and argument order (for example,
y=(u1, const *u2)
.
Data Types: char
| string
TimerService
— Name of timer service interface
Dictionary default
(default) | character vector | string scalar
String or character vector containing the name of a timer service interface
defined in the Embedded Coder Dictionary. To use the dictionary default, specify
"Dictionary default"
.
This property is only applicable for exported functions, and only for service interface mappings. For more information, see Configure Timer Service Interfaces.
Data Types: char
| string
Version History
Introduced in R2020b
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
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)