| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Real-Time Workshop Embedded Coder |
| Contents | Index |
| Learn more about Real-Time Workshop Embedded Coder |
| On this page… |
|---|
Before you generate code for a model that uses custom storage classes, set model options as follows:
If your model assigns custom storage classes to any parameters, select Inline parameters on the Configuration Parameters > Optimization pane. This requirement also applies to models that assign built-in storage classes to parameters. Otherwise, the code generator ignores CSC specifications for parameters.
Deselect Ignore custom storage classes on the Configuration Parameters > Real-Time Workshop pane. Otherwise, the code generator ignores all CSC specifications, and treats all data objects as if their Storage class were Auto.
This section presents an example of code generation with CSCs, based on this model:

The model contains three named signals: aa, bb, and cc. Using the predefined Struct custom storage class, the example generates code that packs these signals into a struct named mySignals. The struct declaration is then exported to externally written code.
To specify the struct, you provide Simulink.Signal objects that specify the Struct custom storage class, and associate the objects with the signals as described in Applying CSCs to Parameters and Signals. All three objects have the same properties. This figure shows the signal object properties for aa:

The association between identically named model signals and signal objects is formed as described in Resolving Symbols. In this example, the symbols aa, bb, and cc resolve to the signal objects aa, bb, and cc, which have custom storage class Struct. In the generated code, storage for the three signals will be allocated within a struct named mySignals.
You can display the storage class of the signals in the block diagram by selecting Port/Signal Display > Storage Class from the Simulink model editor Format menu. The figure below shows the block diagram with signal data types and signal storage classes displayed.

With the model configured as described in Code Generation Prerequisites, and the signal objects defined and associated with the signals, you can generate code that uses the custom storage classes to generate the desired data structure for the signals. After code generation, the relevant definitions and declarations are located in three files:
model_types.h defines the following struct type for storage of the three signals:
typedef struct MySignals_tag {
boolean_T cc;
uint8_T bb;
uint8_T aa;
} mySignals_type;model.c (or .cpp) defines the variable mySignals, as specified in the object's instance-specific StructName attribute. The variable is referenced in the code generated for the Switch block:
/* Definition for Custom Storage Class: Struct */
mySignals_type mySignals = {
/* cc */
FALSE,
/* bb */
0,
/* aa */
0
};
...
/* Switch: '<Root>/Switch1' */
if(mySignals.cc) {
rtb_Switch1 = mySignals.aa;
} else {
rtb_Switch1 = mySignals.bb;
}model.h exports the mySignals Struct variable:
/* Declaration for Custom Storage Class: Struct */ extern mySignals_type mySignals;
A custom storage class that results in multiple data objects being referenced with a single variable in the generated code, in the previous example, is called a grouped custom storage class. In the Simulink package, Bitfield and Struct (shown in the preceding example) are grouped CSCs. Data grouped by a CSC is referred to as grouped data.
![]() | Applying CSCs to Parameters and Signals | Defining Advanced Custom Storage Class Types | ![]() |

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 |