Real-Time Workshop    

Storage Classes for Data Store Memory Blocks

You can control how Data Store Memory blocks in your model are stored and represented in the generated code by assigning storage classes and type qualifiers. You do this in almost exactly the same way you assign storage classes and type qualifiers for block states.

Data Store Memory blocks, like block states, have Auto storage class by default, and their memory is stored within the DWork vector. The symbolic name of the storage location is based on the block name.

Note that you can generate code from multiple Data Store Memory blocks that have the same name, subject to the following restriction: at most one of the identically-named blocks can have a storage class other than Auto. An error will be reported if this condition is not met. For blocks with Auto storage class, Real-Time Workshop generates a unique symbolic name for each block (if necessary) to avoid name clashes. For blocks with non- Auto storage classes, Real-Time Workshop simply uses the block name to generate the symbol.

To control the storage declaration for a Data Store Memory block, use the RTW storage class and RTW storage type qualifier fields of the Data Store Memory block parameters dialog.

In the following block diagram, a Data Store Write block writes to memory declared by the Data Store Memory block myData.

Data Store Memory blocks are nonvirtual, as code is generated for their initialization, and declarations in model header files. The Data Store Memory block parameter dialog is shown next. Note that it documents which blocks write to and read from it.

Table 5-9 shows code generated for the Data Store Memory block in this model. The table gives the variable declarations and MdlOutputs code generated for the myData block.

Table 5-9: Storage Class Options for Data Store Memory Blocks and Generated Code
Storage Class
Declaration
Code

Auto

  • typedef struct D_Work_tag {
      real_T myData;
    } D_Work;
    (declared in model.h)
    .
    .
    /* Data Type Work (DWork) 
    Structure */
    D_Work rtDWork;
    (declared in model.c)
    

rtDWork.myData = rtb_Sine_Wave;

Exported Global

  • extern real_T myData;
    (declared in model_private.h)
    

myData = rtb_Sine_Wave;

Imported Extern

  • extern real_T myData;
    (declared in model_private.h)
    

myData = rtb_Sine_Wave;

Imported Extern Pointer

  • extern real_T *myData;
    (declared in model_private.h)
    

*(myData) = rtb_Sine_Wave;


  Summary of State Storage Class Options Data Store Memory and Simulink Signal Objects