setDataDefault
Set default storage class and storage class property values for model data category
Since R2020b
Description
setDataDefault(
sets the default storage class and storage class property values in the code mappings for
the specified category of model data.coderMapObj
,elemCategory
,Name=Value
)
You cannot specify default data interfaces for models with an attached Embedded Coder Dictionary that defines a service interface configuration.
Examples
Programmatically Get and Set Data Defaults in Code Mappings of Simulink Models
Use the programmatic interface to get and set the data defaults in the code mappings configuration 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 Data Defaults tab selected. To learn how to open the Code Mappings editor, see Open the Code Mappings Editor – C.
Open the model CoderMapAPI
.
simulinkModel = "CoderMapAPI";
open_system(simulinkModel);
Retrieve the code mappings object of the model.
codeMapObj = coder.mapping.api.get(simulinkModel);
Set the storage class of all root-level ports to Model default
so that their generated code is determined by the value you set for Data Defaults
.
setInport(codeMapObj,find(codeMapObj,"Inport"),StorageClass="Model default") setOutport(codeMapObj,find(codeMapObj,"Outport"),StorageClass="Model default")
Determine the default storage classes for Input and output ports.
inPortDefaultStorageClass = getDataDefault(codeMapObj,"Inports","StorageClass")
inPortDefaultStorageClass = 'ImportedExtern'
outPortDefaultStorageClass = getDataDefault(codeMapObj,"Outports","StorageClass")
outPortDefaultStorageClass = 'ImportedExternPointer'
Generate code from the model.
evalc("slbuild(simulinkModel)");
Root-level ports with ImportedExtern
and ImportedExternPointer
storage classes are declared in the generated private header file of the model in separate sections.
Store the name of the header file.
priv_h_file = fullfile(simulinkModel+"_grt_rtw",simulinkModel+"_private.h")
priv_h_file = "CoderMapAPI_grt_rtw/CoderMapAPI_private.h"
These are the declarations of the root-level ports in the header file:
/* Data with Imported storage */ extern real_T in_port_1; /* '<Root>/in_port_1' */ extern real_T in_port_2; /* '<Root>/in_port_2' */ extern real_T in_port_3; /* '<Root>/in_port_3' */ extern real_T in_port_4; /* '<Root>/in_port_4' */ /* Data with Imported storage (pointer) */ extern real_T *out_port_1; /* '<Root>/out_port_1' */ extern real_T *out_port_2; /* '<Root>/out_port_2' */ extern real_T *out_port_3; /* '<Root>/out_port_3' */ extern real_T *out_port_4; /* '<Root>/out_port_4' */
To open the header file, enter this command in the MATLAB Command Window.
edit(priv_h_file)
Switch between the default storage class of input and output ports.
setDataDefault(codeMapObj,"Inports",StorageClass=outPortDefaultStorageClass); setDataDefault(codeMapObj,"Outports",StorageClass=inPortDefaultStorageClass);
Generate the code from the revised model.
evalc("slbuild(simulinkModel)");
The declarations of the root-level ports are updated in the header file according to the specified storage classes.
/* Data with Imported storage */ extern real_T out_port_1; /* '<Root>/out_port_1' */ extern real_T out_port_2; /* '<Root>/out_port_2' */ extern real_T out_port_3; /* '<Root>/out_port_3' */ extern real_T out_port_4; /* '<Root>/out_port_4' */ /* Data with Imported storage (pointer) */ extern real_T *in_port_1; /* '<Root>/in_port_1' */ extern real_T *in_port_2; /* '<Root>/in_port_2' */ extern real_T *in_port_3; /* '<Root>/in_port_3' */ extern real_T *in_port_4; /* '<Root>/in_port_4' */
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
elemCategory
— Model element category
Constants
| ExternalParameterObjects
| GlobalDataStores
| Inports
| InternalData
| ModelParameters
| ModelParameterArguments
| Outports
| SharedLocalDataStores
Category of model data element for which to set the storage class and storage class properties.
Example: "Inports"
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: StorageClass="ExportedGlobal"
StorageClass
— Name of storage class
Auto
| Bitfield
| CompileFlag
| Const
| ConstVolatile
| Define
| Dictionary default
| ExportedGlobal
| ExportToFile
| FileScope
| GetSet
| ImportedDefine
| ImportedExtern
| ImportedExternPointer
| ImportFromFile
| Localizable
| Model default
| Struct
| Volatile
| storage class name
Storage class to set for the specified data element category. The name of a predefined storage class or storage class that is defined in the Embedded Coder Dictionary associated with the model. Values that you can specify vary depending on the category that you specify. See Choose Storage Class for Controlling Data Representation in Generated Code.
Example: StorageClass="ImportedExtern"
DefinitionFile
— C source file
character vector | string scalar
File name for a C source file that contains definitions for global data read by
data elements and external code. Applies to storage classes Const
,
ConstVolatile
, ExportToFile
, and
Volatile
.
Example: DefinitionFile="myDataDefs.c"
Data Types: char
| string
GetFunction
— Name of get function
character vector | string scalar
Name of a get
function that a data element calls in the
generated code. Applies to storage class GetSet
.
Example: GefFunction="myDataGetFunction"
Data Types: char
| string
HeaderFile
— C header file
character vector | string scalar
File name for a C header file that contains declarations for global data read by
data elements and external code. Applies to storage classes Const
,
ConstVolatile
, Define
,
ExportToFile
, GetSet
,
ImportedDefine
, ImportFromFile
, and
Volatile
.
Example: HeaderFile="myDataDecl.h"
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.
Note
You cannot directly retrieve or configure the default
MemorySection
for the
ModelParameterArguments
category using the code mapping
object. To configure the default MemorySection
for
ModelParameterArguments
, define a custom
StorageClass
with the MemorySection
in a
coder dictionary, and set this storage class as the default for
ModelParameterArguments
.
Example: MemorySection="myFastMem"
Data Types: char
| string
Owner
— Owner of global data
character vector | string scalar
Name of the model that owns global data, which is used by other models in the same
model hierarchy. The code generated for the model that owns the data includes the
global data definition. Applies to storage classes Const
,
ConstVolatile
, ExportToFile
, and
Volatile
.
Example: Owner="myModelA"
Data Types: char
| string
PreserveDimensions
— Boolean flag indicating whether to preserve dimensions of multidimensional arrays
True
| False
When model configuration parameter Array layout is set to
Row-major
, a flag that indicates whether to preserve
dimensions of a data element represented in generated code as a multidimensional
array. Applies to storage classes Const
,
ConstVolatile
, , ExportToFile
,
FileScope
, GetSet
,
ImportFromFile
, Localizable
, and
Volatile
.
Example: PreserveDimensions=true
Data Types: logical
SetFunction
— Name of set function
character string | string scalar
Name of a set
function that a data element calls in the
generated code. Applies to storage class GetSet
.
Example: SetFunction="myDataSetFunction"
Data Types: char
| string
StructName
— Name of structure
character vector | string scalar
Name that the code generator uses to identify the structure for a data element in
the generated code. Applies to storage classes Bitfield
and
Struct
.
Example: StructName="myDataStruct"
storageClassPropertyName
— Value of storage class property
depends on property definition
Storage class property defined in the Embedded Coder Dictionary. Values that you can specify vary depending on the storage class definition.
Data Types: char
| string
Version History
Introduced in R2020b
See Also
coder.mapping.api.CodeMapping
| coder.mapping.api.get
| getDataDefault
Topics
- C Data Code Interface Configuration for Model Interface Elements
- Configure Root-Level Inport Blocks for C Code Generation
- Configure Root-Level Outport Blocks for C Code Generation
- Configure Signal Data for C Code Generation
- Configure Parameters for C Code Generation
- Configure Block States for C Code Generation
- Configure Data Stores for C Code Generation
- Configure Default C Code Generation for Categories of Data Elements and Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)