Main Content

getDataDefault

Get default storage class or storage class property setting for model data category

Since R2020b

    Description

    propertyValue = getDataDefault(coderMapObj,elementCategory,mapProperty) returns the value from the code mappings of the specified property for the specified data category.

    You cannot specify default data interfaces for models with an attached Embedded Coder Dictionary that defines a service interface configuration.

    example

    Examples

    collapse all

    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

    collapse all

    Code mapping object (model code mappings) returned by a call to function coder.mapping.api.get.

    Example: myCM

    Category of model data elements that you return a property value for.

    Example: "Inports"

    Code mapping property that you return a value for. Specify one of these property names or a property name for a storage class 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.

    Information to ReturnProperty Name
    Name of storage classStorageClass
    Name of variable for data element in the generated codeIdentifier
    Name of source definition file that contains definitions for global data that is read by the data element and external codeDefinitionFile
    Name of get function called by code generated for the data elementGetFunction
    Name of source header file that contains declarations for global data that is read by the model data element and external codeHeaderFile
    Name of a memory section that is defined in the Embedded Coder Dictionary associated with the modelMemorySection
    Name of model for which the code generator places the definition for data element shared by multiple models in a model hierarchy Owner
    Boolean value indicating whether code generator preserves dimensions of data that is represented as a multidimensional arrayPerserveDimensions
    Name of set function called by code generated for data elementSetFunction
    Name of structure in generated code for data elementStructName

    Example: "Identifier"

    Output Arguments

    collapse all

    The property value is one of these values depending on the category and property that you specify.

    PropertyValue Returned
    DefinitionFileCharacter vector or string scalar that names 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.
    GetFunctionCharacter vector or string scalar that names a get function that a data element calls in the generated code. Applies to storage class GetSet.
    HeaderFileCharacter vector or string scalar that names 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.
    MemorySectionCharacter vector or string scalar that names a memory section for a model defined in the Embedded Coder Dictionary.
    OwnerCharacter vector or string scalar that names the model that owns global data, which is used by other models in the same model hierarchy. The code generated for the owner model includes the global data definition. Applies to storage classes Const, ConstVolatile, ExportToFile, and Volatile.
    PerserveDimensionsBoolean flag that indicates whether to preserve dimensions of a data element that is represented in generated code as a multidimensional array. Applies to storage classes Const, ConstVolatile, ExportToFile, FileScope, ImportFromFile, Localizable, and Volatile.
    SetFunction

    Character vector or string scalar that names a set function, which a data element calls in the generated code. Applies to storage class GetSet.

    StorageClassOne of these values: Auto, Bitfield, CompileFlag, Const, ConstVolatile, Define, Dictionary default, ExportedGlobal, ExportToFile, FileScope, GetSet, ImportedDefine, ImportedExtern, ImportedExternPointer, ImportFromFile, Localizable, Model default, Struct, Volatile
    StructNameCharacter vector or string scalar that names that names a structure for a data element in the generated code. Applies to storage classes Bitfield and Struct.

    Data Types: char | string

    Version History

    Introduced in R2020b