Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
VAMS-LRM-2-3-1.pdf
Скачиваний:
43
Добавлен:
05.06.2015
Размер:
3.73 Mб
Скачать

Accellera

 

Version 2.3.1, June 1, 2009

VERILOG-AMS

defined function, the last value assigned to the output argument is then assigned to the corresponding analog variable reference that was passed into the function.

The following lines (from the second example in 4.7.1) illustrate this concept:

area = l * w;

perim = 2 * ( l + w );

4.7.2.3 Inout arguments

inout arguments allow the user to pass in a value to the function and return a different value from it using the same argument. The argument passed to an inout argument must be an analog variable reference. If the inout argument is defined as an array then the argument passed into the function must be an analog variable or an array assignment pattern of analog variables of equivalent size. The inout arguments of an analog user defined function do not get initialised to zero (0) like those defined as inout. During the execution of the function, these variables can be read and assigned in the flow. At the end of the execution of the analog user defined function, the last value assigned to the inout argument is then assigned to the corresponding analog variable reference that was passed into the function. If a value was not assigned to the inout argument during the execution of the analog user defined function, then the corresponding analog variable reference is left untouched.

The following lines (from the third example in 4.7.1) illustrate the use of an inout argument.

for(i = 0; i < 2; i = i + 1) begin a[i] = a[i] + b[i];

end

Note: inout arguments are not “pass by reference”, but more closely related to “copy in” and “copy out”. Care should be taken to avoid passing the same analog variable reference to different inout and output arguments of the same analog user defined function as the results are undefined.

4.7.3 Calling an analog user defined function

An analog user defined function call is an operand within an expression. Syntax 4-5 shows the analog user defined function call.

analog_function_call ::= // from A.8.2 analog_function_identifier { attribute_instance } ( analog_expression { , analog_expression } )

Syntax 4-5—Syntax for function call

The order of evaluation of the arguments to an analog user defined function call is undefined. The argument expressions are assigned to the declared inputs, outputs, and inouts in the order of their declaration.

An analog user defined function:

shall not call itself directly or indirectly, i.e., recursive functions are not permitted; and

shall only be called within the analog context, either from an analog block or from within another analog user defined function;

The following example uses the maxValue function defined in 4.7.1.

V(out) <+ maxValue(val1, val2);

Copyright © 2009 Accellera Organization, Inc.

86

 

Accellera

Analog and Mixed-signal Extensions to Verilog HDL

Version 2.3.1, June 1, 2009

The following example uses the geomcalc function defined in 4.7.1.

dummy = geomcalc(l-dl, w-dw, ar, per);

Note that the first two arguments are expressions, and match up with the inputs l and w for the function; the second two arguments must be real identifiers because they match up with the function outputs.

The following example incorrectly uses the geomcalc function defined in 4.7.1.

dummy = geomcalc(l-dl, w-dw, ar, V(a));

Here the last two arguments to the user defined function geomcalc are declared as output arguments, but the fourth argument is passed the potential probe V(a). Only analog variable references can be passed to output and inout arguments of a analog user defined function so this example will result in a compilation error.

The following example uses the arrayadd example defined in 4.7.1, to add values from one array to another.

x[0] = 5; x[1] = 10; y = 3; z = 6;

dummy = arrayadd(x,'{y,z});

Here the first and second arguments are both expecting vectors. A vector variable is passed for the first argument and an array assignment pattern of two scalar analog variables has been used for the second argument. Since the first argument is an inout argument, the result of calling the arrayinit function will update the vector variable x with values x[0] = 8 and x[1] = 16.

87

Copyright © 2009 Accellera Organization, Inc. All rights reserved.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]