Main Content


Get code configuration from code mappings for model function

Since R2020b



    propertyValue = getFunction(coderMapObj,modelFunc,funcProperty) returns the value of a property for the specified model function. Use this function to return the function customization template or memory section configured for a model function. For single-tasking periodic functions for which you previously set an argument specification and for Simulink functions, use this function to return the argument specification.


    collapse all

    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";

    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 = 
    InitFcnName = getFunction(codeMapObj,"Initialize","FunctionName")
    InitFcnName = 

    Generate code from the model.


    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 = 

    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:


    Rename the periodic functions.


    Generate code from the model again with the new entry-point function names.


    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

    collapse all

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

    Example: myCM

    Model function for which to return a code mapping property value, specified as one of the values in this table. If model configuration parameter Single output/update function is cleared, you can specify the update version of a partition, periodic multitasking, or periodic single-tasking function. For information about model partitioning, see Create Partitions.

    ValueType of Model Function
    "Initialize"Initialize function
    "Periodic"Periodic single-tasking function
    "PeriodicUpdate"Periodic single-tasking update function
    "Terminate"Terminate function
    "Periodic:slIdentifier", where slIdentifier 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:slIdentifier", where slIdentifier 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
    "Reset:slIdentifier", where slIdentifier is the name of the reset function in the model Reset function
    "SimulinkFunction:slIdentifier", where slIdentifier is the name of the Simulink function in the modelSimulink® function

    Example: "Periodic:D1"

    Code mapping property value to return. Specify one of the property names listed in this table.

    Information to ReturnProperty Name
    Function customization template setting for the specified functionFunctionCustomizationTemplate
    Memory section associated with the specified functionMemorySection
    Name to use for the function in the generated codeFunctionName
    For periodic, single-tasking functions and Simulink functions, a string that shows the names, type qualifiers, and order of arguments as they will appear in the generated code Arguments
    Name of timer service defined in Embedded Coder DictionaryTimerService

    Example: "FunctionCustomizationTemplate"

    Output Arguments

    collapse all

    Name of the function customization template, memory section, function, or argument specification returned as a character vector or string scalar.

    Data Types: char | string

    Version History

    Introduced in R2020b