7.9.1.1. GEL Function Definition

GEL functions are defined as follows, where items in courier font are variables:

funcName( [Parameters1 [, Parameters2 … [, Parameters6 ] ] ] )

{
statements
}

funcNameGEL function

Parameters Valid GEL Parameters

statements Valid GEL statements

GEL functions are defined in text files with a .gel extension. A GEL file can contain many GEL function definitions.

GEL functions do not identify any return type or need any header information to define the types of Parameters they require. This information is obtained automatically from the data value.

As with standard C, a GEL function definition cannot be embedded within another GEL function definition.

In this case, we are squaring the value the user passes to the function.

square(a)
{
return a*a;
}

If you add a call to this function in the Watch window, it looks like this:

square(1.2) = 1.44
square(5) = 25

Since a is a GEL Parameters, you do not have to define it in the function or in the target code.

You can follow each Parameters with an optional string that describes the use of the Parameters. This description is used in the dialog box that is created for dialog functions. For example:

dialog Init(filename “File to be Loaded”,
cpuName “CPU Name”,
initValue “Initialization Value”)
{
GEL_Load(filename, cpuName);
a = initValue;
}

The dialog adds this function to the menu bar. Strings are given for the Parameters to provide a description on the Parameters entry dialog box. In the statement a = initValue, the letter a is not defined in the Parameters list; therefore, it must be defined on the actual/simulated target. If it is not, an error occurs when you call this function. Note the call to the built-in function GEL_Load; this function requires a string identifying the file name for the first Parameters and the CPU name. The CPU name Parameters is optional and is useful in setting up multiple processors. You must pass a string for the first Parameters. An example of a valid call to this function is:

Init(“c:\mydir\myfile.out”, “cpu_a”, 0)

The following code shows how a GEL function is defined. Once a function is loaded, you can execute the function anytime by calling it with the correct Parameters. Calls such as: MyFunc(100, 0) or MyFunc(200) are both valid.

MyFunc(Parameters1, Parameters2)
{
if (Parameters1 == Parameters2)
a = Parameters1;
else
{
b = Parameters2;
c–;
}
}

The symbols a, b, and c are assumed to be target variables.