Main Content

Definition and Declaration of Signal Data

This example shows how to export the definition and declaration of a global variable that the generated code uses as a signal.

C Construct

float mySig;

extern float mySig;

Procedure

1. Open the example model ex_defn_decl.

2. In the Model Data Editor, open the Inports/Outports tab.

3. In the Model Data Editor, for the Inport block, set Data Type to single.

4. Open the Embedded Coder app.

5. In the C Code tab, select Code Interface > Individual Element Code Mappings.

6. In the Code Mappings editor, on the Inports tab, set Storage class for the Inport block to ExportToFile.

7. In the Property Inspector, set Identifier to mySig, Header File to myDecls.h, and Definition File to myDefns.c.

8. Generate code from the model.

Results

The generated header file myDecls.h declares the global variable mySig by using the extern keyword.

/* Declaration for custom storage class: ExportToFile */
extern real32_T mySig;                 /* '<Root>/In1' */

The generated source file myDefns.c defines and initializes mySig.

/* Definition for custom storage class: ExportToFile */
real32_T mySig;                        /* '<Root>/In1' */

Related Topics