coder.mapping.api.CodeMapping - Model data and function interface configuration for C code generation - MATLAB (original) (raw)

Main Content

Model data and function interface configuration for C code generation

Since R2020b

Description

A code mappings object and related functions enable you to configure C code generation for data of a SimulinkĀ® model. For model data elements, code mappings associate data elements with configurations that consist of a storage class and storage class properties. Reduce the effort of preparing a model for C code generation by specifying default configurations for categories of data elements across a model. Override default configurations by configuring data elementsindividually. For smaller models, you can choose to configure each data elementindividually.

Creation

When you select a code generation app from the Apps tab in the Simulink Editor, such as the Simulink Coder or Embedded Coder app, the app creates a coder.mapping.api.CodeMapping object if code mappings do not already exist. The app creates code mappings based on code customization settings stored in the model active configuration set object. The configuration set object can specify memory sections for data and functions.

Create a coder.mapping.api.CodeMapping object programmatically by calling the function coder.mapping.utils.create.

Object Functions

addSignal Add block output signal to model code mappings
coder.mapping.api.get Get code mappings for model
coder.mapping.utils.create Create code mappings object for configuring data and function interface for C and C++ code generation
find Get model elements for the category of model code mappings
getDataDefault Get default storage class or storage class property setting for model data category
getDataStore Get code and calibration configuration from code mappings for local or shared local data store
getInport Get code and calibration configuration from code mappings for root-level inport
getModelParameter Get code and calibration configuration from code mappings for model parameters
getModelVariantControl Get code configuration from code mappings forSimulink.VariantControl object
getModelVariantVariable Get code configuration from code mappings forSimulink.VariantVariable object
getOutport Get code and calibration configuration from code mappings for root-level outport
getSignal Get code and calibration configuration from code mappings for block output signal
getState Get code and calibration configuration from code mappings for block state
removeSignal Remove block output signal from model code mappings
setDataDefault Set default storage class and storage class property values for model data category
setDataStore Configure local or shared local data store for code and calibration file (a2l) generation
setInport Configure root-level inports for code and calibration file (a2l) generation
setModelParameter Configure model parameter for code and calibration file (a2l) generation
setModelVariantControl Configure Simulink.VariantControl object for code generation
setOutport Configure root-level outport for code and calibration file (a2l) generation
setSignal Configure block signal data for code and calibration file (a2l) generation
setState Configure block states for code and calibration file (a2l) generation

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

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

Close the model without saving it.

close_system(simulinkModel,false)

Version History

Introduced in R2020b

expand all

Starting in R2023a, tab completion is available for function names and arguments and for object properties. After you enter the first few characters of a function, input argument, or object property, press the Tab key to let MATLABĀ® automatically complete the typing. MATLAB adds the remaining characters of the function, argument, or parameter. If you did not enter anything or if there are multiple options that begin with the characters you entered, MATLAB opens a list of available alternatives you can choose from. To learn more about tab completion, see Code Suggestions and Completions.