Access Data Through Functions with Storage Class GetSet
To integrate the generated code with legacy code that uses specialized functions to read
from and write to data, you can use the storage class GetSet
. Signals,
block parameters, and states that use GetSet
appear in the generated code
as calls to accessor functions. You provide the function definitions.
You can also create your own storage class in Embedded Coder® Dictionary to access data through functions. Creating your own storage class in Embedded Coder Dictionary gives you the flexibility of customizing function names and return types. For more information, see Access Data Through Functions by Using Storage Classes in Embedded Coder Dictionary.
To generate code that conforms to the AUTOSAR standard by accessing data through
Rte
function calls, use the AUTOSAR code perspective. See AUTOSAR Component Configuration (AUTOSAR Blockset).
Access Legacy Data Using Get and Set Functions
This example shows how to generate code that interfaces with legacy code by using specialized get
and set
functions to access data.
View the example legacy header file ComponentDataHdr.h
. The file defines a large structure type ComponentData
.
coder.example.extractLines('ComponentDataHeader.h','/* ComponentData */','} ComponentData;',1,1)
/* ComponentData */ typedef struct { ScalarData scalars; VectorData vectors; StructData structs; MatricesData matrices; } ComponentData;
The field scalars
is a substructure that uses the structure type ScalarData
. The structure type ScalarData
defines three scalar fields: inSig
, scalarParam
, and outSig
.
coder.example.extractLines('ComponentDataHeader.h','/* ScalarData */','} ScalarData;',1,1)
/* ScalarData */ typedef struct { double inSig; double scalarParam; double outSig; } ScalarData;
View the example legacy source file GetSetSourceData.c
. The file defines and initializes a global variable ex_getset_data
that uses the structure type ComponentData
. The initialization includes values for the substructure scalars
.
coder.example.extractLines('GetSetSourceData.c','/* Field "scalars" */','/* End of "scalars" */',1,1)
/* Field "scalars" */ { 3.9, 12.3, 0.0 }, /* End of "scalars" */
The file also defines functions that read from and write to the fields of the substructure scalars
. The functions simplify data access by dereferencing the leaf fields of the global structure variable ex_getset_data
.
coder.example.extractLines('GetSetSourceData.c',... '/* Scalar get() and set() functions */','/* End of scalar functions */',1,1)
/* Scalar get() and set() functions */ double get_inSig(void) { return ex_getset_data.scalars.inSig; } void set_inSig(double value) { ex_getset_data.scalars.inSig = value; } double get_scalarParam(void) { return ex_getset_data.scalars.scalarParam; } void set_scalarParam(double value) { ex_getset_data.scalars.scalarParam = value; } double get_outSig(void) { return ex_getset_data.scalars.outSig; } void set_outSig(double value) { ex_getset_data.scalars.outSig = value; }
View the example legacy header file GetSetSourceDataScalarHdr.h
. The file contains the extern
prototypes for the get
and set
functions defined in GetSetSourceData.c
.
Open the example model GetSetScalar
. The model creates the data objects inSig
, outSig
, and scalarParam
in the base workspace. The objects correspond to the signals and parameter in the model.
open_system('GetSetScalar')
In the base workspace, double-click the object inSig
to view its properties. The object uses the storage class GetSet
. The GetFunction
and SetFunction
properties are set to the defaults, get_$N
and set_$N
. The generated code uses the function names that you specify in GetFunction
and SetFunction
to read from and write to the data. The code replaces the token $N
with the name of the data object. For example, for the data object inSig
, the generated code uses calls to the legacy functions get_inSig
and set_inSig
.
For the data object inSig
, the HeaderFile
property is set to GetSetSourceDataScalarHdr.h
. This legacy header file contains the get
and set
function prototypes. The data objects outSig
and scalarParam
also use the storage class GetSet
and the header file GetSetSourceDataScalarHdr.h
.
In the model Configuration Parameters dialog box, on the Code Generation > Custom Code pane, on the Code information tab, select Source files. The Source files box identifies the source file GetSetSourceData.c
for inclusion during the build process. This legacy source file contains the get
and set
function definitions and the definition of the global structure variable ex_getset_data
.
Generate code with the example model.
slbuild('GetSetScalar');
### Starting build procedure for: GetSetScalar ### Successful completion of build procedure for: GetSetScalar Build Summary Top model targets: Model Build Reason Status Build Duration =============================================================================================================== GetSetScalar Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 24.66s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 29.454s
In the code generation report, view the file GetSetScalar.c
. The model step
function uses the legacy get
and set
functions to execute the algorithm. The generated code accesses the legacy signal and parameter data by calling the custom, handwritten get
and set
functions.
coder.example.extractLines(fullfile('GetSetScalar_ert_rtw','GetSetScalar.c'),... '/* Model step function */','}',1,1)
/* Model step function */ void GetSetScalar_step(void) { /* Gain: '<Root>/Gain' incorporates: * Inport: '<Root>/In1' */ set_outSig(get_scalarParam() * get_inSig()); }
You can generate code that calls your custom get
and set
functions as long as the functions that you write accept and return the expected values. For scalar data, the functions must have these characteristics:
The
get
function must return a single scalar numeric value of the appropriate data type, and must not accept any arguments (void
).The
set
function must not return anything (void
), and must accept a single scalar numeric value of the appropriate data type.
Use GetSet
with Vector Data
This example shows how to apply the storage class GetSet
to signals and parameters that are vectors.
View the example legacy header file ComponentDataHeader.h
. The file defines a large structure type ComponentData
.
coder.example.extractLines('ComponentDataHeader.h','/* ComponentData */','} ComponentData;',1,1)
/* ComponentData */ typedef struct { ScalarData scalars; VectorData vectors; StructData structs; MatricesData matrices; } ComponentData;
The field vectors
is a substructure that uses the structure type VectorData
. The structure type VectorData
defines three vector fields: inVector
, vectorParam
, and outVector
. The vectors each have five elements.
coder.example.extractLines('ComponentDataHeader.h','/* VectorData */','} VectorData;',1,1)
/* VectorData */ typedef struct { double inVector[5]; double vectorParam[5]; double outVector[5]; } VectorData;
View the example legacy source file GetSetSourceData.c
. The file defines and initializes a global variable ex_getset_data
that uses the structure type ComponentData
. The initialization includes values for the substructure vectors
.
coder.example.extractLines('GetSetSourceData.c','/* Field "vectors" */','/* End of "vectors" */',1,1)
/* Field "vectors" */ { {5.7, 6.8, 1.2, 3.5, 10.1}, {12.3, 18.7, 21.2, 28, 32.9}, {0.0, 0.0, 0.0, 0.0, 0.0} }, /* End of "vectors" */
The file also defines functions that read from and write to the fields of the substructure vectors
. The functions simplify data access by dereferencing the leaf fields of the global structure variable ex_getset_data
. To access the vector data, the functions accept an integer index argument. The get
function returns the vector value at the input index. The set
function assigns the input value
to the input index.
coder.example.extractLines('GetSetSourceData.c',... '/* Vector get() and set() functions */','/* End of vector functions */',1,1)
/* Vector get() and set() functions */ double get_inVector(int index) { return ex_getset_data.vectors.inVector[index]; } void set_inVector(int index, double value) { ex_getset_data.vectors.inVector[index] = value; } double get_vectorParam(int index) { return ex_getset_data.vectors.vectorParam[index]; } void set_vectorParam(int index, double value) { ex_getset_data.vectors.vectorParam[index] = value; } double get_outVector(int index) { return ex_getset_data.vectors.outVector[index]; } void set_outVector(int index, double value) { ex_getset_data.vectors.outVector[index] = value; }
View the example legacy header file GetSetSourceDataVectorHdr.h
. The file contains the extern
prototypes for the get
and set
functions defined in GetSetSourceData.c
.
Open the example model GetSetVector
. The model creates the data objects inVector
, outVector
, and vectorParam
in the base workspace. The objects correspond to the signals and parameter in the model.
open_system('GetSetVector')
In the base workspace, double-click the object inVector
to view its properties. The object uses the storage class GetSet
. The property HeaderFile
is specified as GetSetSourceDataVectorHdr.h
. This legacy header file contains the get
and set
function prototypes.
In the Configuration Parameters dialog box, on the Code Generation > Custom Code pane, the example legacy source file GetSetSourceData.c
is identified for inclusion during the build process. This legacy source file contains the get
and set
function definitions and the definition of the global structure variable ex_getset_data
.
Generate code with the example model.
slbuild('GetSetVector');
### Starting build procedure for: GetSetVector ### Successful completion of build procedure for: GetSetVector Build Summary Top model targets: Model Build Reason Status Build Duration =============================================================================================================== GetSetVector Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 14.03s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 14.823s
In the code generation report, view the file GetSetVector.c
. The model step
function uses the legacy get
and set
functions to execute the algorithm.
coder.example.extractLines(fullfile('GetSetVector_ert_rtw','GetSetVector.c'),... '/* Model step function */','}',1,1)
/* Model step function */ void GetSetVector_step(void) { int32_T i; for (i = 0; i < 5; i++) { /* Gain: '<Root>/Gain' incorporates: * Inport: '<Root>/In1' */ set_outVector(i, get_vectorParam(i) * get_inVector(i)); }
When you use the storage class GetSet
with vector data, the get
and set
functions that you provide must accept an index input. The get
function must return a single element of the vector. The set
function must write to a single element of the vector.
Use GetSet
with Structured Data
This example shows how to apply the storage class GetSet
to nonvirtual bus signals and structure parameters in a model.
View the example legacy header file ComponentDataHeader.h
. The file defines a large structure type ComponentData
.
coder.example.extractLines('ComponentDataHeader.h',... '/* ComponentData */','} ComponentData;',1,1)
/* ComponentData */ typedef struct { ScalarData scalars; VectorData vectors; StructData structs; MatricesData matrices; } ComponentData;
The field structs
is a substructure that uses the structure type StructData
. The structure type StructData
defines three fields: inStruct
, structParam
, and outStruct
.
coder.example.extractLines('ComponentDataHeader.h','/* StructData */','} StructData;',1,1)
/* StructData */ typedef struct { SigBus inStruct; ParamBus structParam; SigBus outStruct; } StructData;
The fields inStruct
, structParam
, and outStruct
are also substructures that use the structure types SigBus
and ParamBus
. Each of these two structure types define three scalar fields.
coder.example.extractLines('ComponentDataHeader.h','/* SigBus */','} ParamBus',1,1)
/* SigBus */ typedef struct { double cmd; double sensor1; double sensor2; } SigBus; /* ParamBus */ typedef struct { double offset; double gain1; double gain2; } ParamBus;
View the example legacy source file GetSetSourceData.c
. The file defines and initializes a global variable ex_getset_data
that uses the structure type ComponentData
. The initialization includes values for the substructure structs
.
coder.example.extractLines('GetSetSourceData.c',... '/* Field "structs" */','/* End of "structs" */',1,1)
/* Field "structs" */ { {1.3, 5.7, 9.2}, {12.3, 9.6, 1.76}, {0.0, 0.0, 0.0} }, /* End of "structs" */
The file also defines functions that read from and write to the fields of the substructure structs
. The functions simplify data access by dereferencing the fields of the global structure variable ex_getset_data
. The functions access the data in the fields inStruct
, structParam
, and outStruct
by accepting and returning complete structures of the types SigBus
and ParamBus
.
coder.example.extractLines('GetSetSourceData.c',... '/* Structure get() and set() functions */',... '/* End of structure functions */',1,1)
/* Structure get() and set() functions */ SigBus get_inStruct(void) { return ex_getset_data.structs.inStruct; } void set_inStruct(SigBus value) { ex_getset_data.structs.inStruct = value; } ParamBus get_structParam(void) { return ex_getset_data.structs.structParam; } void set_structParam(ParamBus value) { ex_getset_data.structs.structParam = value; } SigBus get_outStruct(void) { return ex_getset_data.structs.outStruct; } void set_outStruct(SigBus value) { ex_getset_data.structs.outStruct = value; }
View the example legacy header file GetSetSourceDataStructHdr.h
. The file contains the extern
prototypes for the get
and set
functions defined in GetSetSourceData.c
.
Open the example model GetSetStruct
. The model creates the data objects inStruct
, structParam
, and outStruct
in the base workspace. The objects correspond to the signals and parameter in the model.
open_system('GetSetStruct')
In the base workspace, double-click the object inStruct
to view its properties. The object uses the storage class GetSet
. The property HeaderFile
is specified as GetSetSourceDataStructHdr.h
. This legacy header file contains the get
and set
function prototypes.
The model also creates the bus objects ParamBus
and SigBus
in the base workspace. The signals and parameter in the model use the bus types that these objects define. The property DataScope
of each bus object is set to Imported
. The property HeaderFile
is set to ComponentDataHeader.h
. The generated code imports these structure types from the legacy header file ComponentDataHeader.h
.
In the model Configuration Parameters dialog box, on the Code Generation > Custom Code pane, the example legacy source file GetSetSourceData.c
is identified for inclusion during the build process. This legacy source file contains the get
and set
function definitions and the definition of the global structure variable ex_getset_data
.
Generate code with the example model.
slbuild('GetSetStruct');
### Starting build procedure for: GetSetStruct ### Successful completion of build procedure for: GetSetStruct Build Summary Top model targets: Model Build Reason Status Build Duration =============================================================================================================== GetSetStruct Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 12.621s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 13.245s
In the code generation report, view the file GetSetStruct.c
. The model step
function uses the legacy get
and set
functions to execute the algorithm.
coder.example.extractLines(fullfile('GetSetStruct_ert_rtw',... 'GetSetStruct.c'),... '/* Model step function */','}',1,1)
/* Model step function */ void GetSetStruct_step(void) { /* Bias: '<Root>/Bias' incorporates: * Inport: '<Root>/In1' */ rtDW.BusCreator.cmd = (get_inStruct()).cmd + (get_structParam()).offset; /* Gain: '<Root>/Gain' incorporates: * Inport: '<Root>/In1' */ rtDW.BusCreator.sensor1 = (get_structParam()).gain1 * (get_inStruct()).sensor1; /* Gain: '<Root>/Gain1' incorporates: * Inport: '<Root>/In1' */ rtDW.BusCreator.sensor2 = (get_structParam()).gain2 * (get_inStruct()).sensor2; /* SignalConversion: '<Root>/Signal Conversion' */ set_outStruct(rtDW.BusCreator); }
When you use the storage class GetSet
with structured data, the get
and set
functions that you provide must return and accept complete structures. The generated code dereferences individual fields of the structure that the get
function returns.
The output signal of the Bus Creator block is a test point. This signal is the input for a Signal Conversion block. The test point and the Signal Conversion block exist so that the generated code defines a variable for the output of the Bus Creator block. To provide a complete structure argument for the function set_outStruct
, you must configure the model to create this variable.
Use GetSet
with Matrix Data
This example shows how to apply the storage class GetSet
to signals and parameters that are matrices.
View the example legacy header file ComponentDataHeader.h
. The file defines a large structure type ComponentData
.
coder.example.extractLines('ComponentDataHeader.h',... '/* ComponentData */','} ComponentData;',1,1)
/* ComponentData */ typedef struct { ScalarData scalars; VectorData vectors; StructData structs; MatricesData matrices; } ComponentData;
The field matrices
is a substructure that uses the structure type MatricesData
. The structure type MatricesData
defines three fields: matrixInput
, matrixParam
, and matrixOutput
. The fields store matrix data as serial arrays. In this case, the input and parameter fields each have 15 elements. The output field has nine elements.
coder.example.extractLines('ComponentDataHeader.h'... ,'/* MatricesData */','} MatricesData;',1,1)
/* MatricesData */ typedef struct { double matrixInput[15]; double matrixParam[15]; double matrixOutput[9]; } MatricesData;
View the example legacy source file GetSetSourceData.c
. The file defines and initializes a global variable ex_getset_data
that uses the structure type ComponentData
. The initialization includes values for the substructure matrices
.
coder.example.extractLines('GetSetSourceData.c',... '/* Field "matrices" */','/* End of "matrices" */',1,1)
/* Field "matrices" */ { {12.0, 13.9, 7.4, 0.5, 11.8, 6.4, 4.7, 5.3, 13.0, 0.7, 16.1, 13.5, 1.6, 0.5, 3.1}, {8.3, 12.0, 11.5, 2.0, 5.7, 7.5, 12.8, 11.1, 8.4, 9.9, 10.9, 4.6, 2.7, 16.3, 3.8}, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0} } /* End of "matrices" */
The input matrix has five rows and three columns. The matrix parameter has three rows and five columns. The matrix output has three rows and three columns. The file defines macros that indicate these dimensions.
coder.example.extractLines('GetSetSourceData.c',... '/* Matrix dimensions */','/* End of matrix dimensions */',1,1)
/* Matrix dimensions */ #define MATRIXINPUT_NROWS 5 #define MATRIXINPUT_NCOLS 3 #define MATRIXPARAM_NROWS 3 #define MATRIXPARAM_NCOLS 5 #define MATRIXOUTPUT_NROWS MATRIXPARAM_NROWS #define MATRIXOUTPUT_NCOLS MATRIXINPUT_NCOLS
The file also defines functions that read from and write to the fields of the substructure matrices
.
coder.example.extractLines('GetSetSourceData.c',... '/* Matrix get() and set() functions */','/* End of matrix functions */',1,1)
/* Matrix get() and set() functions */ double get_matrixInput(int colIndex) { int rowIndexGetInput = MATRIXINPUT_NCOLS * (colIndex % MATRIXINPUT_NROWS) + colIndex/MATRIXINPUT_NROWS; return ex_getset_data.matrices.matrixInput[rowIndexGetInput]; } void set_matrixInput(int colIndex, double value) { int rowIndexSetInput = MATRIXINPUT_NCOLS * (colIndex % MATRIXINPUT_NROWS) + colIndex/MATRIXINPUT_NROWS; ex_getset_data.matrices.matrixInput[rowIndexSetInput] = value; } double get_matrixParam(int colIndex) { int rowIndexGetParam = MATRIXPARAM_NCOLS * (colIndex % MATRIXPARAM_NROWS) + colIndex/MATRIXPARAM_NROWS; return ex_getset_data.matrices.matrixParam[rowIndexGetParam]; } void set_matrixParam(int colIndex, double value) { int rowIndexSetParam = MATRIXPARAM_NCOLS * (colIndex % MATRIXPARAM_NROWS) + colIndex/MATRIXPARAM_NROWS; ex_getset_data.matrices.matrixParam[rowIndexSetParam] = value; } double get_matrixOutput(int colIndex) { int rowIndexGetOut = MATRIXOUTPUT_NCOLS * (colIndex % MATRIXOUTPUT_NROWS) + colIndex/MATRIXOUTPUT_NROWS; return ex_getset_data.matrices.matrixOutput[rowIndexGetOut]; } void set_matrixOutput(int colIndex, double value) { int rowIndexSetOut = MATRIXOUTPUT_NCOLS * (colIndex % MATRIXOUTPUT_NROWS) + colIndex/MATRIXOUTPUT_NROWS; ex_getset_data.matrices.matrixOutput[rowIndexSetOut] = value; }
The code that you generate from a model represents matrices as serial arrays. Therefore, each of the get
and set
functions accept a single scalar index argument.
The generated code uses column-major format to store and to access matrix data. However, many C applications use row-major indexing. To integrate the generated code with the example legacy code, which stores the matrices matrixInput
and matrixParam
using row-major format, the custom get
functions use the column-major index input to calculate an equivalent row-major index. The generated code algorithm, which interprets matrix data using column-major format by default, performs the correct matrix math because the get
functions effectively convert the legacy matrices to column-major format. The set
function for the output, matrixOutput
, also calculates a row-major index so the code writes the algorithm output to matrixOutput
using row-major format. Alternatively, to integrate the column-major generated code with your row-major legacy code, you can manually convert the legacy code to column-major format by transposing your matrix data and algorithms.
View the example legacy header file GetSetSourceDataMatrixHdr.h
. The file contains the extern
prototypes for the get
and set
functions defined in GetSetSourceData.c
.
Open the example model GetSetMatrix
. The model creates the data objects matrixInput
, matrixParam
, and matrixOutput
in the base workspace. The objects correspond to the signals and parameter in the model.
load_system('GetSetMatrix') set_param('GetSetMatrix','SimulationCommand','Update') open_system('GetSetMatrix')
In the base workspace, double-click the object matrixInput
to view its properties. The object uses the storage class GetSet
. The property HeaderFile
is specified as GetSetSourceDataMatrixHdr.h
. This legacy header file contains the get
and set
function prototypes.
In the Configuration Parameters dialog box, on the Code Generation > Custom Code pane, the example legacy source file GetSetSourceData.c
is identified for inclusion during the build process. This legacy source file contains the get
and set
function definitions and the definition of the global structure variable ex_getset_data
.
Generate code with the example model.
slbuild('GetSetMatrix');
### Starting build procedure for: GetSetMatrix ### Successful completion of build procedure for: GetSetMatrix Build Summary Top model targets: Model Build Reason Status Build Duration =============================================================================================================== GetSetMatrix Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 10.872s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 11.594s
In the code generation report, view the file GetSetMatrix.c
. The model step
function uses the legacy get
and set
functions to execute the algorithm.
coder.example.extractLines(fullfile('GetSetMatrix_ert_rtw',... 'GetSetMatrix.c'),'/* Model step function */','}',1,1)
/* Model step function */ void GetSetMatrix_step(void) { int32_T i; int32_T i_0; int32_T i_1; int32_T matrixOutput_tmp; for (i_0 = 0; i_0 < 3; i_0++) { for (i = 0; i < 3; i++) { /* Product: '<Root>/Product' incorporates: * Constant: '<Root>/Constant' * Inport: '<Root>/In1' */ matrixOutput_tmp = 3 * i_0 + i; set_matrixOutput(matrixOutput_tmp, 0.0); for (i_1 = 0; i_1 < 5; i_1++) { set_matrixOutput(matrixOutput_tmp, get_matrixParam(3 * i_1 + i) * get_matrixInput(5 * i_0 + i_1) + get_matrixOutput (matrixOutput_tmp)); }
Specify Header File or Function Naming Scheme for Data Items
By default, you specify a header file name, get
function name, and
set
function name for each data item, such as a signal or parameter,
that uses the storage class GetSet
.
To configure a single header file, get
function naming scheme, or
set
function naming scheme to use for every data item, you can use the
Custom Storage Class Designer to create your own copy of GetSet
. You can
specify the header file or function names in a single location.
Follow these steps to define a storage class in your own data class package and apply the new storage class to data items in your model.
As explained in Create and Apply Storage Class Defined in User-Defined Package, copy the MATLAB name space folder
to your working folder, name the foldermatlabroot
/examples/repository/simulink/dataclasses/+SimulinkDemos+myPackage
, and modify theParameter
andSignal
class definitions so that they use the storage class definitions frommyPackage
.Set your current folder to the folder that contains the MATLAB namespace folder
+myPackage
. Alternatively, add the folder containing the namespace folder+myPackage
to your MATLAB® path.Open the Custom Storage Class Designer.
cscdesigner('myPackage')
Select the storage class
GetSet
. Click Copy to create a copy calledGetSet_1
.Select the new storage class
GetSet_1
. In the General tab, set Name tomyGetSet
.Set the drop-down list Header file to
Specify
. In the new text box, set Header file tomyFcnHdr.h
. Click Apply.On the Access Function Attributes tab, set the drop-down lists Get function and Set function to
Specify
.In the new boxes, set Get function to
myGetFcn_$N
and Set function tomySetFcn_$N
. Click OK. Click Yes in response to the message about saving changes.When you generate code, the token
$N
expands into the name of the data item that uses this storage class.Apply the storage class
myGetSet
from your package to a data item. For example, create amyPackage.Parameter
object in the base workspace and apply the storage class to that object.myParam = myPackage.Parameter(15.23); myParam.CoderInfo.StorageClass = 'Custom'; myParam.CoderInfo.CustomStorageClass = 'myGetSet';
Use the object to set a parameter value in your model. When you generate code, the code algorithm accesses the parameter through the functions that you specified. The code uses an
#include
directive to include the header file that you specified.
Access Scalar and Array Data Through Macro Instead of Function Call
If you implement the get
mechanism for scalar or array data as a
macro instead of a function, you can generate code that omits parentheses when reading that
data.
For scalar data, your macro must yield the scalar value.
For array data, your macro must yield the starting memory address.
Create your own AccessFunction
storage class by using the
Custom Storage Class Designer, as described in Specify Header File or Function Naming Scheme for Data Items. In
the Designer, on the Access Function Attributes tab, select
Get data through macro (omit parentheses).
GetSet
Storage Class Restrictions
GetSet
does not support complex signals.Multiple data in the same model cannot use the same
GetFunction
orSetFunction
.Some blocks do not directly support
GetSet
.Custom S-functions do not directly support
GetSet
.
To use GetSet
with an unsupported block or a custom S-function:
Insert a Signal Conversion block at the output of the block or function.
In the Signal Conversion block dialog box, select Exclude this block from 'Block reduction' optimization.
Assign the storage class
GetSet
to the output of the Signal Conversion block.
Related Topics
- Exchange Data Between External C/C++ Code and Simulink Model or Generated Code
- Create and Apply Storage Class Defined in User-Defined Package
- Organize Parameter Data into a Structure by Using Struct Storage Class
- Finely Control Data Representation by Writing TLC Code for a Storage Class
- Generate Code That Dereferences Data from a Literal Memory Address