Main Content

Definition, Initialization, and Declaration of Parameter Data

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

C Construct

int32 myParam = 3;

extern int32 myParam;

Procedure

1. Open the example modelex_defn_decl.

2. In the model, select the Gain block. In the Property Inspector, set the value of theGainparameter tomyParam.

3. Next to the parameter value, click the action button (the button with three vertical dots) and selectCreate.

4. In the Create New Data dialog box, setValuetoSimulink.Parameter(3). ClickCreate. ASimulink.Parameterobject,myParam, appears in the base workspace. The Gain block uses the object to set the value of the Gain parameter, in this case, 3.

5. In the Simulink.Parameter property dialog box, setData typetoint32.

6. Set存储类toExportToFile.

7. SetHeader FiletomyDecls.h.

8. SetDefinition FiletomyDefns.c. ClickOK.

9. To build the model and generate code, pressCtrl+B.

Results

The generated header filemyDecls.hdeclares the global variablemyParamby using theexternkeyword.

/* Declaration for custom storage class: ExportToFile */ extern int32_T myParam; /* Referenced by: '/Gain' */

The generated source filemyDefns.cdefines and initializesmyParam.

/* Definition for custom storage class: ExportToFile */ int32_T myParam = 3; /* Referenced by: '/Gain' */

Related Topics