Code Generation with User-Defined Data Types

Overview

The Real-Time Workshop Embedded Coder software supports use of user-defined data type objects in code generation. These include objects of the following classes:

For information on the properties and usage of these data object classes, see Simulink.AliasType, Simulink.Bus, Simulink.NumericType, and Simulink.StructType in the Data Object Classes section of the Simulink Reference documentation. For general information on creating and using data objects, see the Working with Data Objects section of the Simulink documentation

In code generation, you can use user-defined data objects to

In general, code generated from user-defined data objects conforms to the properties and attributes of the objects as defined for use in simulation. When generating code from user-defined data objects, the name of the object is the name of the data type that is used in the generated code. Exception: for Simulink.NumericType objects whose IsAlias property is false, the name of the functionally equivalent built-in or fixed-point Simulink data type is used instead.

Specifying Type Definition Location for User-Defined Data Types

When a model uses Simulink.DataType and Simulink.Bus objects, corresponding typedefs are needed in code. Both Simulink.DataType and Simulink.Bus objects have a HeaderFile property that controls the location of the object's typedef. Setting a HeaderFile is optional and affects code generation only.

Omitting a HeaderFile Value

If the HeaderFile property for a Simulink.DataType or Simulink.Bus object is left empty, a generated typedef for the object appears in the generated file model_types.h.

Example.   For a Simulink.NumericType object named myfloat with a Category of double and no HeaderFile property specified, model_types.h in the generated code contains:

typedef real_T myfloat;

Specifying a HeaderFile Value

If the HeaderFile property for a Simulink.DataType or Simulink.Bus object is set to a string value,

You can use this technique to include legacy or other externally created typedefs in generated code. When the generated code compiles, the specified header file must be accessible on the build process include path.

HeaderFile Property Syntax.   The HeaderFile property should include the desired preprocessor delimiter ("" or '<>'), as in the following examples.

This example:

myfloat.HeaderFile = '<legacy_types.h>'

generates the directive:

#include <legacy_types.h>

This example:

myfloat.HeaderFile = '"legacy_types.h>"'

generates the directive:

#include "legacy_types.h"

Using User-Defined Data Types for Code Generation

To specify and use user-defined data types for code generation:

  1. Create a user-defined data object and configure its properties, as described in the Working with Data Objects section of the Simulink documentation.

  2. If you specified the HeaderFile property, copy the header file to the appropriate directory.

  3. Set the output data type of selected blocks in your model to the user-defined data object. To do this, set the Data type parameter of the block to Specify with dialog. Then, enter the object name in the Output data type parameter.

  4. The specified output data type propagates through the model and variables of the user-defined type are declared as required in the generated code.

  


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