| Real-Time Workshop® Embedded Coder™ | ![]() |
| On this page… |
|---|
Specifying Type Definition Location for User-Defined Data Types |
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
Map your own data type definitions to Simulink built-in data types, and specify that your data types are to be used in generated code.
Optionally, generate #include directives specifying your own header files, containing your data type definitions. This technique lets you use legacy data types in generated code.
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.
Note The names of data types defined using Simulink.AliasType objects are preserved in the generated code only for installations with a Real-Time Workshop Embedded Coder license. |
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.
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;
If the HeaderFile property for a Simulink.DataType or Simulink.Bus object is set to a string value,
The string must be the name of a header file that contains a typedef for the object.
The generated file model_types.h contains a #include that gives the header file name.
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"
To specify and use user-defined data types for code generation:
Create a user-defined data object and configure its properties, as described in the Working with Data Objects section of the Simulink documentation.
If you specified the HeaderFile property, copy the header file to the appropriate directory.
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.
The specified output data type propagates through the model and variables of the user-defined type are declared as required in the generated code.
![]() | Introduction | Customizing the Target Build Process with the STF_make_rtw Hook File | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |