Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop Embedded Coder   

Generating Code with Custom Storage Classes

Code Generation Prerequisites

Before you generate code for a model that uses custom storage classes, set model options as follows:

Code Generation Example

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:

Grouped Custom Storage Classes

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.

  


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