7.9.1.1. GEL Function DefinitionΒΆ

GEL functions are defined similarly as in C language:

funcName( Parameters1, Parameters2 ... Parameters6 )
{
   statements
}
  • funcName: the name of the GEL function
  • Parameters: valid GEL Parameters
  • statements: valid GEL statements

GEL functions are defined inside the GEL File (.gel extension). A GEL file can contain many GEL function definitions.

Differently than C language, a GEL function does not require defining its prototype (return type, parameters) at the top of the source file or in any header file. All functions are global and the data types are obtained automatically from the passed values.

A GEL function definition cannot be embedded within another GEL function definition.

___

Examples:

A simple function:

In the example below, the GEL parameter a is being squared:

square(a)
{
   return a*a;
}

This function can be used by other GEL functions or can be directly called from the Expressions View:

../_images/gel_function_expressions.png

Since a is a GEL parameter, there is no need to define it in the function or in the target code.

Using target variables:

GEL Functions can also modify data on the target. In the example below, the symbols limitCount, currentIteration, and nextIteration must exist in the code loaded to the target device.

Once a function is loaded as part of a GEL file, it can be executed from any other place (expressions view, other GEL functions) with the designated parameters. Calls such as MyFunc(100, 0) or MyFunc(200) are both valid.

MyFunc(maxValue, currentValue)
{
   if (maxValue == currentValue)
   limitCount = maxValue;
   else
   {
      currentIteration = currentValue;
      nextIteration--;
   }
}

Using dialogs and descriptions:

Each parameter can be followed with an optional string that describes its use. This description is used in the dialog box that is created when dialog functions are used.

In the example below, the dialog GEL function Init has three parameters, each with its own description:

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

In the Init function above, the variable a is not defined in the function parameters. Therefore, it must be defined on the code loaded to the target device. Fail to do so will yield an error.

The dialog adds Init to the Scripts menu bar.

Clicking on the function Init, the dialog box below is shown:

../_images/gel_function_dialog.png

The Init function above calls the built-in function GEL_Load. This function requires as parameters:

  • a string identifying the file name for the first parameter
  • an optional parameter with the CPU name. This parameter is useful when setting up multiple cores or processors.
  • a initialization value

A dialog function can also be called from inside the GEL files as well. An example of a valid call to this function would be:

Init("c:\\workspace\\myProject\\Debug\\myProject.out", "C28xx_CPU1", 0);

___

See also:

GEL Functions: Alphabetical List