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
.
Retrieve the code mappings object of the model.
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
.
Determine the default storage classes for Input and output ports.
inPortDefaultStorageClass =
'ImportedExtern'
outPortDefaultStorageClass =
'ImportedExternPointer'
Generate code from the model.
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 =
"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.
Switch between the default storage class of input and output ports.
Generate the code from the revised model.
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' */