CALL

The CALL function is used to run GLOBAL test device file functions from circuit code files and other test device files.

Syntax

The CALL function has three sets of parameters: the first set contains the reference of the test device and the name of the function to call, the second set is the input arguments and the third set is the output arguments. When there are no output arguments the third set of brackets may be omitted.

CALL( STRING deviceReference, STRING functionName )
  ( variableType inputParm, ... )
  ( variableType outputParm, ... );

Parameters

deviceReference

A test device reference in the form 'board.device'. The board name is optional, but the reference must uniquely identify the test device; if there is any ambiguity, then the board name must be supplied.

functionName
The name of the test device function to run. The function may be defined in its main file or additional code files. The function must be visible from the calling code (see Function Scopes).

Errors

The following errors are possible:

  • The deviceReference test device cannot be found.
  • The deviceReference test device is ambiguous. The device name exists on multiple boards so the reference has to be of the form 'board.device'.
  • The functionName cannot be found on the test device. Either the wrong device is referenced, the function name is incorrect or the scope of the function is not GLOBAL.
  • The inputParm or outputParm types or counts do not match those defined by the test device function.

If the deviceReference and functionName are constant then these errors will be shown at compile-time. If either are non-const then the errors will only be found at runtime and will fail the running test. To avoid such runtime errors, use FUNCTION_EXISTS before using CALL to check if a function can be called.

Examples

LOCAL CONST STRING CRYSTAL := "XJDemo.X1";
GLOBAL ReadFrequency()(INT result)
  INT actualFrequency;
  CALL(CRYSTAL, "SetEnable")(1)();
  actualFrequency := PIN_FREQUENCY(PIO.OSC);
  PRINT(actualFrequency, "\n");
  CALL(CRYSTAL, "SetEnable")(0)();
END;

GLOBAL ReadADC()(INT result)
  CONST INT ADC_CH := 3;
  INT adcVoltage;
  CALL("XJDemo.U11", "ReadADC")(ADC_CH, TRUE, 0)(adcVoltage, result);
  PRINT(adcVoltage, "\n");
END;

GLOBAL TurnOnLEDs()(INT result)
  STRING[] LEDs := {"D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8"};
  FOREACH STRING LED IN LEDs
    CALL(LED, "SetLED")(0); // non-const device string used, and empty third set of brackets omitted
  END;
END;

Test device making CALLs on itself

A test device cannot make a CALL to itself when the deviceReference and functionName are constant as that is not the purpose of CALLs, and it will be a compile-time error. Instead a standard function call should be made. The one exception to this rule is when one or both of deviceReference and functionName are non-constant, where it will be allowed, but it can only call GLOBAL functions on itself this way and it's not recommended if a standard function call would suffice.

See also