Global Variables
This page allows you to give Modelify more information about how a global variable should be converted. Global variables that are constant can be configured to be converted as a Constant Block or as Inports and Outports. If a global variable is a pointer, Modelify may not be able to determine the size of the pointer and this page can be used to configure the dimension of the global variable.
The table in this page will automatically be populated with the global variables that are used in the project.
To change how a constant global variable is converted, click in the cell in the Simulink Block column and a drop down box will appear with the options Constant Block and Inport/Outport Block. This is only enabled for constant global variables.
To change the dimension of a pointer global variables, click in the cell in the Dimension column. The cell will become editable and you can enter a dimension for the global variable. The value -1 can be used if the global variable should inherit its dimension from an input.
For global variables that are not constant and are not a pointer, no configuration is necessary.
The page also contains the following:
- A Create MATLAB variables for constant globals checkbox: if enabled, Modelify will create MATLAB variables for global variables marked as 'const' or that are never written.
- An Apply Simulink.Signal objects to ports (Embedded Coder) checkbox: this option allows configuring code generation options for ports corresponding to global variables. See details in the section below.
- Search box: the search box at the top of the table allows locating global variable elements under the Global Variable column.
Configure Simulink.Signal creation to support Embedded Coder
Steps below show how to configure Simulink.Signal objects for ports to specify code generation options.
- Check the Apply Simulink.Signal object to ports(Embedded Coder) checkbox. This enables the below three columns in the table to configure the creation of Simulink.Signal objects. Note that Modelify will automatically fill out Header File and/or Definition File columns using the information of the place where the global variable is declared/defined.
These values can be changed as desired.
- Create Simulink.Signal: indicates if a Simulink.Signal has to be created for a global variable. Convenience Create All Simulink.Signals and Create No Simulink.Signals buttons are included at the top of the table to create Simulink.Signals for all or no variables, respectively.
- Header File: specifies header file of global variable. It should include the file extension (.h)
- Definition File: specifies definition file of global variable. It should include the file extension (.c)
- Convert functions that use configured global variables.
- Simulink.Signal objects are created in the initialization file. It is also possible to perform manual changes in the initialization file; however note that a future conversion could override those manual edits.
The image below shows an example of an M-Script initialization file with Simulink.Signal objects.