Main Content

coder.mapping.utils.create

Create code mappings object for configuring data and function interface for C and C++ code generation

Since R2020b

    Description

    example

    coderMapObj = coder.mapping.utils.create(simulinkModel) creates a code mappings environment for the specified model, if one does not exist, and returns it as the object coderMapObj. Code mappings associate model data elements and functions with configurations for C or C++ code generation. If code mappings exist for the specified model, the function returns those code mappings as the object coderMapObj.

    coderMapObj = coder.mapping.utils.create(simulinkModel,configObj) imports default memory section and shared utility naming rule configurations from configuration set configObj while creating C code mappings for the specified model. See Migration of Memory Section and Shared Utility Settings from Configuration Parameters to Code Mappings.

    Examples

    collapse all

    Use the programmatic interface to create and use code mappings objects of Simulink models.

    Load the model NoCoderMapping.

    simulinkModel = "NoCoderMapping";
    load_system(simulinkModel);

    Use a try-catch block to determine whether a code mappings object exists for the model. Inside the try block, attempt to retrieve the existing object by using function coder.mapping.api.get. Inside the catch block, create a new code mappings object by using the function coder.mapping.utils.create. Store the code mappings object in the variable codeMapObj.

    Add print messages to show whether the model had an existing code mappings object or not.

    try
      codeMapObj = coder.mapping.api.get(simulinkModel);
              fprintf("" + ...
                " ========================================================\n" + ...
                " The model already had code mappings.\n" + ...
                " ========================================================\n");
    catch
              fprintf("" + ...
                " ==========================================\n" + ...
                " The model does not have code mappings.\n" + ...
                " Creating new code mappings for the model.\n" + ...
                " ==========================================\n");
      codeMapObj = coder.mapping.utils.create(simulinkModel);
    end
     ==========================================
     The model does not have code mappings.
     Creating new code mappings for the model.
     ==========================================
    

    Retrieve the storage class of input port inport_1 of the model.

    getInport(codeMapObj,"inport_1","StorageClass")
    ans = 
    'Auto'
    

    Set the storage class of input port inport_1 to ExportedGlobal.

    setInport(codeMapObj,"inport_1",StorageClass="ExportedGlobal")

    Use the same try-catch block to see how the function coder.mapping.api.get is now able to retrieve the existing code mappings of the model.

    try
      codeMapObj = coder.mapping.api.get(simulinkModel);
              fprintf("" + ...
                " ========================================================\n" + ...
                " The model already had code mappings.\n" + ...
                " ========================================================\n");
    catch
              fprintf("" + ...
                " ==========================================\n" + ...
                " The model does not have code mappings.\n" + ... 
                " Creating new code mappings for the model.\n" + ...
                " ==========================================\n");
      codeMapObj = coder.mapping.utils.create(simulinkModel);
    end
     ========================================================
     The model already had code mappings.
     ========================================================
    

    Retrieve the storage class of input port inport_1 of the model. Notice that it is the storage class that you set previously.

    getInport(codeMapObj,"inport_1","StorageClass")
    ans = 
    'ExportedGlobal'
    

    Close the model without saving it.

    close_system(simulinkModel,false)

    Input Arguments

    collapse all

    Simulink® model for which to create and return a code mappings object, specified as a handle or a character vector or string scalar with the model name (without the .slx file extension), or the relative or absolute path of the model file (including the .slx file extension).

    Note

    The model must be loaded (for example, by using load_system).

    Example: "configModel"

    Data Types: char | string | handle

    Model configuration object from which to import memory section and shared utility naming rule configurations while creating code mappings for simulinkModel, specified as a handle, character vector or string scalar. Specify a configuration set object to preserve memory section definitions or shared utility naming rules applied to a model in a version of Embedded Coder® prior to R2018a.

    Example: "my_legacyConfigset"

    Output Arguments

    collapse all

    The model code mappings, returned as a CodeMapping object or a CodeMappingCPP object.

    OutputInput Object
    coder.mapping.api.CodeMappingSimulink model configured for C code generation
    coder.mapping.api.CodeMappingCPPSimulink model configured for C++ code generation

    Version History

    Introduced in R2020b