Main Content

getFunctionDefault

Get default function customization template or memory section for model functions category

Since R2020b

    Description

    example

    propertyValue = getFunctionDefault(coderMapObj,funcCategory,funcProperty) returns the value of the specified property for the specified function category.

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

    Examples

    collapse all

    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 generated the 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

    collapse all

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

    Example: myCM

    Category of model entry-point functions for which to return the default function customization template or memory section.

    Example: "Execution"

    FunctionCustomizationTemplate or MemorySection for which to return a value.

    Example: "FunctionCustomizationTemplate"

    Output Arguments

    collapse all

    Name of the function customization template or memory section.

    Data Types: char | string

    Version History

    Introduced in R2020b