Main Content

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.

rtwdemodbtype('ComponentDataHdr.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.

rtwdemodbtype('ComponentDataHdr.h','/* ScalarData */','} ScalarData;',1,1)
/* ScalarData */

typedef struct {
    double inSig;
    double scalarParam;
    double outSig;
} ScalarData;

View the example legacy source file getsetSrc.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.

rtwdemodbtype('getsetSrc.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.

rtwdemodbtype('getsetSrc.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 getsetHdrScalar.h. The file contains the extern prototypes for the get and set functions defined in getsetSrc.c.

Open the example model rtwdemo_getset_scalar. 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('rtwdemo_getset_scalar')

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 getsetHdrScalar.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 getsetHdrScalar.h.

In the model Configuration Parameters dialog box, on the Code Generation > Custom Code pane, under Additional build information, select Source files. The Source files box identifies the source file getsetSrc.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.

rtwbuild('rtwdemo_getset_scalar');
### Starting build procedure for: rtwdemo_getset_scalar
### Successful completion of build procedure for: rtwdemo_getset_scalar

Build Summary

Top model targets built:

Model                  Action                       Rebuild Reason                                    
======================================================================================================
rtwdemo_getset_scalar  Code generated and compiled  Code generation information file does not exist.  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 31.281s

In the code generation report, view the file rtwdemo_getset_scalar.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.

rtwdemodbtype(fullfile('rtwdemo_getset_scalar_ert_rtw','rtwdemo_getset_scalar.c'),...
    '/* Model step function */','}',1,1)
/* Model step function */
void rtwdemo_getset_scalar_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 ComponentDataHdr.h. The file defines a large structure type ComponentData.

rtwdemodbtype('ComponentDataHdr.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.

rtwdemodbtype('ComponentDataHdr.h','/* VectorData */','} VectorData;',1,1)
/* VectorData */
        
typedef struct {
    double inVector[5];
    double vectorParam[5];
    double outVector[5];
} VectorData;

View the example legacy source file getsetSrc.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.

rtwdemodbtype('getsetSrc.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.

rtwdemodbtype('getsetSrc.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 getsetHdrVector.h. The file contains the extern prototypes for the get and set functions defined in getsetSrc.c.

Open the example model rtwdemo_getset_vector. 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('rtwdemo_getset_vector')

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 getsetHdrVector.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 getsetSrc.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.

rtwbuild('rtwdemo_getset_vector');
### Starting build procedure for: rtwdemo_getset_vector
### Successful completion of build procedure for: rtwdemo_getset_vector

Build Summary

Top model targets built:

Model                  Action                       Rebuild Reason                                    
======================================================================================================
rtwdemo_getset_vector  Code generated and compiled  Code generation information file does not exist.  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 17.261s

In the code generation report, view the file rtwdemo_getset_vector.c. The model step function uses the legacy get and set functions to execute the algorithm.

rtwdemodbtype(fullfile('rtwdemo_getset_vector_ert_rtw','rtwdemo_getset_vector.c'),...
    '/* Model step function */','}',1,1)
/* Model step function */
void rtwdemo_getset_vector_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 ComponentDataHdr.h. The file defines a large structure type ComponentData.

rtwdemodbtype('ComponentDataHdr.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.

rtwdemodbtype('ComponentDataHdr.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.

rtwdemodbtype('ComponentDataHdr.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 getsetSrc.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.

rtwdemodbtype('getsetSrc.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.

rtwdemodbtype('getsetSrc.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 getsetHdrStruct.h. The file contains the extern prototypes for the get and set functions defined in getsetSrc.c.

Open the example model rtwdemo_getset_struct. 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('rtwdemo_getset_struct')

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 getsetHdrStruct.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 ComponentDataHdr.h. The generated code imports these structure types from the legacy header file ComponentDataHdr.h.

In the model Configuration Parameters dialog box, on the Code Generation > Custom Code pane, the example legacy source file getsetSrc.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.

rtwbuild('rtwdemo_getset_struct');
### Starting build procedure for: rtwdemo_getset_struct
### Successful completion of build procedure for: rtwdemo_getset_struct

Build Summary

Top model targets built:

Model                  Action                       Rebuild Reason                                    
======================================================================================================
rtwdemo_getset_struct  Code generated and compiled  Code generation information file does not exist.  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 18.578s

In the code generation report, view the file rtwdemo_getset_struct.c. The model step function uses the legacy get and set functions to execute the algorithm.

rtwdemodbtype(fullfile('rtwdemo_getset_struct_ert_rtw',...
    'rtwdemo_getset_struct.c'),...
    '/* Model step function */','}',1,1)
/* Model step function */
void rtwdemo_getset_struct_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 ComponentDataHdr.h. The file defines a large structure type ComponentData.

rtwdemodbtype('ComponentDataHdr.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.

rtwdemodbtype('ComponentDataHdr.h'...
    ,'/* MatricesData */','} MatricesData;',1,1)
/* MatricesData */

typedef struct {
    double matrixInput[15];
    double matrixParam[15];
    double matrixOutput[9];
} MatricesData;

View the example legacy source file getsetSrc.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.

rtwdemodbtype('getsetSrc.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.

rtwdemodbtype('getsetSrc.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.

rtwdemodbtype('getsetSrc.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 getsetHdrMatrix.h. The file contains the extern prototypes for the get and set functions defined in getsetSrc.c.

Open the example model rtwdemo_getset_matrix. 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('rtwdemo_getset_matrix')
set_param('rtwdemo_getset_matrix','SimulationCommand','Update')
open_system('rtwdemo_getset_matrix')

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 getsetHdrMatrix.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 getsetSrc.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.

rtwbuild('rtwdemo_getset_matrix');
### Starting build procedure for: rtwdemo_getset_matrix
### Successful completion of build procedure for: rtwdemo_getset_matrix

Build Summary

Top model targets built:

Model                  Action                       Rebuild Reason                                    
======================================================================================================
rtwdemo_getset_matrix  Code generated and compiled  Code generation information file does not exist.  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 16.4s

In the code generation report, view the file rtwdemo_getset_matrix.c. The model step function uses the legacy get and set functions to execute the algorithm.

rtwdemodbtype(fullfile('rtwdemo_getset_matrix_ert_rtw',...
    'rtwdemo_getset_matrix.c'),'/* Model step function */','}',1,1)
/* Model step function */
void rtwdemo_getset_matrix_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 = i + 3 * i_0;
      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 create your own storage class by creating your own data class package, creating a copy of GetSet, and applying the new storage class to data items in your model.

  1. Create your own data class package, myPackage, by copying the example package folder +SimulinkDemos and renaming the copied folder as +myPackage. Modify the Parameter and Signal class definitions so that they use the storage class definitions from myPackage. For an example, see Create Data Class Package.

  2. Set your current folder to the folder that contains the package folder. Alternatively, add the folder containing the package folder to your MATLAB® path.

  3. Open the Custom Storage Class Designer.

    cscdesigner('myPackage')
  4. Select the storage class GetSet. Click Copy to create a copy called GetSet_1.

  5. Select the new storage class GetSet_1. In the General tab, set Name to myGetSet.

  6. Set the drop-down list Header file to Specify. In the new text box, set Header file to myFcnHdr.h. Click Apply.

  7. On the Access Function Attributes tab, set the drop-down lists Get function and Set function to Specify.

  8. In the new boxes, set Get function to myGetFcn_$N and Set function to mySetFcn_$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.

  9. Apply the storage class myGetSet from your package to a data item. For example, create a myPackage.Parameter object in the base workspace.

    myParam = myPackage.Parameter(15.23);
    myParam.CoderInfo.StorageClass = 'Custom';
    myParam.CoderInfo.CustomStorageClass = 'myGetSet';
    

  10. 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 or SetFunction.

  • 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:

  1. Insert a Signal Conversion block at the output of the block or function.

  2. In the Signal Conversion block dialog box, select Exclude this block from 'Block reduction' optimization.

  3. Assign the storage class GetSet to the output of the Signal Conversion block.

Related Topics