Import external C types#

The Matlab/Simulink Embedded-Coder generates C-Code from Simulink models. The page Embedded-Coder (C-Code) describes an easy way to get started with the Embedded-Coder on the UltraZohm. In order to streamline the inclusion of generated C-Code from Simulink into the UltraZohm workspace the Matlab function Simulink.importExternalCTypes can be used. This function parses the C (.h) header files for typedef, struct, and enum type definitions, and generates Simulink representations of the types.

How to use#

In your init.m Matlab script for your Simulink model include the following command.

Simulink.importExternalCTypes('headerfile.h');

Tip

Use a relative path to link back to the ultrazohm_sw library. This way changes to the C-source-code are reflected in your model.

This will create a bus object in your workspace with the appropriate types (i.e. float -> single). Theses buses can then be used in your Simulink object as normal data type.

Warning

For this to properly work all structs and enums, which are used in the Simulink model, have to be typedef. Otherwise, Simulink generates bus objects with incompatible names, which, if code generated, are not compatible with the initially included header-file (i.e. using struct uz_3ph_dq_t in the header-file leads with code-generation to struct_uz_3ph_dq_t name instead of struct uz_3ph_dq_t name. Using typedef fixes this).

Example#

Include the data types for the dq-transformation.

Simulink.importExternalCTypes('uz_Transformation.h');

In the Simulink workspace the following bus objects will be created:

../../../_images/bus_editor.png

These buses can be used, e.g., as an output for dq-reference currents.

../../../_images/property_inspector.png

This output can be directly assigned to other uz_3ph_dq_t structs or functions, which use this type.

Listing 38 Example for the usage of the generated code from imported C-types#
float theta_el_rad = 23.4f;
uz_3ph_dq_t dq_currents = codegenInstance.output.i_dq_ref;
uz_3ph_abc_t abc_currents = uz_transformation_3ph_dq_to_abc(codegenInstance.output.i_dq_ref, theta_el_rad);

More Information#