Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop Embedded Coder   

GetSet Custom Storage Class for Data Store Memory

Overview

The GetSet custom storage class is designed to generate specialized function calls to read from (get) and write to (set) the memory associated with a Data Store Memory block, when there is a need to read/write a signal many times in a single model. See Working with Data Stores for information about data stores and the Data Store Memory block.

The GetSet storage class is an advanced CSC: it cannot be represented by the standard Unstructured or FlatStructure custom storage class types. To access the CSC definition for GetSet, you must launch Custom Storage Class designer in advanced mode:

cscdesigner -advanced

GetSet CSC is capable of handling signals other than data stores. GetSet is supported for the outputs of most built-in blocks provided by The MathWorks. However, it is not supported for user-written S-functions. A workaround is to drop a Signal Conversion block at the outport of an S-Function (or unsupported built-in) block and assign the GetSet storage class to the output of the Signal Conversion block.

The next table summarizes the instance-specific properties of the GetSet storage class:

PropertyDescription

GetFunction

String that specifies the name of a function call to read data.

SetFunction

String that specifies the name of a function call to write data.

HeaderFile (optional)

String that specifies the name of a header (.h) file to add as an #include in the generated code.

    Note   If you omit the HeaderFile property for a GetSet data object, you must specify a header file by an alternative means, such as the Header file field of the Real-Time Workshop/Custom Code pane of the Configuration Parameters dialog box. Otherwise, the generated code might not compile or might function improperly.

For example, if the GetFunction of signal X is specified as 'get_X' then the generated code calls get_X() wherever the value of X is used. Similarly, if the SetFunction of signal X is specified as 'set_X' then the generated code calls set_X(value) wherever the value of X is assigned.

For wide signals, an additional index argument is passed, so the calls to the get and set functions are get_X(idx) and set_X(idx, value) respectively.

The following restrictions apply to the GetSet custom storage class:

For more details about the definition of the GetSet storage class, look at its associated TLC code in the file

matlabroot\toolbox\simulink\simulink\@Simulink\tlc\GetSet.tlc

Example of Generated Code with GetSet Custom Storage Class

The model below contains a Data Store Memory block that resolves to Simulink signal object X. X is configured to use the GetSet custom storage class as follows:

X = Simulink.Signal;
X.RTWInfo.StorageClass                 = `Custom';
X.RTWInfo.CustomStorageClass           = `GetSet';
X.RTWInfo.CustomAttributes.GetFunction = `get_X';
X.RTWInfo.CustomAttributes.SetFunction = `set_X';
X.RTWInfo.CustomAttributes.HeaderFile  = `user_file.h';

The following code is generated for this model:

/* Includes for objects with custom storage classes. */
   #include "user_file.h"

   void getset_csc_step(void)
   {
     /* local block i/o variables */
     real_T rtb_DSRead_o;
   
     /* DataStoreWrite: '<Root>/DSWrite' incorporates:
      *   Inport: '<Root>/In1'
      */
     set_X(getset_csc_U.In1);
   
     /* DataStoreRead: '<Root>/DSRead' */
     rtb_DSRead_o = get_X();
   
     /* Outport: '<Root>/Out1' */
     getset_csc_Y.Out1 = rtb_DSRead_o;
   }

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS